%       # Jump to next matching brace
{       # Jump to previous empty line/paragraph
}       # Jump to next empty line/paragraph
*       # Search forward for word under cursor
#       # Search backward for word under cursor
]s      # Go to next spelling error
[s      # Go to previous spelling error

To or until character:

f{char} # Jump forward to character
F{char} # Jump backward to character
t{char} # Jump forward until character
T{char} # Jump backward until character
;       # Repeat last f/t/F/T search forward
,       # Repeat last f/t/F/T search backward

Jump List Navigation

  • Backward in jump list: <C-o>
  • Forward in jump list: <C-i> or <Tab>

Marks

Marks allow you to set bookmarks in your code:

  • Set mark: m{char}
    • Lowercase (a-z): buffer-local marks
    • Uppercase (A-Z): global marks (work across files)
  • Jump to mark:
    • '{mark} - jump to line start
    • `{mark} - jump to exact position
  • View marks: :marks
    • Telescope key map for marks is <leader>m
  • Clear marks:
    • All manual marks: :delmarks a-zA-Z
    • Specific mark: :delmark {mark}
    • Everything including special marks: :delmarks!

Special Marks

  • ': Position before last jump
  • ": Position when last exiting current buffer
  • [: Start of last change/yank
  • ]: End of last change/yank
  • ^: Position where last stopped Insert mode
  • 0-9: Automatic marks
    • 0: Position where you last exited Vim
    • 1-9: Positions of last 9 changes (1 is most recent)

Line by line navigation: gj & gk Beginning of line: g0 End of line: g$

Text Objects

Operations work with text objects:

  • i" - inside quotes
  • i{ - inside braces
  • ip - inner paragraph
  • is - inner sentence
  • iw - inner word
  • it - inner tag

Examples:

ci"    # Change inside quotes
ca{    # Change around braces (includes braces)
di[    # Delete inside brackets
yi(    # Yank inside parentheses

Formatting text

  • Format to textwidth: gq{motion}
  • Format paragraph: gqip (inner paragraph) or gqap (around paragraph)
  • Format and keep cursor: gwip

Changing case

Lowercase: gu uppercase: gU Alternate cases: g~

Examples:

~       # Toggle case of character under cursor
g~iw    # Toggle case of word
gUiw    # Make word uppercase
guiw    # Make word lowercase

Conjoining lines

With space: J Without space: gJ

Surround Operations (with vim-surround)

ys{motion}{char}  # Add surround
    ysiw"         # Surround word with quotes
    ysip{         # Surround paragraph with braces
cs{old}{new}     # Change surround
    cs'"          # Change single quotes to double quotes
ds{char}         # Delete surround
    ds"          # Delete surrounding quotes

Folding

zM      # Fold everything (close all folds)
zm      # Fold more (increase fold level throughout buffer)
zR      # Unfold everything (open all folds)
zr      # Fold less (decrease fold level throughout buffer)
za      # Toggle fold under cursor
zc      # Close fold under cursor
zo      # Open fold under cursor
zf      # Create fold (in manual mode)
zd      # Delete fold (in manual mode)
zE      # Eliminate all folds

Command Mode (:)

Enter by pressing : in normal mode. Useful commands:

  • <C-r>" - Paste from default register
  • <C-r>/ - Paste last search pattern
  • <C-f> - Edit command in buffer
  • <Up>/<Down> - Navigate command history

Window Management

<C-w>v  # Split vertically
<C-w>s  # Split horizontally
<C-w>=  # Make splits equal size
<C-w>r  # Rotate windows

Register Management

"ay     # Yank into register 'a'
"ap     # Paste from register 'a'
:reg    # Show all registers

Misc

Goto file: gf

  • gf - Open file under cursor
  • <C-w>f - Open in new window
  • <C-w>gf - Open in new tab Reselect last visual selection: gv Run last search/replace over whole document: g&

Opening files

# Opens all files that contain `foo`. Look at ripgrep for more options.
# -l only output filenames, which neovim opens
nvim $(rg -l "aliasses")
# Opens all .md files in ./slips
:args ./slips/**/*.md 
# Writes or save all buffers
:argdo write

JSON

These require jq to be installed and are all commands, meaning they start with :.

% for matching brace

Formatting

Pretty print JSON: %!jq . Compacting: %!jq -c .

Others

Keep only the selected data part: %!jq '...' with … being your JQ pattern. Example: %!jq '.data.items[0].sys'

Validate JSON: %!jq .

Altering JSON

Using JQ we can add things for example with the following command: %!jq '.data.branchCollection.items |= map(.sys += {test: "wow"})'

References

Vim Tips You Probably Never Heard of