Skip to content
Projets

À propos

A curriculum for leveling up your Vim

Apprentissage et éducation

Comment ces chiffres sont mesurés

Progression mesurée des étoiles

in 24h
0
in 7 days
0
in 15 days
0
in 1 month
Historique en cours

Variations nettes sur des périodes qui se chevauchent, pas des totaux quotidiens. Les mesures absentes restent vides. Les étoiles indiquent l’intérêt, pas la qualité.

README.md

Original

Vim 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
    • :on
    • CTRL-W {H,J,K,L} move window to edge.
    • CTRL-W r rotate windows.
    • CTRL-W _ maximize current window (vertically); count to size to specific height 10 CTRL-W _.
    • CTRL-W | maximize current window (horizontally).
    • CTRL-W = equalize window sizes (vertically and horizontally).
    • CTRL-W t jump to topmost window.
    • CTRL-W b jump to bottommost window.
    • Common re-mappings:
      • CTRL-h → CTRL-W h to focus window on left.
      • CTRL-j → CTRL-W j to focus window below.
      • CTRL-k → CTRL-W k to focus window above.
      • CTRL-l → CTRL-W l to focus window on right.
  • Tabs
    • :tabe
    • CTRL-W T
    • gt/gT next/previous
    • {count}gt jump 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, zC close folds recursively.
    • zo: open fold, zO open 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=indent vs marker (eg. ~/.config/nvim/init.lua).

Navigation

Editor fundamentals

  • Motions
    • h, j, k, l for movement
    • gj, gk for virtual movement
    • w forward to beginning of word, or W (WORD)
    • b back to beginning of word, or B (WORD)
    • e forward to end of word, or E (WORD)
    • ge back to end of last word, or gE (WORD)
  • f (mnemonic: "find"), F (in reverse)
  • t (mnemonic: "up to", "until"), T (in reverse)
  • ; repeat last f/F/t/T operation
  • , repeat last f/F/t/T operation, 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
    • o open line below for editing in INSERT mode.
    • O open line above for editing in INSERT mode.
    • A enter INSERT mode at end of line.
    • I enter INSERT mode at beginning of line.
  • Useful "fundamental" plugins:

Tools

  • Marks
    • a-z are in-file marks, A-Z are 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}p or "{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>)
  • Command-mode tricks:
    • Global operations
      • :g/foo/ d delete lines matching "foo" (d is an "Ex" command; can use others, like :s etc).
      • :v/foo/ d delete lines not matching "foo".
      • :%sort sort everything (:%sort n sort 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. like a*?)
          • a{-1,} (ie. like a+?)
        • Positive look-ahead (zero-width match): ab@= (ie. like a(?=b)).
        • Negative look-behind (zero-width match): ab@! (ie. like a(?!b)).
        • Positive look-behind (zero-width match): a@<=b (ie. like a($<=b)).
        • Negative look-behind (zero-width match): a@<! (ie. like a(?<!b)).
        • Easy to remember:
          • \zs do a zero-width match anywhere, setting start of match to that position; eg:
            • Positive look-behind: a\zsb
          • \ze do a zero-width match anywhere, setting end of match to that position; eg:
            • Positive look-ahead: a\zeb
      • Replacement modifiers:
        • \u makes next character uppercase
        • \U makes everything uppercase until \E/\e
        • \l makes next character lowercase
        • \L makes everything lowercase until \E/\e

Miscellaneous tips

  • Indenting and dedenting:
    • VISUAL mode: >>, <<
    • INSERT mode: CTRL-d (mnemonic: "dedent"), CTRL-t (mnemonic: "tab")
  • In INSERT mode, CTRL-O to execute one command and return to insert mode.
  • gv reselect last VISUAL selection
  • ga show ASCII value at current position
  • g8 show UTF-8 value at current position
  • g CTRL-g show current cursor position and total counts (columns, lines, words, bytes)
  • gu{motion} make lowercase
  • gU{motion} make uppercase
  • g~{motion} toggle case
  • gq{motion} format lines
  • CTRL-a increment number
  • CTRL-x decrement number
  • In INSERT mode, CTRL-r ={expr} to insert the value of an expression.

Customizing Vim

Debugging and troubleshooting

  • :verbose set ...?
  • :verbose map <prefix>
  • 'verbose' and 'verboselog'
  • Startup profiling: vim --startuptime log.txt

Resources

Explorer des projets similaires

Chargement…