Vi, a little great editor -I part-

created: 1267882702|%e %B %Y, %H:%M
TAGS: vi

emacs_learning_curves.png

In all these years, I have always work with vi under linux. Vi is not really the most user friendly editor you can find out there, but certainly is one of the most powerful and flexible.

I strongly encourage my student to have a basic knowledge in vi, and for this, a nice and complete tutorial can be found |here.

Beforehave a look to the most common commands we can use in vi, what should be clear is that vi has two “operating modes”: the edit mode and the command mode. When vi starts, you are in command mode: type i to go in edit mode and start to write. Press the escape key to return in command mode. And please, oh please, forget your mouse ;)

from command mode you can go to insert mode with:

i : start editing from the current position of the cursor
a : start editing from the position next to the current position of the cursor
shift+a : start editing from the end of the line
o : insert a newline below the current line, and start editing
shift+o : insert a newline above the current line, and start editing

some commands in command mode:

x : delete current character
n dd : delete n lines starting from (and including) the current one (dd to delete 1line)
shift+g : jump to the end of the file
n+shift+g : jump to the nth line
1+shift+g : jump to the 1st line
ctrl+g : info about file (name, current line, total line, …)
n shift+y : yank n lines starting from (and including) the current one (Y to yank 1 line)
p : past yanked or deleted lines below the current line
shift+p : past yanked or deleted lines above the current line
. : repeat last command or text entry
u : undo last command
/string : search string in file. type n to jump to the next occurrence, shift+n to jump to the previous occurrence
:1,$s/string/string2/ : replace string1 with string2 in all the file
:n,ms /string/string2/ : replace string1 with string2 from line n to line m
:.,ms /string/string2/ : replace string1 with string2 from the current line to line m
:sp : split horizontally the current vi windows in two
:vsp : split vertically the current vi windows in two
ctrl+w up/down/left/right : change active window (if window has been split)
:e file : open a file /create new file

save, quit, open (command mode):

:w : write (save)
:w! : overwrite an existing file
:q : quit
:q! : quit without saving
:wq or :x : save and quit

visual block (command mode)

ctrl+v : select part of a file (move with the cursor) and then you can use dd, Y, x, …

Continue…

Bookmark and Share

Rate this post:

rating: 0+x

Comments: 0


vi
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License