Projects
View on GitHub
wincent/vim-university
About
A curriculum for leveling up your Vim
Learning & EducationMeasured star growth
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- 0
- in 1 month
- Collecting history
Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.
README.md
OriginalVim University
Despite its reputation for minimalism, Vim has a surprising depth that rewards study. Here we list many of its most loved features, some tips, and a list of ideas for things to study or practice to take your Vim usage to the next level.
Where to get help
:h(:help!):h tutor
Laying out your workspace
- Splits:
:sp:vs:onCTRL-W {H,J,K,L}move window to edge.CTRL-W rrotate windows.CTRL-W _maximize current window (vertically); count to size to specific height10 CTRL-W _.CTRL-W |maximize current window (horizontally).CTRL-W =equalize window sizes (vertically and horizontally).CTRL-W tjump to topmost window.CTRL-W bjump to bottommost window.- Common re-mappings:
CTRL-h→CTRL-W hto focus window on left.CTRL-j→CTRL-W jto focus window below.CTRL-k→CTRL-W kto focus window above.CTRL-l→CTRL-W lto focus window on right.
- Tabs
:tabeCTRL-W Tgt/gTnext/previous{count}gtjump to{count}indexed tab
- tmux:
- Splits (panes)
- Windows
- Sessions
- Foreground/backgrounding (
CTRL-Z) vs:terminal - Folds
zm: increase fold level (mnemonic: "more").zM: increase fold level to maximum.zr: reduce fold level (mnemonic: "reduce").zR: reduce fold level to minimum.zc: close fold,zCclose folds recursively.zo: open fold,zOopen folds recursively.za: toggle fold (Pro-tip™️:<Tab>is a good for mapping to this).zA: toggle fold recursively.zv: unfold folds to view cursor line (mnemonic: "view").:set foldlevelstart=1(start with everything folded,99= start with nothing folded).:set foldmethod=indentvsmarker(eg.~/.config/nvim/init.lua).
Navigation
- Movements/motions:
H,M,Lmove cursor to high, middle, low positions.CTRL-Fforward full screen,CTRL-Bbackward full screen.CTRL-Ddown half screen,CTRL-Uup half screen.{,}move to previous/next blank line.ggjump to top of buffer,Gjump to bottom of buffer.%jump to matching brace.- Relative line numbers:
:set number:set relativenumber{count}j: move down{count}lines{count}k: move up{count}lines
- Absolute line numbers:
{count}G: go to line{count}:[range]: go to line[range](eg.:50)
- Scrolling:
CTRL-Escroll up by one line,CTRL-Yscroll down by one line (cursor stays).zzcenter current cursor line in viewport.ztscroll current cursor line to top of viewport.zbscroll current cursor line to bottom of viewport.
- Fuzzy finders:
- NvimTree: https://github.com/kyazdani42/nvim-tree.lua
<LocalLeader>f: To reveal in tree.
- vim-vinegar: https://github.com/tpope/vim-vinegar
- vim-dirvish: https://github.com/justinmk/vim-dirvish
- vim-projectionist: https://github.com/tpope/vim-projectionist
:Ago to alternate file:ASopen alternate in split:AVopen alternate in a horizontal split- Sample configurations:
~/.config/nvim/after/plugin/projectionist.lua
- LSP-powered navigation
- Example project:
~/code/masochist/next - Go-to-definition, hover, autocomplete, inline diagnostics.
- Example project:
- Search-based navigation
- Quickfix list
:cn:cp:cnf:cpf:colder:cnewer- Pro-tip™️:
<Up>,<Down>,<Left>,<Right>are good for mapping to these.
- Location list:
:lne:lp:lnf:lpf:lolder:lnewer
- Plug-ins:
- Ferret: https://github.com/wincent/ferret
- vcs-jump: https://github.com/wincent/vcs-jump
- Quickfix list
- Within-file find-and-replace:
:%s/- Scalpel: https://github.com/wincent/scalpel
- Jump list:
:jumpsCTRL-o,CTRL-i/<Tab>- Filewise jumplist mappings:
~/.config/nvim/plugin/mappings/leader.lua. - Mappings to store big jumps in jump list:
~/.config/nvim/plugin/mappings/normal.lua
CTRL-^: go to previous buffer (suggested mapping:<Leader><Leader>).gf: go to file under cursor.CTRL-W f: go to file under cursor, in split.
Editor fundamentals
- Motions
h,j,k,lfor movementgj,gkfor virtual movementwforward to beginning of word, orW(WORD)bback to beginning of word, orB(WORD)eforward to end of word, orE(WORD)geback to end of last word, orgE(WORD)
f(mnemonic: "find"),F(in reverse)t(mnemonic: "up to", "until"),T(in reverse);repeat lastf/F/t/Toperation,repeat lastf/F/t/Toperation, but in opposite direction.*,#+n/N/{pattern}+?{pattern}- Composite commands:
xp: swap two characters (really,x,p).ggn: go to first match in file (really,gg+n).GN: go to last match in file (really,G+N).
- Common editor operations
oopen line below for editing in INSERT mode.Oopen line above for editing in INSERT mode.Aenter INSERT mode at end of line.Ienter INSERT mode at beginning of line.
- Useful "fundamental" plugins:
- repeat.vim: https://github.com/tpope/vim-repeat (repeat entire mapping instead of last thing in it).
- surround.vim: https://github.com/tpope/vim-surround
cs{from}{to}: change surrounds.ds{delimiter}: delete surrounds.ys{motion}{delimiter}: add surrounds (mnemonic: "yes, surround").
Tools
- Marks
a-zare in-file marks,A-Zare global marks.- Special marks include:
[: last yanked text.<: last visual selection (>is end of last visual selection).^: last place we left INSERT mode..: place where last change was made.
- Set a mark:
:mark {mark}(or shorter,:k{mark}). - Go to mark
`{mark}(exact position within line). - Go to mark
'{mark}(beginning of line contents). - For convenience: https://github.com/kshenoy/vim-signature
m{mark}: to toggle mark;m,to place next available mark.dm{mark}: delete a mark.
- Jumping between marks without naming them:
]'next (or]`).['previous (or[`).
- Registers
:di/:registers"{register}y{motion}and"{register}por"{register}P
- Macros
- Recording a macro:
q{register}(uppercase appends). - Replaying a macro:
@{register}(@@repeats last replay command). - Editing macros:
"{register}p→ edit →"{register}yy<CTRL-v>can be handy here for typing literal control characters.
- Replay plug-in: https://github.com/wincent/replay (default mapping:
<CR>)
- Recording a macro:
- Command-mode tricks:
- Global operations
:g/foo/ ddelete lines matching "foo" (dis an "Ex" command; can use others, like:setc).:v/foo/ ddelete lines not matching "foo".:%sortsort everything (:%sort nsort numerically; for other modifiers, see:h :sort).
- Regex patterns:
- Magic and "very magic":
- Perlisms in Vim syntax (these in "very magic" syntax):
- Non-greedy mappings:
a{-}(ie. likea*?)a{-1,}(ie. likea+?)
- Positive look-ahead (zero-width match):
ab@=(ie. likea(?=b)). - Negative look-behind (zero-width match):
ab@!(ie. likea(?!b)). - Positive look-behind (zero-width match):
a@<=b(ie. likea($<=b)). - Negative look-behind (zero-width match):
a@<!(ie. likea(?<!b)). - Easy to remember:
\zsdo a zero-width match anywhere, setting start of match to that position; eg:- Positive look-behind:
a\zsb
- Positive look-behind:
\zedo a zero-width match anywhere, setting end of match to that position; eg:- Positive look-ahead:
a\zeb
- Positive look-ahead:
- Non-greedy mappings:
- Replacement modifiers:
\umakes next character uppercase\Umakes everything uppercase until\E/\e\lmakes next character lowercase\Lmakes everything lowercase until\E/\e
- Global operations
Miscellaneous tips
- Indenting and dedenting:
- VISUAL mode:
>>,<< - INSERT mode:
CTRL-d(mnemonic: "dedent"),CTRL-t(mnemonic: "tab")
- VISUAL mode:
- In INSERT mode,
CTRL-Oto execute one command and return to insert mode. gvreselect last VISUAL selectiongashow ASCII value at current positiong8show UTF-8 value at current positiong CTRL-gshow current cursor position and total counts (columns, lines, words, bytes)gu{motion}make lowercasegU{motion}make uppercaseg~{motion}toggle casegq{motion}format linesCTRL-aincrement numberCTRL-xdecrement number- In INSERT mode,
CTRL-r ={expr}to insert the value of an expression.
Customizing Vim
- Leader mappings:
:let mapleader = " "(Vimscript), orvim.g.mapleader = ' '(Lua)~/.config/nvim/plugin/mappings/leader.lua
- Local leader:
:let maplocalleader = "\\"(Vimscript), orvim.g.maplocalleader = '\\'(Lua)
- ftplugins
'gitcommit':~/.config/nvim/ftplugin/gitcommit.lua'markdown':~/.config/nvim/ftplugin/markdown.lua
- Lua
- Useful plug-ins:
- undotree: https://github.com/mbbill/undotree
- vim-easydir: https://github.com/duggiefresh/vim-easydir
- vim-fugitive: https://github.com/tpope/vim-fugitive
- vim-lion: https://github.com/tommcdo/vim-lion
- And many others: https://github.com/wincent/wincent/blob/main/.gitmodules
- Pro-tip™️: Map
<leader>qto:q, to avoid accidentally typingq:. - Useful settings
'colorcolumn''cursorline''shortmess''switchbuf'(seeusetab,uselast)'virtualedit'(block)
Debugging and troubleshooting
:verbose set ...?:verbose map <prefix>'verbose'and'verboselog'- Startup profiling:
vim --startuptime log.txt
Resources
- Screencasts and streams:
- Forums:
- Books:
- Games and challenges:
Explore related projects
Loading…