Skip to content

Instantly share code, notes, and snippets.

@laughnan
Created April 23, 2020 19:12
Show Gist options
  • Save laughnan/78ac754cb6849b46ab9c7ba482221d3b to your computer and use it in GitHub Desktop.
Save laughnan/78ac754cb6849b46ab9c7ba482221d3b to your computer and use it in GitHub Desktop.
quick vim commands
basic movements
————————
i - enter insert mode
ctrl+[ - exit insert mode (or esc, but this is easier)
h - left
j - down
k - up
l - right
ctrl+d - page down
ctrl+u - page up
w - move forward one word
b - move backwards one word
u - undo
ctrl+r - redo
x - delete current character over cursor
G - move to end of file
gg - move to beginning of file
$ - move to end of line
^ - move to beginning of line
J - move next line to end of current line
advanced movements
——————————
a - move right, enter insert mode (shortcut for li)
s - delete current character, enter insert mode (shortcut for xi)
A - move to end of line, enter insert mode (shortcut for $i)
o - insert new line, enter insert mode (shortcut for A<enter>)
f<character> - move forward to character on current line
F<character> - move backwards to character on current line
t<character> - move forward to just after character on current line
T<character> - move forward to just after character on current line
; - repeat last f/F/t/T movement
% (when cursor is on or adjacent to a ([{ or }]) character) - move to opening/closing character
ctrl+o - jump to cursor’s previous position
ctrl+i - jump to “next” cursor position (opposite of ctrl+o)
actions
———
c - change
d - delete
y - yank
= - format/auto-indent
<any number> - do motion n times
v - visual select
V - visual line select
search/replace (action)
——————————
/text - search forward for text
?text - search backward for text
n - move to next occurrence of searched text
N - move to previous occurrence of searched text
:s/find/replace - replace next instance of “find” with “replace” on current line
:s/find/replace/g - replace all instances of “find” with “replace” on current line
:%s/find/replace/g - replace all instances of “find” with “replace” in entire filew
prefix with :’<,’> to do this find/replace only in your visual selection (the goofy ‘<,’> will be automatically prepended when you have something selected and type : )
“motions” (actions+movements combos)
——————————————————
. - repeat last motion
some useful examples, but remember you can pair any action with any movement!
3j - jump 3 lines down
dG - from wherever the cursor is, delete everything else until the end of the file
var chris = “what a cool guy”;
ci” - with cursor anywhere inside the quotes, type this to change inside the “, and enter insert mode
ct= - with cursor anywhere before the = sign, type this to change all character until after the = sign, then enter insert mode
dF= - with cursor anywhere after the =, type this to delete all characters (backwards) until the =
d/cool - with cursor anywhere before cool, type this to delete all characters until the first instance of “cool” is found by the search
var chris = function() {
console.log(“what a cool guy”);
};
=% - with cursor on the }, type this to auto-indent everything inside the function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment