VIM: Code Editor
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:
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 toleft, down, up and right
w
move cursor to the start of the next wordb
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 linegg
to move to the start of the fileG
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, ^, $, %
withd, c
orvisual mode
will make your life easy.
Modes:
- editing mode:
iIaA
- command mode:
:
- visual mode:
vV
i
to start editing to left where the cursor isa
to start editing to right where the cursor isA
to move the cursor to the end of the current line and start editingI
to move the cursor to the start of the line and start editingV
to switch tovisual
mode and highlight the current line
Editing:
dd
to cut the current lineyy
to copy the current linep
to paste the content stored in thecopy
registero
to create a new line after the current line and switch toediting
O
to create a new line before the current line and switch toediting
x
to delete the current characterr<replace-with-character>
to replace the current character with the<replace-with-character>
c
acts liked
but switches toediting
after the command executesd<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 modectrl+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 searchENTER
to searchn
to move to next search resultN
to move to previous search result
My favorites:
:set relativenumber
to display relative line numbers for easy navigation