Skip to content

Vim tips

by Ammar on September 29, 2011

Yes, I know there are a multitude of guides out there on using vim as a super-powerful code editor, but I am going to go ahead and make my own recommendations. This is more or less a list of commands/tools that I use a lot and that work for me. ┬áTo use a few of these though, you’re going to have to use my vimrc configuration: take a look at my vimrc repository on github.

Normal mode:
:vsp [filename] – vertical split – one of my all-time favs! You can tab out the filename to see where you are and what files are available
:sp [filename] – horizontal split. Almost as useful as :vsp.
Ctrl+W Ctrl+R – While working with split windows, move current window clockwise. Useful for moving around splits.
:W – write and compile C files using the file ‘compile’ in the same directory, requires my vimrc config
. – Execute last command. Haven’t used it much yet, but seems very useful!
~ – switch the letter under the cursor from uppercase to lowercase and vice versa then move forward one char. Credit to Hashem for showing me this, it made my life n amount of times better!
:%s/from/to/g – Globally replace the ‘from’ strings in the file to ‘to’ – really useful find and replace. Don’t forget the g for global!
gg – Go to the start of a file
G – Go to the end of a file
gg=G – Indent from the start of a file to the end of a file (i.e. indent the whole file). You can also indent the line you’re on by using ==
q <char> – Insert <char> before cursor – requires my vimrc
Q <char> – Insert <char> after cursor – requires my vimrc
0 – Go to the start of a line
$ – Go to the end of a line
w – Go to the start of the next word
e – Go to the end of the current word
b – Go back to the previous word
J – Replace the newline at the end of the current line with space, i.e. bring the lower line up. Super useful
K – Look up the current word in the man pages, good for looking up C functions

Insert mode:
Tab – autocomplete current word! Super useful, requires my vimrc
Ctrl+[ – an alias for ESC to get out of insert mode, again credit to Hashem!

From → Tech

No comments yet

Leave a Reply

Note: HTML is allowed. Your email address will not be published.

Subscribe to this comment feed via RSS

Spam prevention powered by Akismet