Vim editing tips

Vim editing tips

replace ^M

  • ^M = Ctl-v Ctl-m
  • %s/^M/\r/g

add before each column

  • Ctl+v —-> j to select —> I —> add content —> ESC

delete empty lines

  • g/^$/d

remove whitespace(s) at the end of line

  • %s/\s+$//g

Insert file name (and path)

  • :r! echo %
  • :r! echo %:p

sort by columns

  • %!sort -k4,4n -rk3,3

Other shortcuts

  • :set nobackup
  • :set fileencoding=
  • :set guifont=
  • :set nowrapscan # especially useful when you apply macros: no infinite looping
  • :syntax on / off

Insert increasing / decreasing numbers

  • Ener number e.g., Smp_30001 -> qr RECORD_START -> 0 -> Y -> p -> Ctl+a -> q RECORD_END -> 10@r

Show word/char stats

  • g -> Ctl-g
Z. Lu avatar
Z. Lu
Data scientist, bioinformatician, retro fan and web lover.
comments powered by Disqus