Vim Editor Session
~SriBhavani and Bakyalakshmi
On 18th Jan 2022, we had a session on vim by HarshaVaradhan from AuraSemiconductors. In this blog, we share what we have learned about vim and how we use it.
Vim is a highly configurable text editor built to create and change any kind of text very efficiently. Vim Editor has its own configuration file called vimrc. This can be customizable based on how we want to see GVIM
- Vim has the Two modes of operation
- Command Mode
- Insert Mode
To enter into the command mode press ESC.
There are two sub-modes in the command mode.
- Command Line Editing 🡪 “:” followed by the command
(eg) :q- to quit the editor window
- Command-line window 🡪 Directly enter the command It will automatically execute once it got the valid sequence
(eg) dd – delete the current line
There are two ways to enter into insert mode.
- i 🡪 Enter into the Insert mode at the point where the cursor present
- o 🡪 Enter into the Insert mode with the new line, next to the Cursor line
Few commands to access vim editor in the Command line window:
- dd 🡪 Delete the cursor line.
- ndd 🡪 Delete the n lines from the cursor position
- gg 🡪 Go to File Starting.
- GG 🡪 Go to End of the File.
- Ngg 🡪 Go to nth line in the file.
- yy 🡪 Copy the Cursor line
- Nyy 🡪 Copy N lines from the cursor line
- u 🡪 undo the changes
- ctrl+R 🡪 Redo the last changes
- ggVG 🡪 This will select all the file data
- y 🡪 copy the selected content
- p 🡪 paste copied content
Few commands to access vim editor in Command Line Editing
- :w 🡪 To save the file
- :q! 🡪 close the editor without saving the changes
- :vsp 🡪 Split the same vim editor file in two windows vertically
- :sp 🡪 Split the same vim editor file in two windows Horizontally
- :tabnew 🡪 Open newtab
- :E 🡪 To open the file tree
- :se nu 🡪 Show line numbers in the text editor
- :se nonu 🡪 Remove line numbers in the text editor
- Type ” / “ to search a word or sentence in command mode
(e.g.) /cat – it will highlight all occurrence of word “cat” in the file
- n 🡪 show next occurrence from current to bottom
- N 🡪 Show search word occurrence from current to top
Search and replace:
|:%s/Old/New/gc||Search for word “Old” and replace by “New”, ask confirmation before replace|
|:%s/old/NEW/gi||Case insensitive, Search all possibilities of word “old” and replace by “NEW”|
|:%s/Old/New/gI||Case sensitive, Search “Old” replace by “New”|
|:%s/Old/New/g||Replace all occurrence of “Old” by “New”, without asking for confirmation|