VIM: Code Editor

Arbaz Ajaz
GopenSource

--

Starting with Vim feels scary and it is, considering the fact that my typing speed went down quite drastically because i was not used to vim, but now that i’m getting a hang of it, it almost feels like it is saving me a bunch of clicks and it’s doing what it is supposed to be doing, helping me use mouse a lot less! Following are the list of things I have been using:

Photo by Brigitte Tohm on Unsplash

I have an added an extension vim to enable vim in Visual Studio Code because It is after all the best code editor you can find.

Movement:

  • hjkl map to left, down, up and right
  • w move cursor to the start of the next word
  • b move cursor to the end of the last word (Go back)
  • e move cursor to the end of the current word
  • ^ move cursor to the first non empty character on the line
  • $ move cursor to the last non empty character on the line
  • gg to move to the start of the file
  • G to move to the end of the current file
  • % to move to matching opening/closing of nearest bracket. (Quite handy in visual mode for clearing a whole code block.)

Using/combining w, b, e, ^, $, % with d, c or visual mode will make your life easy.

Modes:

  • editing mode: iIaA
  • command mode: :
  • visual mode: vV
  • i to start editing to left where the cursor is
  • a to start editing to right where the cursor is
  • A to move the cursor to the end of the current line and start editing
  • I to move the cursor to the start of the line and start editing
  • V to switch to visual mode and highlight the current line

Editing:

  • dd to cut the current line
  • yy to copy the current line
  • p to paste the content stored in the copy register
  • o to create a new line after the current line and switch to editing
  • O to create a new line before the current line and switch to editing
  • x to delete the current character
  • r<replace-with-character> to replace the current character with the <replace-with-character>
  • c acts like d but switches to editing after the command executes
  • d<modifier> to cut according to the modifier. i.e. de cut from the current position to the end of the current word.
  • ctrl+a to increment a value in normal mode
  • ctrl+x to decrement a value in normal mode

Prefixing a number before the command will repeat the command given number of times. For example, 5+ctrl+a will increment the number 5 times, so if it was 6, it will become 11.

Searching:

  • / for regex powered search
  • ENTER to search
  • n to move to next search result
  • N to move to previous search result

My favorites:

  • :set relativenumber to display relative line numbers for easy navigation

--

--

Arbaz is a MERN Stack developer, aiming to make learning programming accessible and straight forward