Skip to content

Vim

:w !sudo tee "%"

Shift+V from point of cursor and press D key to delete.

:%s/search/replace/g
:noh
  1. Shift+V from point of cursor to enter Visual Block mode
  2. Move up/down to select multiple lines
  3. : to enter command mode
  4. s/^/#/g to replace first character on the lines with a #

The prompt will look something like this when all done:

:'<,'>s/^/#/g
  1. Set text width to desired width:

    :set textwidth=80
  2. Move to start of file:

    gg
  3. Format text from start to the end:

    gqG
Terminal window
$ hyperfine "nvim --headless +qa" --warmup 5
Benchmark 1: nvim --headless +qa
Time (mean ± σ): 40.3 ms ± 1.8 ms [User: 16.1 ms, System: 8.0 ms]
Range (min … max): 37.2 ms … 46.3 ms 58 runs
  • A single line: ==
  • A range of lines: <range>==
  • Entire file: gg=G
    • Probably won’t be as intelligent as a language-specific formatter
:g/^/m0

More information here.

Use visual mode to selectively reverse ((:g|:global) command is still required).

Useful for re-ordering commits with git rebase -i if you know you made the most relevant commit first and subsequent minor changes afterwards.

:set spell
:set spell!

Run :diffthis in both of the buffers. Run :diffoff to disable.

:cq
:e <file path>

When using relative paths, your actual working directory needs to match as well

Get the file path to the currently opened buffer

Section titled “Get the file path to the currently opened buffer”
  1. Enter Insert mode
  2. Press <Ctrl-r> and %

The active line should now contain the file path to the currently opened buffer, but remember that this is relative to the current working directory. So, whereever Vim was opened will be the root.