skip to main content

(Neo)Vim is Cool

But also complicated.

Published 2024/07/03

Updated 2024/07/05


Table of Contents


    Normal Mode

    Jumps


    Marks


    Registers


    Folds

    Fold level > foldlevel will be closed. Zero (default) will close all folds. Local to window.

    Fold with lines < foldminlines will always be open. Default 1.

    Currently using nvim-ufo to manage folds.

    Opening and Closing Folds

    zo
    {count} zo
    Open one fold under the cursor.
    Open count fold levels under the cursor.
    zO
    Open all folds under the cursor.
    zc
    {count} zc
    Close one fold under the cursor.
    Close count folds under the cursor.
    zC
    Close all folds under the cursor.
    za
    {count} za
    Toggle one fold under the cursor.
    Toggle count fold levels under the cursor.
    zA
    Toggle all folds under the cursor.
    zv
    View cursor line. Unfold until the line in which the cursor is located is not folded.
    zx
    Update folds. Undo manually opened and closed folds. Re-apply foldlevel, then do zv. Forces recomputing folds.
    zX
    Undo manually opened and closed folds. Re-apply foldlevel. Forces recomputing folds.
    zm
    fold more. Decrease foldlevel.
    zM
    Fold most. Set foldlevel to zero, i.e. close all folds.
    zr
    Fold reduce. Increase foldlevel.
    zR
    Fold reduce to minimum. Set foldlevel to max, i.e. open all folds.
    zi
    Toggle foldenable.

    Moving Over Folds

    [z
    Move to the start of containing open fold.
    ]z
    Move to the end of containing open fold.
    zk
    Move upwards to the end of the previous fold.
    zj
    Move downwards to the start of the next fold.

    /{some text}Enter
    Search forward for some text.
    n
    Move cursor to next result.
    N
    Move cursor to previous result.
    Ctrl+l
    :mod[e]
    Clear and redraw screen.
    Clears search highlights (:noh[lsearch]) and updates diffs (:dif[fupdate]).

    Buffers

    Create

    Close

    Focus

    Ctrl+^
    Edit alternate file in current window. Usually last edited file.
    {count} Ctrl+^
    Edit count buffer in current window.

    Windows

    Creating a window will fail if there is not enough room. Every window needs at least one screen line and column, sometimes more.

    Windows are numbered starting from 1.

    Windows are numbered from top-left to bottom-right.

    Create

    Ctrl+w s
    Ctrl+w S
    Ctrl+w Ctrl+s
    :[N]sp[lit] [++opt] [+cmd] {file}
    Split horizontally.
    Make the new window N rows high.
    Opens same file buffer if not specified.
    Note: Ctrl+s does not work on all terminals and might block further input. Use Ctrl+q to get going again.
    Ctrl+w v
    Ctrl+w Ctrl+v
    :[N]vs[plit] [++opt] [+cmd] {file}
    Split vertically.
    Make the new window N columns wide.
    Opens same file buffer if not specified.
    Ctrl+w ^
    Ctrl+w Ctrl+^
    Open alternate file in horizontal split.
    Matches behaviour of Ctrl+^ .

    Close

    Ctrl+w c
    Close the current window.
    Fails if there is only one window. Ctrl+w q will close last window and exit, so this is safer.
    Ctrl+w Ctrl+c does not work, because the Ctrl+c cancels the command.
    Ctrl+w o
    Ctrl+w Ctrl+o
    Keep only active window, closing all others.

    Focus

    Cursor will cycle from end to start, and vice versa.

    Ctrl+w w
    Ctrl+w Ctrl+w
    Move cursor one window forward (down/right).
    Ctrl+w W
    Move cursor one window backward (up/left).
    {count} Ctrl+w w
    {count} Ctrl+w Ctrl+w
    {count} Ctrl+w W
    Move cursor to window number count.
    If count > number of windows, go to last window.
    Ctrl+w h j k l
    Ctrl+w Ctrl+h j k l
    Move cursor to window left/right/above/below current one.
    Ctrl+w t b
    Ctrl+w Ctrl+t b
    Move cursor to top-left/bottom-right window.

    Move

    Ctrl+w r
    Ctrl+w Ctrl+r
    Rotate windows downwards/rightwards.
    The cursor remains in the same window.
    This only works within the row or column of windows that the current window is in.
    Ctrl+w R
    Rotate windows upwards/leftwards.
    The cursor remains in the same window.
    This only works within the row or column of windows that the current window is in.
    Ctrl+w x
    Ctrl+w Ctrl+x
    Exchange current window with next one.
    If there is no next window, exchange with previous window.
    The cursor is put in the other window.
    When vertical and horizontal window splits are mixed, the exchange is only done in the row or column of windows that the current window is in.
    Ctrl+w H J K L
    Move current window to far left/right/top/bottom, and use full height/width.
    Ctrl+w T
    Move the current window to a new tab page.
    Fails if there is only one window in the current tab page.

    Resize

    Ctrl+w =
    Equalize width and height of all windows.
    Ctrl+w _
    Maximize height of the active window.
    Ctrl+w |
    Maximize width of the active window.
    Ctrl+w - +
    Incrementally decrease/increase active window height.
    Ctrl+w < >
    Incrementally decrease/increase active window width.

    Tabs

    Tabs are numbered starting from 1.

    Create

    :tabe[dit] {filename}
    Open filename in a new tab.

    Close

    :tabc[lose]
    Close the current tab page and all of its windows.
    :tabo[nly]
    Keep only the active tab page, closing all others.

    Focus

    gt
    Switch to the next tab page.
    gT
    Switch to the previous tab page.
    {count}gt
    Switch to tab page number count.

    Move

    :tabmove
    Move current tab page to the end.
    :tabmove 0
    Move current tab page to the beginning.
    :tabmove {count}
    Move current tab page to position count.

    Terminal Mode

    :te[rminal]
    Create new interactive shell.
    Ctrl+\ Ctrl+n
    Return to Normal Mode.

    Lua


    LSPs

    K
    vim.lsp.buf.hover()

    Diagnostics

    [d
    vim.diagnostic.goto_prev()
    ]d
    vim.diagnostic.goto_next()
    Ctrl+w d
    Ctrl+w Ctrl+d
    vim.diagnostic.open_float()

    Notes

    Shortcuts are sometimes written as <C-A> to mean: hold Ctrl, press and release a, release Ctrl. Same for other modifiers.

    Modifiers are not combined with uppercase, only lowercase, so <C-w> and <C-W> both mean Ctrl+w.

    <CR> means "carriage return", i.e. Enter.

    : to switch to command line mode, where commands can be typed, and tab-completion is available.

    A buffer is the in-memory text of a file.

    A window is a viewport on a buffer.

    A tab page is a collection of windows.