VIM — The Improved VI Editor

$ vim
$ sudo apt install vim #for Debian based distros-or-$ sudo yum install vim #for RHEL based distros
  • By default when you enter vim editor, you are in command mode. Command mode is used to command various operations like moving through editor etc.
  • To enter insert mode, press i or I. Insert mode adds text to the file.
  • Press V to get into the visual mode, Visual mode makes it easier to highlight and manipulate text in Vim
  • Replace mode allows you to replace existing text by directly typing over it. Before entering this mode, get into normal mode and put your cursor on top of the first character that you want to replace. Then press ‘R’ (capital R) to enter replace mode. Now whatever you type will replace the existing text.
  • Press Esc to enter the command mode and then press ‘:’ followed by different combinations of w and q to save or quit changes.
  • k — navigate upwards
  • j — navigate downwards
  • l — navigate the right side
  • h — navigate the left side
  • 0 — go to the beginning of the current line.
  • ^ — go to the first non-blank character of the line.
  • $ — go to the end of the current line.
  • g_ — go to the last non-blank character of the line.
  • U — Undo
  • . — Redo
  • 4u — To undo 4 steps
  • H — Go to the first line of the current screen.
  • M — Go to the middle line of the current screen.
  • L — Go to the last line of the current screen.
  • ctrl+f — Jump forward one full screen.
  • ctrl+b — Jump backwards one fullscreen
  • ctrl+d — Jump forward (down) a half screen
  • ctrl+u — Jump back (up) one half screen
  • N% — Go to the Nth percentage line of the file.
  • NG — Go to the Nth line of the file.
  • G — Go to the end of the file.
  • `” — Go to the position where you were in NORMAL MODE while last closing the file.
  • `^ — Go to the position where you were in INSERT MODE while last closing the file.
  • g — Go to the beginning of the file.
  • e — Takes you to the end of the current word.
  • E — Takes you to the end of the current WORD.
  • b — Takes you to the previous (before) word.
  • B — Takes you to the previous (before) WORD.
  • w — Takes you to the next word.
  • W — Takes you to the next WORD.
  • 192.168.1.1 — single WORD
  • 192.168.1.1 — seven words.
  • { — Takes you to the beginning of the current paragraph. By pressing { again and again move to the previous paragraph's beginnings.
  • } — Takes you to the end of the current paragraph. By pressing } again and again move to the next paragraph's ends, and again.
  • /i — Search for a pattern which will you take you to the next occurrence of it.
  • ?i — Search for a pattern which will you take you to the previous occurrence of it.
  • * — Go to the next occurrence of the current word under the cursor.
  • # — Go to the previous occurrence of the current word under the cursor.
  • To copy a line, press y, placing the cursor at the beginning of the line and then press p, where you want to paste the line.
  • To select a text, type v to go into visual mode and then select the required text by highlighting and press y when done. Go to new location press p to paste.

Thanks for reading! Happy VIMing!!!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Manminder Singh

Manminder Singh

DevOps Trainee | 3x AWS Certified | Linux Certified | Former IT HR | Naval Brat