VI improved text editor or VIM text editor is an opensource solution available for both CLI and GUI interfaces. In this cheat sheet, you will find most of the Vim Commands which are needed when you will work with text files in the CLI interface.
So let’s start with open a file in Vim text editor. Use the below command to open a file in Vim CLI interface.
Vim text editor is having two different mods Insert mode and Command mode.
When you need to write normal text in a file, you can just press i for insert mode and start writing. After writing Press Esc. to go back into the command mode.
The default mode you will get when you open a file in Vim editor. From here you will give commands to the editor for all operations.
Below is the list of basic vim commands –
- :help [keyword] – To searching for help about a specific keyword
- u – To Undo the last command performed
- Ctrl+r – To Redo the undo command
- 0 – Press zero (0) to move the cursor to the beginning of the line
- $ – Move the cursor to the end of the line
- H – Moves the cursor to the top of the screen
- L – Moves the cursor to the bottom of the screen
- M – Moves the cursor to the middle of the screen
- :e [filename] – For open a file in Vim editor
- :w – To save the file
- :w [filename] – To save the file with a different name
- :wq – To save the file and close Vim editor
- :q! – To Quit without saving the file
- yy – To copy the entire line
- yw – To copy a single word
- p – To paste the copied item
- dd – To delete the entire line of text
- dw – To delete a single word
- /[keyword] – To search for a specific keyword. For Example: To search the word cat use the command “/cat“
- n – To search the next appearance of the specific word which is searched in the last command.
- :%s/[find]/[replace]/g – To find and replace the specific string
The Above commands are must be known when we edit a file in Vim text editor. Hope this will help you in any way. You can share your thoughts in the comment section. Also, suggest to me if I missed any basic command here.
- Also Read: Tcpdump Examples