VIM tricks
May 13, 2013
I am running Vim 7.3. on a linux system.
My $VIMRUNTIME is /usr/share/vim/vim73
My cheat sheet
- :version - lots of stuff about vim
- :let x=0 - set a variable
- :echo x - sort of like printf for vim
- :so file - source a file
- :mkv file - save all current settings for .vimrc
- * and # - search for word under the cursor
- gf - opens file under the cursor
- gg goes to first line of file.
- % goes to matching dingus even if not on a dingus
- :!ls runs a command
- :r !ls runs a command and pulls in its output
- tT work like f and F, except stop one character short
- zt put the current line at the top of the screen (handy!)
- zb put the current line at the bottom of the screen
- zz put the current line at the center of the screen
.vimrc
- :r $VIMRUNTIME/vimrc_example.vim
Split windows
- :split file - edit a new file, splitting the current window
- :new - split the current window, producing a new empty window
- ^W^W jumps among windows
Word and Line completion
I have to tell you right up front that this is flakey as hell and
I am still struggling with making it work. It sounds like a nice idea,
but needs a smoother implementation. When I am lucky enough to get
it to try to complete a word, it offers me a menu of candidates, and
I have no clue how to navigate the menu. The usual vi motion commands
do not work. Maybe the arrow keys?
The basics of this are Control-P and Control-N which search backward
and forwards for words in the file being edited. The Control-X character
triggers a special mode (watch the line at the bottom of the screen).
When you are offered a list of words, use Control-P and Control-N to move
around in the list and select what you want.
- Ctrl-P does word completion in insert mode, from previous words
- Ctrl-N does word completion in insert mode, from following words
- Ctrl-X Ctrl-L does line completion, while in insert mode
- Ctrl-X Ctrl-k does word completion from dictionary.
- :set dictionary=/usr/share/dict/words - sets dictionary for the above.
- Ctrl-X Ctrl-F complete a filename in insert mode
- Ctrl-X Ctrl-I does some other completion thing.
Help
- :h topic list of all help topics containing "topic"
- :h vimrc-intro
- :h user-manual
- :h usr_41
- :Helptags must be typed to access plugin documentation.
- Use Ctrl-] to visit a hyperlink.
- Use Ctrl-T as a back button.
Links
Feedback? Questions?
Drop me a line!
Tom's Computer Info / [email protected]