Skip to content

Instantly share code, notes, and snippets.

@mjrulesamrat
Last active December 12, 2021 02:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mjrulesamrat/e0726f88b1288b74b2d792b6db9fe9e6 to your computer and use it in GitHub Desktop.
Save mjrulesamrat/e0726f88b1288b74b2d792b6db9fe9e6 to your computer and use it in GitHub Desktop.
Vim shortcuts

Modes

  1. Normal
  2. Edit/Insert
  3. Visual
  4. Replace

Normal Mode

Alphanumeric keys can not be used to edit open code. We can use commands to manipulate content of open file.

This is default mode.

Navigation

j - down

k - up

h - left

l - right

2k - Go 2 line up from cursor - Similar with other navigations

w - next word end

W - Next word start

e - End of the next word

b - last word

B - last word begin

search

/nginx - Find first occurrence of nginx after cursor

?nginx - Find first occurrence of nginx before cursor

Roaming the file

:12 - Go to line number

$ - Beginning of the current line

0 - end of the current line

G - go to last line

gg - go to first line

  • 2k - Go 2 line up from cursor
  • 5j - go 4 lines down from the cursor

Insert Mode

with i we can start using alphanumeric keys to edit our code/lines file

I - Insert at the beginning of the line/Goto beginning of the line

A - Append insert at the end of the line

a - append after at the cursor

i - Insert before at the cursor

Undo last change

ESC + u * keep going back to previous changes

Visual Mode

We can edit/select lines/code with commands without using mouse.

Enter into the visual mode: small v, capital V,

v - selects the characters -> up down left right

  • d to remove selected characted

V - selects the whole current line

  • d to remove selected lines

ctrl + v (not command + v of mac )- Enters into visual mode with first character selected only -> right + up + down

  • Useful to correct the multiple lines indentations

Indentation

>> - shift right

<< - shift left

Multiple Lines indentation -> V + >>

Replace Mode

Same as visual mode, though we can replace patterns with this command.

R - Start replacing the characters from the cursor

r - replaces the current characted with entering into replace mode

Operators + Motion keys

c - change (paste) d - delete (probably cut) y - yank (copy)

Action

c + w -> replace the current word + get into the insert mode

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment