Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
March 24, 2011 01:42 am GMT

Vim Essential Plugin: Surround


Surround.vim, by Tim Pope, is easily one of the most useful plugins available. As the name suggests, it allows you to surround, update, and delete wrapping characters and tags with ease!


Usage

Let’s say you have the string “Hello World.” If we want to wrap the word, “World,” within an <em> tag, we can type: viws<em>. This stands for “move into visual mode, select the inner word, and then surround it with an <em> tag.”

Hello <em>World</em>

But let’s say that we later change our mind, and wish to change the wrapping <em> to a <strong> tag instead. With the surround plugin, that’s a cinch: cst<strong>. Again, this means: “Change the surround tag to an <strong>.”

Hello <strong>World</strong>

But, ya know, we can never make up our mind. A day later, we decide to remove the wrapping element all together. Rather than using the clumsy mouse to highlight and delete the tags, let’s type three characters and be done with it: dst, or delete surrounding tag.

Hello World

One More Example

Next, let’s imagine that we have a word that needs to be wrapped in an anchor tag:

Link

Well that’s an easy one: viws<a href="https://url.com">. Switch to visual mode, select the inner word, and surround it with an anchor tag, which links to url.com.

<a href="https://url.com">Link</a>

Be sure to review the video for more examples. I guarantee that you’ll find this plugin to be one of the most useful extensions available for Vim.


Original Link: http://feedproxy.google.com/~r/nettuts/~3/jufmNvuMATY/

Share this article:    Share on Facebook
View Full Article

TutsPlus - Code

Tuts+ is a site aimed at web developers and designers offering tutorials and articles on technologies, skills and techniques to improve how you design and build websites.

More About this Source Visit TutsPlus - Code