Skip to content

Instantly share code, notes, and snippets.

@mohamed

mohamed/vim.rst

Last active Jul 25, 2019
Embed
What would you like to do?
Vim cheatsheet

Misc

guu                         : lowercase line
gUU                         : uppercase line
g~~                         : flip case line
gf                          : open file name under cursor (SUPER, requires :set path+=<path_to_file>)
<C-w>f                      : open file name under cursor in a new window
<C-w>gf                     : open file name under cursor in a new tab
<C-o>                       : go to previous file (the one from which you ran `gf`)
ga                          : display hex, ascii value of char under cursor
gv                          : Re-select the previous visual area (ULTRA)
[I                          : show lines matching word under cursor (SUPER)
>i{                         : Block shifting (MAGIC)
q/                          : Search history Window
q:                          : commandline history Window
J                           : join next line to this line

Recording macros

qq                          : record to q your series of commands
q                           : stop recording
@q                          : execute
@@                          : repeat

Quickfix

copen                       : Open the quickfix window
ccl                         : Close it
cw                          : Open it if there are "errors", close it otherwise (some people prefer this)
cn                          : Go to the next error in the window
cnf                         : Go to the first error in the next file

GVIM Difference Function

vimdiff file1 file2
dp                          : "put" difference under cursor to other file
do                          : "get" difference under cursor from other file

Markers

'.                          : jump to last modification line (SUPER)
`.                          : jump to exact spot in last modification line
ma                          : place a mark named "x" at current location
'x                          : jump to mark named "x" at THIS file
'X                          : jump to mark named "X" at ANY file
d'x                         : delete to mark "x"

Tabs

:tab sball                  : move all open files to individual tabs (SUPER)
:tabedit /path/file         : open file in new tab
:tabfind ...                : search file and open in new tab
:tab help ...               : open help in new tab
gt                          : go to next tab
gT                          : go to prev tab

Buffers

:e filename                 : open "filename" in new full-screen buffer
<C-^>                       : switch between two last buffers
:bnext                      : switch to next buffer (just map it to <Tab>)

Registers

"xY                         : yank to register "x" (x may be any a-z)
"xp                         : paste from register "x"
<C-R>x                      : paste from register "x" in INSERT mode
:reg                        : display contents of all registers
:echo @x                    : display (multi-line) content of register "x"
:s/fred/\=@x/g              : sub "fred" with contents of register "x"

Searching

/\Vpattern                  : all charactes in pattern treated literally ex. \
/\cpattern                  : case-insensitive match
/joe/e                      : cursor set to End of match
/joe/e+1                    : cursor set to End of match plus 1
/joe/s-2                    : cursor set to Start of match minus 2
/begin\_.*end               : search over possible multiple lines
/begin\_s*end               : any whitespace including newline
/begin\_.\{-}end            : any whitespace including newline NON-GREEDY

Folding

zo                          : open fold
zc                          : re-close fold
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.