This cheat sheet is intended to be a quick reminder for the main concepts involved in using the command line program Vim (or vi) and assumes you already understand its usage. It does not cover every command in Vim, only the ones we consider to be useful for most people for the majority of their text editing. What is VI-editor? While in vi you can run AIX commands without exiting the editing session. Creates a shell to execute the command that follows. 1.:!ls will create a shell 2. All files in the current directory are listed. Press return to exit the shell and return to the vi session or 3. While still in command mode, issue the:r. The ultimate Vi cheat sheet for anyone learning Vi Commands or the Vi editor in general. Keep this guide close by when using the editor and you will learn how to use Vi in no time. Vim commands will be the same as Vi for the most part – Windows however has Gvim which allows some GUI interaction.
Some times I have to work on Server(Linux hosted server – Ubuntu), due to hands on experience on UI based editors (IDE, Sublime, Atom, Notepad ++, etc ) I felt difficult to edit any documents(usually programming) via terminal at initial stage. But VI is a powerful tool as any other editor, can perform almost all operation on File edit manipulation.
VI has 2 modes. Insert Mode and Command Mode.
- Insert mode: Its to used edit/update content of a file
- Command mode: Its help us to perform VI function and it has wide range of functions. Its a default mode of VI.
Vi Editor Commands Cheat Sheet Pdf
To switch to ‘Insert mode’ hit letter ‘i‘ or ‘insert‘ button.
To switch to ‘Command mode’ hit ‘Esc‘ button.
Basic Commands:-
:q | Close file |
:w | Write to File |
:wq | Write to file and then close editer. |
:12 | Go to specific line number of file. Number reference line number |
G | Go to last line of the file |
Search & Replace Commands:- How can i download internet explorer for mac.
/test | Search word ‘test’ on document. Hit letter ‘n’ to repeat search and ‘N’ for backward search |
/test/word | If search term contains backward slash, escape with forward slash. Search term on above example is “test/word” |
?test | Search word ‘test’ on document from bottom to top. |
/test|word | Search more than search term. “test” and “word” both are search criteria. |
/test* OR /<test | Search word starts with ‘test’ on document, Like test, testing, tested, testimonial, etc. |
/test> | Search word ends with ‘test’ on document. |
:%s/find/replace/g | Find and replace content. |
:%s/find/replace/gi | Find and replace content and its not case sensitive. |
:%s/find/replace/gw | Find and replace content on confirmation. |
:10,20s/find/replace/g | Find and replace content between lines 10 and 20. |
:s/find/replace/ | Find and replace content at first occurrence on current line. |
:s/find/replace/g | Find and replace content on current line. |
Delete Commands:-
'This is Mountain Biking' The Triple B mountain bike started out as the Bossnut’s big brother and was designed by the Calibre team to have all the upgrades they wanted to ride right out of the box. Details Buy now BOSSNUT The Bossnut is back, but not as you know it. Our multiple award winning, industry smashing trail bike has had a complete. Calibre full. Two lifelong friends on a hunting trip in Scotland find their nerves - and their morals - ruthlessly tested after a harrowing turn of events. Watch trailers & learn more. Calibre: The one stop solution for all your e-book needs. Comprehensive e-book software.
D | Delete from cursor position to end of current line. D is equivalent d$ |
dw | Delete from the current cursor position to the beginning of the next word |
dd | Delete current line |
5dd | Repeat dd command (delete current line) 5 times |
dG | Delete lines from current to end of file |
d10j | Delete from current line to 10 lines forward direction |
d10k | Delete from current line to 10 lines backward direction |
:10,20d | Delete lines between range. |
:g/test/d | Delete all lines containing matching pattern. |
:v/test/d | Delete all lines that does not containing matching pattern. Reverse of :g command |
:v/test|testing/d | Delete all lines except those that containing ‘test’ or ‘testing’. |
Vi Editor Commands Cheat Sheet Download
Tab, Split & Switch:
:tabnew file | Create new tab and open file |
g t | Switch to next tab |
g T | Switch to previous tab |
002 g t | Switch to specific tab by tab number |
:split file | Split window/screen on horizontal |
Ctrl + W Ctrl + W | Switch between window |
:qa | Close all tab or window |
:e test.sh | Open file or switch from current file |
:e# 1 | Switch file, here number is file number |
I have not listed all VI Commands, but these commands can help to modify document via terminal.