VI / VIM Editor Commands
" Popular and powerfull editor used in Linux "
General Startup
- vim filename // create/edit a file name
- press i // switch to insert mode
- enter content // enter your content
- Esc key // switch back to command mode
- :wq // write file and exit vim
Inserting
- i Insert before cursor.
- r Replace character under cursor with next character typed.
- R Keep replacing character until [esc] is hit and backspace will undo the replaced character.
- O Open line above cursor and enter append mode.
Cursor Movement
- h Move left (backspace)
- j Move down
- k Move up
- l Move right (spacebar)
- $ Last column on the current line.
- 0 Move cursor to the first column on the current line.
- w Move to the beginning of the next word or punctuation mark.
- b Move to the beginning of the previous word or punctuation mark.
- H Move cursor to the top of the screen.
- M Move cursor to the middle of the screen.
- L Move cursor to the bottom of the screen.
Deleting
- x Delete character under cursor.
- dd Delete line under cursor.
- dw Delete word under cursor.
- db Delete word before cursor.
- 10dd Delete 10 lines from the cursor.
- u Undo.
- U Restore line.
Copying/yank
- yy Copies (yank) line.
- 10yy Copies 10 lines from the cursor.
- y$ Copy to end of current line from cursor.
- yw Copy from cursor to end of current word.
Paste
- p Brings back previous deletion or yank of lines.
Find/Search
- ? Finds a word going backwards.
- / Finds a word going forward.
- /hi Find a word hi.
- n Move to next occurrence of search string.
- N Move to next occurrence of search string in opposite direction.
- /jo[ha]n Search john or joan.
- /\< ¦.\> Search all words of 4 letters.
Replace
- :%s/old/new/g Replace all occurences of old by new in file.
- :%s/old/new/gw Replace all occurences with confirmation.
- :2,35s/old/new/g Replace all occurences between lines 2 and 35.
- :5,$s/old/new/g Replace all occurences from line 5 to EOF.
- :%s/^/Good/g Replace the begining of each line by Good.
- :%s/$/vivek/g Replace the end of each line by vivek.
- :%s/onward/forward/gi Replace onward by forward, case unsensitive.
- :%s/ *$//g Delete all white spaces.
- :s/VD/MK/ Replace the first occurence of VD by MK in current line.
- :s/VD/MK/g Replace VD by MK in current line.
- :%s/VD/MK/g Replace VD by MK in all the file.
- :%s/\r//g Delete DOS carriage returns (^M).
- :%s#<[^>]\+>##g Delete HTML tags but keeps text.
- :%s/^\(.*\)\n\1$/\1/ Delete lines which appears twice.
Line Numbers
- :set nu To set line number.
- :.= Returns line number of current line at bottom of screen.
- := Returns the total number of lines at bottom of screen.
Syntax highlighting
- :syntax on Turn on syntax highlighting.
- :syntax off Turn off syntax highlighting.
- :set syntax=perl Force syntax highlighting.
Miscellaneous Commands
- . Repeat last command.
- xp Reletes first character and inserts after second.
- % If at one parenthesis, will jump to its mate.
- esc gg To move the top of the file.
- shift g To move the bottom of the file.
- :1,2w newfile Writes lines 1 to 2 from the courser to a newfile.
- :1,8w >> newfile Appends lines 1 to 8 to newfile.
- :!pwd Execute the pwd unix command, then returns to edditor.
- :Sex Split window and open integrated file explorer.
VI / VIM Editor Commands
Reviewed by vivek sathisan
on
15:58
Rating:

No comments: