English
+370 5 205 5502 sales@monovm.com

Vim Editor shortcuts

This guide seeks to break the loop once and for all so that you can learn all of its Shortcuts quickly. This blog aims to walk you through each Vim Shortcuts along with covering other important aspects of Vim.

28 Feb, 22 by Susith Nonis 8 min Read

List of content you will read in this article:

Vim is Vi's most recent and popular version, which supports text and graphical interfaces and runs on any platform. The problem with learning Vim isn't that it's difficult; It's just that you have to keep doing it.

This guide seeks to break the loop once and for all so that you can learn all of its Shortcuts quickly. This blog aims to walk you through each Vim Shortcuts along with covering other important aspects of Vim.

Vim stands for "Vi IMproved." It is a Unix text editor that is included with Linux, BSD, and macOS. It's known for being quick and powerful, thanks to its simple application that can operate in a terminal (although it has a graphical interface). 

It's mostly because it can be operated totally without the use of menus or a mouse. However, Vim is not the way current computer users expect to edit text. Yet it's how Unix administrators all around the world update config files, changelogs, scripts, and more.

Features of Vim

  • It has a small memory footprint.
  • It's a command-based system. With just a few commands, you can complete difficult text-related activities.
  • It is very configurable and stores its settings in a simple text file.
  • There are numerous Vim plug-ins available. These plug-ins can greatly increase the usefulness of the programme.
  • Multiple windows are supported. This function allows you to split your screen into numerous windows.
  • It has many tabs that allow you to work on multiple files at the same time.
  • It has recording tools that allow you to record and play Vim commands over and over again.

Because Vim's developers know how straightforward it is, they built vimtutor, a short, interactive explanation of the essentials. Although Vim has a lot of power, there are just a few controls you need to master to utilise it effectively. 

  • Start Vim by entering Vim in a terminal or by running gvim on your desktop.
  • To enter input text mode, press I. You can only type text into your document while in insert mode. In insert mode, there are no commands.
  • Enter normal mode by pressing Esc, which is used for commands.
  • You can move your cursor with h (left), j (down), k (up), and l (left) in regular mode (right). It could be easier to remember that j is down if you visualise it as a Down arrow.
  • To exit Vim, type :wq to save your work or :q! to discard any changes that haven't been saved.

Other than these fundamentals, all other Vim commands are arguably for convenience and efficiency.

Cursor Movements 

  • h - moving the cursor to the left
  • j - moving the cursor down
  • k - moving the cursor up
  • l - moving the cursor to the right right
  • H - Jumping directly on the top of the screen
  • M - Jumping on the middle of the screen
  • L - Jumping directly on the bottom of the screen
  • w - Jumping on the start of a written word
  • e - Jumping towards the end of a written word
  • Ctrl + e - Moving the screen down by one line without the use of a cursor
  • Ctrl + y - Moving the screen up by one line without making the use of cursor
  • Ctrl + b - Moving one fullscreen forward
  • Ctrl + f - Moving one fullscreen backword
  • Ctrl + d - Moving ½ fullscreen forward 
  • Ctrl + u -  Moving ½ fullscreen backword

Insert mode - inserting/appending text

  • i - Inserting before the cursor 
  • I - inserting at the beginning of a line 
  • a - inserting after the cursor
  • A - inserting at the end of the line
  • o - Opening new lines below the selected line
  • O - Opening new lines above the selected line
  • ea - inserting at the end of the selected word
  • Ctrl + h - deleting characters before the cursor 
  • Ctrl + w - deleting words before the cursor 
  • Ctrl + j - Creating a new line while inserting a new mode
  • Ctrl + t - Moving right with one line shift width
  • Ctrl + d - Moving left with one line shift width
  • Ctrl + ox - Quickly access normal mode for executing any normal mode command
  • Esc - Exiting the insert mode 

Working with multiple files

  • :e[dit] file - Editing files in new buffer
  • :bn[ext] - Jumping to the next buffer
  • :bp[revious] - Jumping back to the previous buffer 
  • :bd[elete] - Deleting a buffer 
  • :b[uffer]# - Hoping directly to a buffer through index 
  • :b[uffer] file - Hopping to a buffer through file 
  • Ctrl + ws - Splitting the Window
  • Ctrl + wv - Vertical splitting of the Window 
  • Ctrl + ww - Switching between the windows
  • Ctrl + wq - Quitting Window
  • Ctrl + wx - Exchanging current Window with the next Window
  • Ctrl + w= - Adjusting the height and width of all the Windows as same
  • Ctrl + wh - Jumping the cursor to next Window
  • Ctrl + wl - Jumping the cursor to the next Window
  • Ctrl + wj - Jumping the cursor to the Window present below
  • Ctrl + wk - Jumping the cursor to the Window present above 
  • Ctrl + wH - Making selected Window expand to the full screen 
  • Ctrl + wJ - Making selected Window expand to the full screen at right bottom

Cut and paste

  • yy - (Copy command) pull a single line
  • 2yy - (Copy command) pull two lines
  • yw - (Copy command) pull the characters of the words below cursor for starting the next position 
  • yiw - (Copy command) Pull the words below the cursor 
  • yaw - (Copy command) Pull the words selected with the cursor and add space 
  • p - (paste command) paste from clipboard after the cursor position
  • P - (paste command) paste from the clipboard before the cursor position
  • gP - (paste command) paste content before cursor and leave cursor after newly added text
  • dd - (cut command) deleting a line
  • 2dd - (cut command) deleting two lines
  • dw - (cut command) deleting the characters of the word selected from the cursor 
  • diw - (cut command) deleting words selected through the cursor 
  • D - (cut command) deleting text at the end of the selected line
  • x - (cut command) deleting characters

Editing 

  • r - replacing only one character 
  • R - replacing more a single characters
  • J - Joining below the line with the current one along with adding one-line space between them 
  • gJ - Joining below the line with the current one along without adding any space 
  • cc - Changing the entire line 
  • C - Changing at the end of a line
  • ciw - Replacing an entire word
  • cw or ce - Replacing at the end of a word
  • s - deleting characters along with substituting its text
  • S - Deleting lines along with substituting their text
  • xp - Trasposing 2 letters 
  • u - Undo

Search and replace 

  • /pattern - Quickly search patterns
  • ?pattern - Quickly search backwards of a pattern
  • n - Repeating search in a similar direction 
  • N - Repeating searches in different directions 
  • :%s/old/new/g - Replacing old contents with the new ones all over the file
  • :noh[lsearch] - Removing highlights from search matches 

Tabs

  • :tabnew or :tabnew {page.words.file} - Opening a new file in a new tab
  • Ctrl + wT - Moving current split Window into an old tab
  • gt or :tabn[ext] - Moving to a next tab
  • gT or :tabp[revious] - Moving back to the previous tab
  • :tabm[ove] # - Moving selected tab to a pointed location 
  • :tabc[lose] - Closing the current tab
  • :tabo[nly] - Closing every tab except the selected one

You can write code at incredible speed with VIM. Just get begun, and the rest will take care of itself. Use a vim plug-in for your text editor if you wish to integrate into the vim universe gradually. A vim plug-in is available for all popular text editors (here's one for VsCode). So there you have it, the best of all worlds! When you're sure you're ready, make the complete transition.

People also read: 

Susith Nonis

I'm fascinated by the IT world and how the 1's and 0's work. While I veture into the world of Technology I try to share what I know in the simplest way possible. Not a fan of coffee, a sweet addict and a self accredited 'master chef'.