Skip to content

Latest commit

 

History

History
77 lines (53 loc) · 1.83 KB

cheats.md

File metadata and controls

77 lines (53 loc) · 1.83 KB

Vim freezes

Probably a was pressed, which is a scroll-locking signal in terminals Just press to unlock the cursor.

Delete all ^M when loading a file from Windows

:%s/^M$//g

^M has to be entered by Ctrl+v+Ctrl+m

Yank all matches regex with grouping in a register

:%s/regex/=setreg('A', submatch(0), 'V')/n :%s/regex <--- possibly with grouping (regex) .../=setreg('register name', select group (number), 'V' = linewise ... ... /n <--- sandbox, it won't actually make changes

Write as sudo

:w !sudo tee %

Load an hex version of buffer and revert back

:%!xxd :%!xxd -r

Fast format a json file or chunk

:%!python -m json.tool

Sort and filter duplicates

:sort u

Grep IP addresses from commandline

grep -Eo '[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}'

Format a XML document

silent %!xmllint --encode UTF-8 --format -

Apply a macro in a range

:3,15norm! @a

Will apply macro in register 'a' from line 3 to line 15

Clean a register

:exec setreg('', [])

Clean all registers

let regs=split('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/-"', '\zs') for r in regs call setreg(r, []) endfor

Good links

Using external tools with Vim Reddit's Vim Wiki The Patient's Vimmer Vi-improved Power Of Vim