Skip to content

Instantly share code, notes, and snippets.

@bengolder
Created June 1, 2011 03:07
Show Gist options
  • Save bengolder/1001720 to your computer and use it in GitHub Desktop.
Save bengolder/1001720 to your computer and use it in GitHub Desktop.
Useful Vim Commands
" The movement commands I use the most, besides h,j,k,l
{ or } " move forward or backward by paragraphs
( or ) " move forward or backward by sentences
W, w, B, b, E, e "These all move by words, if capitalized, it only uses whitespace to divide words.
"W/w moves to the beginning of the next word, B/b moves to the beginning of the
"previous word, and E/e moves to the end of the current/next word
_, $ " move to beginning(_) and end($) of line
gg "go to the top of the file
G " go to the end of the file
<number>G " go to line <number>
/<anything> "go to the next instance of <anything> 'n' jumps to next .. to next .. and so on.
?<anything> "search backwards for <anything> and go there. 'n' jumps backwards instead of forwards
" Some basic text editor commands that took me too long to learn in Vim
" for navigating and opening files
:w " save the current file (write)
:q " close the current file
:e. "turn the current window into a file browser window
:vsp. "split the window vertically and turn the new window into a file browser, at teh current directory
c "While in file browser mode, make this directory the current directory, where any new files will be made.
- "while in file browser mode, move up a directory
/<anything> " while in file browser or normal mode, search and goto <anything> regular expressions are ok
:e <filename> "while in file browser mode, make a file named <filename> in the current directory and start editing it (see above)
" note the :e will not actually make a file until your first save, (after you type :w)
:sav <filename> "save the current file as <filename> in the current directory (see above)
v<movement> "visually select the text passed over by <movement>
V<and optional movement> "Visually select the entire current line, and any lines touched by the optional movement.
"+p " paste from the system clipboard
"+y " copy to the system clipboard
"+x " cut to the system clipboard
" helpful editing commands
i, I, a, A " go to insert mode before (i) or after (a) the curser (lower) or the current line (UPPER) respectively
p, P, x, X, " paste (p) or cut (x) forward (lower) or backward (UPPER) respectively these also work with the system clipboard
c<movement> " change all the text covered by movement (or just whatever's highlighted if no movement)
r<character> " replace the hghlighted text with <character> I often use this to deal with typos
s " remove the highlighted text and go into insert mode to replace it
dd " delete the current line
. " repeat the last edit
u " undo
control + r " redo
o, O "open a new line below (lower) or above (UPPER) the current line
:%s/<anything1>/<anything2>/g " replace <anything1> with <anything2> in the entire document
q<character> " start recording a macro called with '@<character>', stop recording by pressing 'q' again.
~ " change the case of anything highlighted or under the cursor (really useful in Python)
" illustrative combos:
VjjjjX<number>GP " highlight 5 lines, cut them and paste them above line <number>
bve or ve "highlight the current word
ct<character> "change up to <character>
cw " change the current word
dd... "delete a few lines
dw.. "delete few words
ea "insert at the end of the word
bi "insert at the beginning of the word
kI "insert at the beginning of the line above
jA "insert at the end of the line below
v3ws "replace the next three words with what I'm about to type
v_ " highlight from here to the beginning of the line
v$ " highlight from here to the end of the line (this will snag the newline character, so I often follow this with 'h')
d$ " delete to the end of the line
}o " go to the next paragraph and open a line below
V> or V< " indent (>) or de-indent the current line
Vkk> " indent the current lines and a few of the lines above
V{2> " indent every line from here to the beginning of the paragraph 2 times
@bengolder
Copy link
Author

anything that begins with ':' is on command line, and you have to press enter afterwards
press 'escape' to get out of insert mode. You'll find yourself doing this constantly out of habit, as soon as you finish writing anything.

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