Vi
From MEPIS Documentation Wiki
Vi or Vim is a basic text editor found in most of UNIX-like operating systems. It is useful to know how to use it in case there are no other text editors available, it is also a very powerful editor.
Vim is "vi improved" and it usually replaces "Vi" on most of the modern systems.
Contents |
Tutorial
Start Vim tutorial by typing "vimtutor" in konsole. If that doesn't work make sure you have "vim-full" installed on your system.
Basic operation
Vi has two basic modes "command mode" and "insert mode", you can enter text only in insert mode, otherwise Vim expects a command. Vim starts in command mode, to enter insert mode press "i", to exit back to command mode press "Esc".
Basic commands
exit to command mode Esc
exit vi (without saving) :q!
exit vi (with saving) :wq
Editing
All these commands place you in "edit mode" to exit press Esc.
insert mode i
append mode A
open new line o
copy (or yank) y
copy word yw
paste p
Delete
delete character x
delete word dw
delete line dd
delete 5 lines d5d or 5dd -- many commands in Vim can be applied multiple times by using a number with them, for example d3w deletes three words and 7x deletes seven characters.
put or paste p pastes the deleted content
Undo
undo u
undo all changed to a line U
Search and replace
search /
search backward ?
search again (next) n in opposite direction N
replace :s/old/new
replace in all the line :s/old/new/g
replace in all document :%s/old/new/g
go to original position CTRL-o
go to line number linenumber G, or linenumber gg
go to begin of document gg
go to end of document G
show position in document CTRL-g
Open file
start program with vi filename
in vi type :o filename
Save file
save :w
save as :w filename
Other useful commands
execute external commands :!command, for example :!ls runs the "ls" command in the current directory.