Jump to content

Seven Substitution Tricks for vi and Vim

0
  chco's Photo
Posted Mar 11 2011 10:06 AM

This excerpt from vi and Vim Editors Pocket Reference, Second Edition provides a rundown of helpful substitution tips for vi.
  • You can instruct vi to ignore case by typing :set ic.

  • A simple :s is the same as :s//~/.

  • :& is the same as :s. You can follow the & with g to make the substitution globally on the line, and even use it with a line range.

  • You can use the & key as a vi command to perform the :& command, i.e., to repeat the last substitution.

  • The :~ command is similar to the :& command, but with a subtle difference. The search pattern used is the last regular expression used in any command, not necessarily the one used in the last substitute command.

  • Besides the / character, you may use any nonalphanumeric, nonwhitespace character as your delimiter, except backslash, double quote, and the vertical bar (\, ", and |).

  • When the edcompatible option is enabled, vi remembers the flags (g for global and c for confirmation) used on the last substitution and applies them to the next one.


Cover of vi and Vim Editors Pocket Reference
Learn more about this topic from vi and Vim Editors Pocket Reference, 2nd Edition. 

Many Unix, Linux, and Mac OS X geeks enjoy using the powerful, platform-agnostic text editors vi and Vim, but there are far too many commands for anyone to remember. Author Arnold Robbins has chosen the most valuable commands for vi, Vim, and vi's main clones—vile, elvis, and nvi—and packed them into this easy-to-browse pocket reference. You'll find commands for all kinds of editing tasks, including programming, modifying system files, writing and marking up articles, and more.

Learn More Read Now on Safari


Tags:
0 Subscribe


0 Replies