Here you’ll learn some commands to use vim.
Vim
Vim is an advanced text editor that seeks to provide the power of the de-facto Unix editor Vi, with a more complete feature set.
so, install it:
sudo apt-get install vim
You can open files using:
vim namefile

Basics of Moving in Vim
Vim accept interac through shell using keys like:
’`.’ move to the last word edit.
hmoves the cursor one character to the left.lmoves the cursor one character to the right.jmoves the cursor down one line.kmoves the cursor up one line.0moves the cursor to the beginning of the current line.$moves the cursor to the end of the current line.wmove to the beginning of the next word.bmove to the beginning of the previous word.emove to next word end.gemove to previous word end.ggmove to the beginning of the file.Gmove to the end of the file.ctrl-umoves to the previous page of the document.ctrl-dmoves to the next page of the document.
Note: if your press k, Vim move the cursor up 1 line, but if you press 10k Vim move the cursor up 10 lines.
More movements in Vim
Wmove to the beginning of the next word like blankspace,\nor\t.Bmove to the beginning of the previous word like blankspace,\nor\t.Emove to next word end like blankspace,\nor\t.gEmove to previous word end like blankspace,\nor\t.(Go to the beginning of the sentence.)Goes to the end of the sentence.{Go to the beginning of the paragraph.}Go to the end of the paragraph.|Goes to the first visible column on the screen.
Modes of Vim
Vim has 6 modes, a normal mode, insertion mode, replace mode, visual mode, selection mode and CLI mode:
ESCactivates normal mode, now you can write a command like write (:w) o quit (:q).:activates CLI mode, now you can write w to save o q to exit.
Normal Mode
In /etc/vim/vimrc file, add:
"show number line"
set number
"tabulation step"
set tabstop=2 softtabstop=2 shiftwidth=2 expandtab
"indent at press enter"
set autoindent
"show current position"
set ruler
CLI Mode
Vim has this mode when you use the : and other letters like:
! dateshows all the changes did in a file.e namefilecreates a new file namednamefile.b#where#is a number (1, 2, etc), is like tabs.
Insertion Mode
Vim has ways to activates insertion mode:
ithe cursor is left where it was.Imoves the cursor to the end of the current line.aThe cursor moves one character to the right.Amoves the cursor to the end of the current line.oinserts a new line below the current line and moves the cursor to the beginning of that new line.Oinserts a new line above the current line and moves the cursor to the beginning of that new line.
Replace Mode
Ractivates replace mode.INSactivates normal mode from replace mode and viceverse.
Visual Mode
vactivates visual mode, now you can select by letters.Vactivates visual mode, now you can select by lines.ctrl-vactivates visual mode, now you can select by colums.vGselect all document from the current position of the cursor until the end of the file..vggselect all document from the current position of the cursor until beginning of the file.uconverts the entire selection to lowercase.Uconverts the entire selection to uppercase.>adds a tabulation.<removes a tabulation.
Selection Mode
ghorgHactivates selection mode.ghis similar tov.gHis similar toV.gctrl-his similar toctrl-v.ctrl-homeselect all until the beginning of file.ctrl-endselect all until the end of file.
Deleting text in Vim
dstarts the delete operation.dwwill delete a word.d0will delete until the beginning of a line.d$orDwill delete until the end of a line.dggwill delete until the beginning of the file.dGwill delete until the end of the file.d{will delete until the beginning of paragraph.10ddord10ddelete 10 lines.d12Gwill delete from the current position of cursor to the line number 12.Jwill delete\nand blank spaces.gJwill delete\nbut not blank spaces.cis identical todbut this option activates insertion mode.ccis identical toddbut this option activates insertion mode.xwill delete the first caracter on the right side of the cursor.Xwill delete the first caracter on the left side of the cursor.
Copy and Paste text in Vim
ppaste text after the current line.Ppaste text on the current line.ystarts the delete operation.ywwill copy a word.y0will copy until the beginning of a line.y$will copy until the end of a line.yggwill delete until the beginning of the file.yGwill delete until the end of the file.10yyory10ycopy 10 lines.y12Gwill copy from the current position of cursor to the line number 12.
Undo and Redo
uwill undo the last operation.Udiscard all changes in the current line.Ctrl-rwill redo the last undo.
Searching and replacing
/wordsearch forwordin the document, going forward.nmove the cursor to the next instance of the text from the last search. This will wrap to the beginning of the document.Nmove the cursor to the previous instance of the text from the last search.?wordsearch forwordin the document, going backwards.:%s/orginal/new word/gsearch through the entire document for text and replace it with replacement text.:%s/orginal/new word/gcsearch through the entire document and confirm before replacing text.
Write and Exit of Vim
Vim accept 2 ways to write (or save) and exit:
qExits window.:q!Exits without saving changes.Z!Exits without saving changes.:wqExits and saving changes.ZZExits and saving changes.
