Helpful VIM Routines

Helpful VIM Routines
  • Removing all non text in nsd:
    :v/\a*\.a*/d
    :%s/^.* .* \([a-zA-Z]*\.[a-zA-Z]*\).*$/\1/
    :%s/^.* .* .* \([a-zA-Z]*32\.[a-zA-Z]*\).*$/\1/
  • Formatting html text
    :filetype indent on
    :set filetype=html # abbrev - :set ft=html
    :set smartindent # abbrev - :set si
    ESC ESC
    gg=G
  • Altering case of characters Lines
    ~ : Changes the case of current character
    guu : Change current line from upper to lower
    gUU : Change current LINE from lower to upper
    guw : Change to end of current WORD from upper to lower
    guaw : Change all of current WORD to lower
    gUw : Change to end of current WORD from lower to upper
    gUaw : Change all of current WORD to upper
    g~~ : Invert case to entire line
  • Print to pdf:
    :hardcopy > myfile.pdf
  • Find closing html tag
    1. Place the cursor on the tag.
    2. Enter visual mode by pressing v.
    3. Select the outer tag block by pressing a+t or i+t for inner tag block.
    Your cursor should jump forward to the matching closing html/xml tag. To jump backwards from closing tag, press o or O to jump to opposite tag.
    Now you can either exit visual by pressing Esc, change it by c or copy by y.
  • VIM can't remove <CTRL+V><CTRL+M> from file try SED
    First cat the file to see where ^M are in the file using -v to show none printing characters, example:
    cat -v file.txt
    Then using sed remove chars and print to new file, example:
    sed -e "s/^M//" filename > newfilename
    To enter ^M hold down CTRL and type V then M in succession
  • Example to get all printable text folowed by spaces etc, see: VIM RegEx
    :%s/^\p*\t//