VIM Cheat sheet
VIM is improved version VI. There are two modes, command mode and Insert mode. You can switch to insert mode with i and command mode with ESC. Insert mode is for inserting text and paragraph. Command mode is for all other things.
Commands
Opening and Creating file
- Opening or creating file
vim filename.txtorvi filename.txt - Opening two file
vi file1.txt file2.txt - Compare two file
vi -d file1.txt file2.txtEditing
- Insert mode
i - Insert mode from starting of line
SHIFT + iorI - Insert mode from ending of line
SHIFT + aorA - Insert mode on next line
o - Insert mode on previous line
SHIFT + oorOSearch and Replace
- Search using
/yourtext + ENTERfor nextnfor previousN - Reverse Search using
?yourtext + ENTERfor nextnfor previousN - Replace text in full document
%s/yourtext/replacetext/g (+c) - Replace a single character
rCut Copy Paste
- Delete full line
dd - Delete Multiple lines
5dd - Delete Right side
shift + dorD - Delete Single char
x - Delete Multiple chars
5x - Copy whole line
SHIFT + vorV(entering visual line mode) Now, copyycutd - Select from char
v(entering visual mode) Now, copyycutd - Select
CTRL + V(entering visual mode) Now, copyycutd - Paste below
p - Paste above
SHIFT + porPAction
- Undo with
u - Redo with
ctrl-r - Undo all changes
:e! + ENTERMovement
- Top
gg - Bottom
G - Move to line
:100eg:linenumber - Move to different file
CTRL + wwwhen opened two file withvi file1.txt file2.txtSetting change
- Show line number
:set nu - Word wrap
:set wm - Syntax color mode off
:syntax off - Syntax color mode on
:syntax onSave
- Saving Text:
:w! - Quite
:q! - Save and Quite with
:wq!