Home | Hardware | Internet News |Web Hosting |IT Management |Network Storage
LinuxPlanet
Search 
  Power Search | Tips 

 Front Door
 Discussion
 LinuxEngine
 Opinions
 Reports
 Reviews
 Tutorials
 News
 Technology Jobs

 Browse by subject.
Free Newsletter

Linux Planet
Linux Today
More Free Newsletters

Be a Commerce Partner


















internet.com
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

Print this article
Email this article

   LinuxPlanet / Tips







Speed-Typing in Vim With Maps and Abbreviations
Better Than a Clipboard

Juliet Kemp
Monday, June 29, 2009 11:21:55 AM

Juliet Kemp
Vim is still one of the most powerful text editors out there. One of its more useful features is that it allows you to set up your own abbreviations and mappings. These can speed up the typing of stock phrases or do far more complicated things. Enter these in command mode to try them out, or add them to your ~/.vimrc (without the initial colon) if you want them to stay.

Abbreviations (use iab for abbreviations that work only in insert mode or ab for abbreviations that work in any mode) and mappings (use imap for mappings that work in insert mode, or map for mappings that work in multiple modes) are very similar. Broadly speaking, if you're doing something you'd normally use the command-line mode for, use a mapping. If you want a set of characters to expand into a longer string while you're typing, use an abbreviation.

  • The basic 'shorten a stock phrase' type abbreviation:
    :iab YDATE =strftime("%a %b %d %T %Y")
    If you type YDATE, this will output a string like 'Mon May 04 11:01:58 2009'. (You can also use abbreviations to fix common typos, e.g.,
    :iab teh the
    )
  • Reformat the current paragraph according to the current textwidth by hitting Ctrl+L:
    :imap <C-L> gqap
    :map <C-L> gqap
  • Underline the current line with ,u or double-underline it with ,U (this is useful for text note files):
    :imap ,u <ESC>yypv$r-o
    :imap ,U <ESC>yypv$r=o
  • Take out unwanted newlines: Turns every paragraph into a single line:
    :map ,L :%s/(.)n(w)/1 2/<CR>
    This is helpful when you're editing config files that need not have line breaks (e.g. ~/.ssh/authorized_keys2), but you have your textwidth set for normal reading of textfiles.

To list all the mappings that have been set, use :map.

Article courtesy of Serverwatch; Follow ServerWatch on Twitter





Linux is a trademark of Linus Torvalds.


internet.com home | search | help! | about us

Jupiter Online Media

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Web Hosting | Newsletters | Tech Jobs | Shopping | E-mail Offers