Some Useful VI Tips

54

vi tips that I find useful.

 :make will run the make file in the current directory, and load the file where the first error occurs at the location that the first error occurs

 

% will match brackets.

=% will indent brackets and braces (very useful)

:e. will select a file to edit from the working directory

 Some more general VI tips

To move your cursor without having to move your hands, use hjkl where h is left, j is up, k is down and l is left. This is also used when switching between windows after doing ctrl-w.

 go to a line

:10000

will go to line 10000

 

search

/find text

 

(note that no colon is needed)

 

search and replace

:%s/find text/replace text/g

 

the g at the end means global. 

 

 ctrl-w ctrl-s  

ctrl-w is window command mode, ctrl-s is split horizantlaly

 after that you can

edit a new file

:e file

or go to the next buffer if you are already editing more then one file

:bn 

To search for a file edit the directory

:e .

 this will allow you to select a file from within the directory. (use hjkl to move around)

 

To repeat a command use a period. For example if you inserted some text, then moved to another part in the file, pushing . will insert the text again.

 Macro Record

q letter edit sequence q

Macro playback

@ letter

 

Common letter commands

i is insert

I is insert from the beginning of the line

a is append after the current letter

A is append at the end of the line.