Skip to content

Instantly share code, notes, and snippets.

@starkers
Created July 10, 2017 17:35
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 starkers/1a53f5648452c27773f54e0c445d968c to your computer and use it in GitHub Desktop.
Save starkers/1a53f5648452c27773f54e0c445d968c to your computer and use it in GitHub Desktop.
# Normal shortcuts
<ctrl-/> comment/uncomment a line or visual block
<ctrl-f> open "files" in the same dir as current file
<ctrl-p> "CtrlP" file browser (fuzzy finding)
<ctrl-n> "new" buffer
<ctrl-o> "open" previous files from MRU (most recently used)
<leader>? view vim cheatsheet / "help"
<leader>e show/disable "expand tab" toggle
<leader>f toggle the "file browser" pane, ? for help or :help NERDtree
<leader>g toggle "git" hints
<leader>i toggle visible "indent" lines
<leader>[ GitGutter goto Previous Hunk
<leader>] GitGutter goto Next Hunk
<leader>n adjust "number" column (relative/absolute/none)
<leader>p "paste" from current X11 clipboard
<leader>q "quit" a buffer (don't save)
<leader>w trim (trailing) "whitespace"
<leader>d "next" buffer
<leader>a "previous" buffer
# NerdTree file management
s opens the highlighted file in a horizontal split
i opens the highlighted file in a vertical split
cd changes CWD onto selected dir
B access bookmarks
:Bookmark adds dir to bookmarks
# Commenting motion
gc{motion} #EG:
gcip # comment out a whole paragraph
# AutoAlign
# suppose you want to align a block by the second '=' signs
gaip2=
# Splits
^w _ Max out the height of the current split
^w | Max out the width of the current split
^w = normalize all split sizes
# File management
:e reload file
:q quit
:q! quit without saving changes
:w write file
:w {file} write new file
:x write file and exit
# Movement
k
h l basic motion
j
w next start of word
W next start of whitespace-delimited word
e next end of word
E next end of whitespace-delimited word
b previous start of word
B previous start of whitespace-delimited word
0 start of line
$ end of line
gg go to first line in file
G go to end of file
gk move down one displayed line
gj move up one displayed line
# Insertion
# To exit from insert mode use Esc or Ctrl-C
# Enter insertion mode and:
a append after the cursor
A append at the end of the line
i insert before the cursor
I insert at the beginning of the line
o create a new line under the cursor
O create a new line above the cursor
R enter insert mode but replace instead of inserting chars
:r {file} insert from file
# Editing
u undo
yy yank (copy) a line
y{motion} yank text that {motion} moves over
p paste after cursor
P paste before cursor
<Del> or x delete a character
dd delete a line
d{motion} delete text that {motion} moves over
# Search and replace with the `:substitute` (aka `:s`) command
:s/foo/bar/ replace the first match of 'foo' with 'bar' on the current line only
:s/foo/bar/g replace all matches (`g` flag) of 'foo' with 'bar' on the current line only
:%s/foo/bar/g replace all matches of 'foo' with 'bar' in the entire file (`:%s`)
:%s/foo/bar/gc ask to manually confirm (`c` flag) each replacement
# Preceding a motion or edition with a number repeats it 'n' times
# Examples:
50k moves 50 lines up
2dw deletes 2 words
5yy copies 5 lines
42G go to line 42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment