Vi search and replace tricks, double spacing etc


  • Double spacing:
    • :%s/$/{ctrl-V}{CR}/g
      This command applies an extra carriage return at the end of all lines
  • Strip blanks at end of line:
    • :%s/{TAB}*$//
  • Delete all lines beginning with or matching a pattern:
    • :1,$ /^#/d
      Delete all (first to last line: 1,$ or g) comments lines in file. Delete all lines beginning (^) with "#" (specify text pattern).
    • :g/#/d
      Delete all lines (g) containing comments (comments follow "#") in file. Delete all lines containing "#".
    • :g!/^#/d
      Delete all lines except (g! or v) comment lines beginning (^) with "#".
  • Strip DOS ctrl-M's:
    • :1,$ s/{ctrl-V}{ctrl-M}//

Comments

Popular posts from this blog

Vim vi how to reload a file your editing