Skip to content

Instantly share code, notes, and snippets.

@M-Mueller
Last active March 13, 2018 14:37
Show Gist options
  • Save M-Mueller/906e388be441137e5ce3497cce3cff7a to your computer and use it in GitHub Desktop.
Save M-Mueller/906e388be441137e5ce3497cce3cff7a to your computer and use it in GitHub Desktop.
vim fu

Visual Mode

vib - Select everything inside parenthesis
vab - Select everything inside parenthesis (including parenthesis) vi" - Select everything inside double/single quotes
viB vi{ - Select curly brace block
gv - Select last visual block
VISUALo - Move cursor to other end of the selection

Movement

% - Jump to matching brace
{ } - Move to next/previous paragraph
mq - Add mark q at cursor position
'q - Jump to mark q
; - Repeat last f, t, F or T search
zz - Center on cursor
H M L - Jump to top/middle/button of the screen
Ctrl+U/D - Scroll half a page up/down

Editing

~ - Change case
VISUALU - Change to upper case
VISUALu - Change to lower case
== - Fix line indent
>aB - Indent block
Ctrl+A/X - Increment/decrement number under cursor
R - Start overriding text under cursor
di( - Delete everyting inside parenthesis

Copy & Paste

"ayy - Copy (yank) line to register a
"Ayy - Append line to current content of register a
"ap - Paste content from register a

Regex

:s/foo/bar/g - Search 'foo' and replace with 'bar' anywhere in current line
:%s/foo/bar/g - Same as above but anywhere in current file
:%s/\%Vfoo/bar/g - Replace 'foo' with 'bar' in visual block only
\( \) - Grouping
\1 \2 ... - first, second, ... matched pattern
. - Matches any character (except newline)
* \+ \{n} \{n,m} - Matches 0 or more, 1 or more, exactly n times, from n to m characters
\_s - Matches whitespace or newline character
:s/x/\r/g - Replace every occurence of 'x' with a newline
\(foo\|bar\) - Matches either 'foo' or 'bar'
See vimregex

Various

:w !sudo tee % - Save current buffer with sudo rights
:noh - Clear search highlight
:r !ls - Insert output of ls at current cursor position
Ctrl+R " - Paste last yanked text (also works in command-line mode)
Ctrl+Q - Makes VIM responsive again if it hangs after Ctrl+S

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