Skip to content

Instantly share code, notes, and snippets.

@jjst
Last active August 8, 2016 21:30
Show Gist options
  • Save jjst/745f6d382759aebccced to your computer and use it in GitHub Desktop.
Save jjst/745f6d382759aebccced to your computer and use it in GitHub Desktop.
Vim cheat sheet

Moving around

h,j,k,l      — move left, down, up, right
{,}          — go to previous/next paragraph (where the previous/next blank line is}
%            — go to matching brace/parens
gg           — start of file
G            — end of file
z.           — to put the line with the cursor at the center,
zt           — to put the line with the cursor at the top
zb           — to put the line with the cursor at the bottom of the screen.
H            — go to top of window
M            — middle of window
L            — bottom of window

While in Visual mode, you can use : to run commands only on the current selection. Super handy for e.g. doing a search and replace on the current selection.

Visual mode

Essential to get some stuff done and easily do multiline edits for example, or replace text within the selection.

v      - enter visual mode
V      - enter line visual mode (selects entire lines instead of starting at the cursor)
Ctrl+V - enter block visual mode (select the same length over multiple lines)

Markers

Very useful to move around in the same file

 mk      - mark current position (can use a-z-A-Z, upper case works between files)
 'k      - move to mark k
 d'k     - delete from current position to mark k
 'a-z    - same file
 'A-Z    - beteween files

Tabs

Creating:

:tabedit {file}   edit specified file in a new tab
:tabfind {file}   open a new tab with filename given, searching the 'path' to find it

Or with Ctrl+P open, use Ctrl+t

Navigation:

gt            go to next tab
gT            go to previous tab
{i}gt         go to tab in position i

Splits

Split window horizontally/vertically. Also useful for navigation in plugins like NERDTree.

Ctrl+w s     Split horizontally
Ctrl+w v     Split vertically
Ctrl+w w     Switch between windows

Vimdiff

https://stackoverflow.com/questions/5288875/vimdiff-what-are-the-most-frequently-used-commands-shortcuts-that-could-get-a-n

Cool Misc Stuff

:so $MYVIMRC    Reload .vimrc
gx              Open URL under cursor in browser
Cltr+R "        Paste contents of register in command mode
:normal .       Repeat last command on each line of the current visual selection
[I              Find all instances of what's under cursor in current folder
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment