Skip to content

Instantly share code, notes, and snippets.

@nbarnwell
Last active October 30, 2017 16:08
Show Gist options
  • Save nbarnwell/38ff958a04c69f6fbdff5c52a2fd1193 to your computer and use it in GitHub Desktop.
Save nbarnwell/38ff958a04c69f6fbdff5c52a2fd1193 to your computer and use it in GitHub Desktop.

Moving around

Action Keys Notes
Down, Up, Left, Right h, j, k, l
Start/end of line ^/$
Beginning of next word/non-whitespace w/W
End of word/non-whitespace e/E
Move until "x" tx
Find, Reverse-find "x" fx, Fx
Find next ;
Search, Reverse-search "x" /x, ?x
Search next n
Goto line 12G, :12
Matching brace/bracket % R#'s CTRL+ALT+L/R might be better

All above is relevant in Visual Mode for making selections. E.g. Selecting to matching brace: F{v%.

Scrolling

[z]+modfier scrolls screen Scroll current line to top [zt] Scroll current line to middle [zz]

Selecting

Enter visual mode [v] Select line [V] Select word [viw] When selecting more than one char, [o] will move the cursor to the beginning/end of the selection. Select "inner"/"around" block (can use "b" or any bracket type of [/], (/), {,}) [vi(] Select quoted string [vi"] (can use any quote marks and supports delete, change etc) Select tag with [t] e.g. [vit] Note "action inner movement" might be better than R#'s CTRL+SHIFT+L/R. Re-select the previous selection when selection is lost [gv]

Editing

Insert/Append [i,I,a,A] Change ['visual mode select'c, C, cw, ciw] Replace single [r] OverwRite mode [R] Insert new lines [o, O] Join lines [J, 2J, gJ] Change case [~] Yank [y, Y, yte] store in register x ["xyte] Put [p, P] Delete [x, dte, D] Delete line [dd] Indent/unindent (linewise) [>, <, 3>] Autoindent (one or more lines) [==]

Substitution

First instance on a line [:s/foo/bar] Whole words only [:s/<foo>/bar Modifiers [g (all instances on line), c (confirm each match) and i (case insensitive)] On all lines [:%s/...] Capture and use backreference by wrapping in (escaped) braces [:s/(foo)/I like \1/g] Similar to PoSh: PS> "Hello world" -replace "(\w+) world", "`$1 everyone" Capture and upper/lowercase backreferences using "\U" and "\L" [:s/(foo)/I like \U\1/g] Ignorecase - what it suggests Smartcase - ignore case if search text is lowercase, otherwise case-sensitive

Loading/Saving

Edit file [:e[path]] Write buffer [:w[path], :w] Save and exit [:x] Quit [:q, :q!] Load into vertical split [:vsplit [filename]] Move between splits [CTRL+W, [h,j,k,l]]

Buffers

New buffer [:new] List buffers [:ls] Close current buffer [:bw] Close buffer X [:Xbw] Close buffers X through Y [:X,Ybw] Close buffer by filename [:bw [filename][tab]] Next/previous buffer [:bn]/[:bp] Make current split max width [:CTRL+W, K]

Commands

List command history [q:] Write register X (including special registers for '@', '/' and ':') to buffer ["Xp] Yank line back to register X after editing [^v$"Xy] Show relative line numbers [:set relativenumber] Highlight current line [:set cursorline] Highlight current column [:set cursorcolumn]

Key Mappings

(nore)n(un)map - Normal mode map (nore)i(un)map - Insert mode map (nore)v(un)map - Visual mode map

Macros

Basic repeat [.] Example: [ql/, [ENTER]a[ENTER][ESC]q]

VsVim

Disabling [CTRL+SHIFT+F12]

ReSharper playing along

Use VsVim to edit, then invoke "Rename refactoring" quickfix.

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