vim is a free powerful text editor based on the vi text editor.
An example of installing vim on Ubuntu/Debian:
sudo apt-get install vim
Install vim GUI:
sudo apt-get install vim-gtk
Running the vim tutorial:
vimtutor
gvimtutor
Examples of opening a file:
vi file.txt
vim /home/user/file.txt
gvim file.txt
After opening the file, the editor will use the command mode, then you can go to edit mode.
I will describe several function keys.
Move Commands:
j (move cursor down)
k (move cursor up)
h (move cursor right)
l (move the cursor to the left)
0 (move to the first character in the string)
$ (move to the last character in the string)
Ctrl+F (move page forward, similar to PageUp)
Ctrl+B (move page forward, similar to PageDown)
gg (go to the beginning of the document)
G (go to end of document)
number G (go to line with number)
w (move to the first character of the next word)
5w (go to the beginning of the fifth word from the current position)
e (move to the last character of the word)
5e (go to the end of the fifth word from the current position)
b (move to the previous first character of the word)
Search:
/ (Search)
? (reverse search)
n (go to next found item)
p (go to the previous item found)
Undo Commands:
u (undo the last change)
U (discard line changes)
CTRL+R (undo cancel)
:q! (exit the editor by canceling all changes)
Uninstall Commands:
x (delete character under cursor)
DIGIT x (removal of the number of characters from the cursor position)
dd (delete current runoff)
DIGIT dd (delete the number of lines from the cursor position)
dDIGITw (removal of the specified number of words from the cursor position)
d$ (delete characters to the end of the current line)
d0 (delete characters before the beginning of the current line)
AutoCorrect:
:s/word1/word2/g (replace all “word1” in the current line with “word2”)
:1,50s/word1/word2/g (replace all “word1” with “word2” from line 1 to line 50)
Copy and paste:
yy (copy the entire line to the clipboard)
p (paste the contents of the clipboard after the cursor)
y10y or 10yy (copy 10 lines to the clipboard)
yw (copy one word)
The clipboard may also contain recently deleted data.
Other:
:q (exit the editor if no changes have been made)
:q! (exit the editor by canceling all changes)
:w (save file)
:w file_name (save the file under a different name)
:x or :wq (save and exit)
i or a (enter input mode)
Esc (return to command mode)
J (joining the next sink to the current)
r+character (replacing a character with a specified character)
:help command (command help)