Linux.com

Some Useful VI Tips

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.

 

 

 

 

Comments

Subscribe to Comments Feed

Upcoming Linux Foundation Courses

  1. LFS426 Linux Performance Tuning
    21 Apr » 24 Apr - Virtual
    Details
  2. LFS520 OpenStack Cloud Architecture and Deployment
    05 May » 09 May - Virtual
    Details
  3. LFD320 Linux Kernel Internals and Debugging
    12 May » 16 May - Virtual
    Details

View All Upcoming Courses


Who we are ?

The Linux Foundation is a non-profit consortium dedicated to the growth of Linux.

More About the foundation...

Frequent Questions

Join / Linux Training / Board