Skip to content

Instantly share code, notes, and snippets.

@Clish254
Created April 4, 2023 14:52
Show Gist options
  • Save Clish254/c9184785df11159e1d5a765aab5cec7c to your computer and use it in GitHub Desktop.
Save Clish254/c9184785df11159e1d5a765aab5cec7c to your computer and use it in GitHub Desktop.
Vim crash course

Quiting vim

:q

Quit only if all changes are saved

:q!

Quit without saving all changes

:wq

Save all changes and quit

Movement commands

h

Move horizontally to the left

l

Move horizontally to the right

j

Move vertically down

k

Move vertically up

gg

Move to the top of the file

G

Move to the bottom of the file

w

Move forward by one word

W

Move forward by one word but ignore punctuation, space will be used as word seperator.

e

Move to the end of a word

b

Move back by one word

B

Move back by one word but ignore punctuation, space will be used as word seperator.

0

Move to the beginning of a line

$

Move to the end of a line

space

Move right

{

Move one paragraph up

}

Move one paragraph down

-

Move to first character in the previous line.

+

Move to the first character in the next line

%

Show matching curly brace or parenthesis

i

Insert text before current cursor position

a

Insert text after current cursor position

I

Insert text at the beginning of the cursor line

A

Insert text at the end of the cursor line

o

Open up a new line following the current line in insert mode

O

Open up a new line above the current line in insert mode

t<character>

Move to a character(to the left of it), e.g t( will move to the ( character in the line. You can press ; multiple times afterwards to scroll through other matching characters in the line.

f<character>

Move to a character(to the exact position), e.g t( will move to the ( character in the line.

*

scroll through every word matching the word under the cursor

Editing commands

v

Enter visual mode and select text below the cursor as it moves, you can copy or delete the selected text.

V

Enter visual-line mode and select text in the cursor line as it moves, you can copy or delete the selected text.

y

Copy selected text or text below the cursor

yy

Copy text in the whole cursor line

y0

Copy text from the current cursor position(not including) to the beginning of the line.

y$

Copy text from the current cursor position to the end of the line

p

Paste deleted or copied text one line below the cursor line or from the character after the cursor if it was selected in visual mode.

P

Paste deleted or copied text one line above the cursor line or from the character after the cursor if it was selected in visual mode.

d

Delete, should be followed by a movement e.g db(delete one word backwards), dw(delete one word forward), dl(delete one character forward starting from the character under the cursor), d{(delete one paragragh up), d}(delete one paragraph down).

dw

Delete a word starting from the character under the cursor

d<number>w

Delete the specified number of words from the character under the cursor. e.g d5w to delete five words

D

Delete everything to the right from the current cursor position

dt&ltcharacter>

Example, dt) will delete everything from the character under the cursor to(but not including) the ) character.

dgg

Delete everything from the current cursor line to the beginning of the file

dG

Delete everything from the current cursor line to the end of the file

x

Delete the character under the cursor

<number>x

Delete a given number of letters from the current position

C

Delete the rest of the line starting from the current cursor position and enter insert mode.

c<motion>

Example, cw will delete a word from the character under the cursor and put you in insert mode.

ct&ltcharacter>

Example, ct) will delete everything from the character under the cursor to(but not including) the ) character and put you in insert mode.

u

Undo a change

ctrl-R

Redo your undo(s).

.

Repeat the thing you just did, e.g repeat a line deletion,a paste e.t.c

~

Switch the case of the character under the cursor. You can also do <number>~ to repeat the action across n number of letters. e.g 3~ will switch the case of 3 letters from the current cursor position.

r<character>

Replace the character under the cursor with a different character. You can also give it the number if characters to replace e.g 3ro will replace 3 characters from the cursor position with o

R

Puts you in replace mode and as you type the characters under the cursor will be replaced with the typed characters.

>

Indent selected code or code in the cursor line. e.g 3>> will indent 3 lines starting from the current line.

Macros

Check from 41:00 here

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