Wiki/vim.md

4.2 KiB

Vim Cheat Sheet

  • Path autocompletion ctrl + x ctrl + f
  • Enter command mode from insert mode for one command ctrl + o
  • Edit multiple consecutive lines:
    1. Select lines using ctrl + v
    2. Enter insert mode using shift + i
    3. Made edit and then press ESC

Search, Replace etc.

  • Search and replace in line range :<start>,<end>s/<search>/<replace>/g

Spell Correction

  • Enable :setlocal spell
  • Set language :setlocal spelllang=en

Macro

  • Run macro on range of lines :<startLine>,<endLine>norm! @<macro>

Edit Binary

  • Open file with vim

  • Enable binary :set binary

  • Convert to binary and open: :%!xxd

  • Edit the hex numbers

  • Convert back to plain text: :%!xxd -r

  • Count words: press g and ctrl-g

    • Also works with selections

LSP

  • Show which code action are supported by a language server: :lua print(vim.inspect(vim.lsp.buf_get_clients()[1].resolved_capabilities))

Insert Mode Bindings

From here

I would not remap any of these:

  • <C-@> and : Repeat last insert (and automatically escape with <C-@>). These are basically the same as .. Indispensable once you get used to them.
  • and : Change indent level even if you're not at the beginning of the line. Handy, but I don't use it much.
  • and : Copy character from below/above the cursor. Sort of useful, not terribly. But not having them would drive me nuts.
  • : A prefix key. I don't really care about u to split the insert into multiple undo levels. Almost no one uses j/k to start a new insert a line down/up at the same column the current insert started on, but I'm a huge fan. I wouldn't touch this.
  • : This is literally the same as . Don't you dare touch this.
  • : This is literally the same character you get from hitting Enter. Don't you dare touch this.
  • and : Basic word completion. Extremely useful. I would never touch this.
  • : Return to insert after a single normal command. You can always just use escape. Has its uses though.
  • and : Since these are used by terminals for the locking feature, they're unbound in basically every terminal program. That makes them great candidates for screen/tmux prefixes (if you disable the locking feature first). Generally not safe for portable remapping though.
  • : Like pasting registers from insert mode. This is extremely useful and should not be touched.
  • and : Delete line/word. Extremely useful. Works similar but not exactly the same as in cooked terminal though, which is frustrating...
  • : Insert literal characters. I use this a lot.
  • : A prefix to several completion functions. I would say is probably the most indispensable (complete filename), but a lot of them are handy. Read :help i^X to learn about them all.
  • <C-[>: This is literally . Don't you dare touch it.

I wouldn't mind remapping these:

  • : This is safe.
  • : Really escape. I'm not a big fan.
  • : This is safe.
  • and <C-?>: These behave the same as backspace, but they aren't literally backspace. I wouldn't mind too much if I lost these.
  • : Literal newline. Not used too much in its own right. If mappings worked in pastes, remapping this would mess up your multiline pastes, but since they don't, it should be safe to remap.
  • : Digraphs. I don't use them. If you just need occasional characters maybe, like a single Greek character or a way to type an em dash, they're fine. If you try to type in a foreign script using this feature, God help you.
  • : This is safe.
  • : In a terminal, backgrounds Vim, though it shouldn't do that in insert mode.
  • <C->: This is mostly safe. If you're using in mappings, you should probably use <C-> instead, so the cursor doesn't shift inconsistently if you're at the end of the line. It's very unlikely I'd use that outside of mappings though.
  • <C-]>: Abbreviations. I've never used this.
  • <C-^>: Useless in insert mode.
  • <C-_>: Toggling reverse insert (if you have some special nondefault settings). Useless for almost everyone.

Performance

  • Show startup time using flag --startuptime <OUT_FILE>