basic vim motions
autocomplete
- ctrl+P autocomplete tab to switch suggestions
- ctrl+N autocomplete tab to switch the other direction
insert-modes
i
- insert before cursor. (I
start of line)a
- insert after cursor. (A
end of line)o
- add newline then insert (O
for above)gi
- insert mode at last change
ctrl+c
to exit insert modectrl+h
delete last char typedctrl+w
delete last word typedctrl+u
delete last line typed
select-mode
v{motion}{operator}
Used to select text.
v
- visual mode characterV
- visual mode linewise<C-V>
- visual blockaf
- selects increasing large blocksgh
- hover mouse over cursor (ex for type info)
vscode-fileexplorer
ctrl+w THEN h
- to move left one tabctrl+p
- go to filectrl+shift+o
- go to symbol in filectrl+t
- go to symbol in workspace
cmd-mode
:edit {relative-path-to-file.js}
- to create a new file. Same as:e
:write
,:w
- save file.:wall
to save all:quit
,:q
- quit.:q!
- ignores complains q might have (ex not saved warning)wq
- save then quit.wall
to save all
Movement
hjkl
- move left-up-down-rightw
- beginning next word (W includes. )e
- end next word (E includes, or the full Iam_A_WORD(WORD) )b
- move backwards to start of word (again with B to comined.ones() )ge
- move backwards to end of word
Searching in line of chars
f{char}
- find and move to next occurance of char - only inside lineF{char}
- find and move to previous occurance of char - only inside linet{char}
- find and move unTil/before char (like f)T{char}
- find and move unTil/before char (like F);
and,
- (after using f or t) repeat search
big horizontal moves
0
: Moves to the first character of a line^
: Moves to the first non-blank character of a line$
: Moves to the end of a lineg_
: Moves to the non-blank character at the end of a line
big vertical moves
}
jumps entire paragraphs downwards{
similarly but upwardsCTRL-D
lets you move down half a page by scrolling the pageCTRL-U
lets you move up half a page also by scrolling
searching moves (accept regex)
You can write regex here ex: 3/## .*
to find the next 3rd h2 in .md
/{pattern}
to search forward?{pattern}
to search backwardsn
to go to the next matchN
to go to the previous matchgn and gN
combine next functionalitz with operation. so.
goes next then deletes.../ENTER ?ENTER
- last search*
- search word under cursor
code navigation
gd
- go definition- under cursor to where code(function) is definedgf
- go file - to file under cursorgg
- top of file{line}gg
- to lineG
- to end of file%
- jump to matching*({[]})
range selection
.
to represent the current line$
to represent last line in file buffer%
to represent entire file
examples:
:2,10d delete lines 2-10
:25,$d delete from 25-eof
:%d delete every line
:5,10t 15 copy lines 5-10 to 15
:5,10m 15 move lines 5-10 to 15
Editing
u
- undoctrl R
- redo
ctrl o
- go back to where cursor was beforectrl i
- go forward to in cursor history
{operator}{count}{motion}
2dw delete 2 words
x
- shortform ofdl
deletes char under cursorX
- shortform ofdh
delete char before cursors
- shortform ofch
deletes char under cursor and inserts~
switch case for single char
Operators
d
- deletec
- change (deletes and enters insert)=
- format codegUw
- uppercase word /g~
- toggle case>
/<
- add/remove indentation
Doubling an operator, operates on whole line: dd
- deletes whole line
Bold an operator is till end-of-line: D
- deletes till end-of-line
- Examples:
d2w deletes 2 words
dt; deletes untill ;
d/hello deletes untill hello
.
- dot-operator - repeats last change
Copy paste
y
- yank (copy) -yy
copy linep
/P
- paste after/before cursorgp
&gP
- same as p but cursor after pasted
yl yanks a letter,
yaw yanks a word,
yas yanks a sentence
yi( yanks everything within (
ddp ddP swap lines
cut and paste
d or c actually cut. so we can just dd
a line then p
it where we want it
text objects
The benefit of these is that they care less about where the cursor is pointed. so they become more reusable with .
{operator}{a|i}{text-object}
i
- innera
- outer
- | identifiers |
---|---|
w | word |
s | sentence |
p | paragraph |
b or ( | block inside () |
[ | block inside [] |
B pr { | block inside {} |
" or ' | quoted text |
t | for tag |
examples:
daw delete a word + trailing whitespace
ciw change inner word
das delete a sentance
da" delete something in quotes
ci" change text inside quotes
dat delete a html-tag
cit change contents of an html-tag
imange we want to delete all this
/this ENTER
daw
THEN n THEN . for each time we find one we want to delete