Vim tips

Motions

  • ciw: Change the inner word
  • dwi: Delete current word and enter edit mode
  • d$ or D: delete all after current position
  • $: go to the last char normal-mode
  • w and b: move a word forward or backwards
  • daw: delete from the current char til the first letter on next word
  • d9w: delete 9 words
  • dap: delete around paragraph
  • dd: delete a line
  • 2dd: delete two lines
  • u and ctrl+o: undo and redo editions

more of this:

  • 0: go to beginning
  • $: go the the endline
  • I: Edit beginning line
  • A: Edit end of the line
  • O: Add blank line above
  • o: Add blank line below
  • J: Join bottom line to current
  • D: Remove all to the end from current char
  • dd: remove line
  • gg: jump to first line
  • G: jump to last line

Moving things around

  • Join (move) the line bellow at the end of the current: gJ
  • Join lines by removing tabs and newlines (supports visualmode): J
  • Split a long line in multiple sized lines: %!fmt --width=75 --split-only

Markdown

  • Generate a ToC with anchor links: GenTocGFM
  • Open a buffer with the markdown headers navigation: Toc:

Stuff

  • Delete blank lines: :g/^$/d:
  • Correct a file edited on windows os: :ed ++ff=dos %:
  • Go back to terminal and go back again to vim: CTRL+z & fg:

FZF and Vim

  • Search recent opened files and open it vertically splitted: :History + CTRL+v:
  • will uppercase the selection

Edits

  • shift+I will go to the first letter in the line and enter edit mode
  • shift+A will go to the last letter in the line and enter edit mode

Files

  • gf - Edit existing file under cursor in same window
  • C-W f - Edit existing file under cursor in split window
  • C-W C-F - Edit existing file under cursor in split window
  • C-W gf - Edit existing file under cursor in new tabpage

Buffers

  • C-W L - Moves a horizontal buffer to vertical

Tabs

  • 4gt: Go to Tab number 4
  • :g//#: Incremental search and list matches with line numbers

Other tips

# delete white lines
:g/^$/d

# autoindent all file
gg=G

# uppercase
shift+U

Commands

Deletions:

  • :.,$d : From the current line to the end of the file.
  • :.,1d : From the current line to the beginning of the file.
  • 10,$d : From the 10th line to the end of the file.

Deletions by search:

  • :g /word/d: Delete lines that has word
  • :g!/word/d: The opposite
  • :g/^$/d: Delete blank lines

Copying and pasting

  • :364,757y Copy range
  • :364,757t2 Copy and paste two lines after current
  • :364,757t. Copy and paste in current line

Powerful plugins

Git

  • Git blame

Plugins

  • <leader>KP: Paste result from Cheatsh
  • M-CR: Results from Copilot

mkdx

  • LEADER + I: List headers in a buffer
  • LEADER + i: Update TOC