Use Vim Surround Plugin inside Sublime Text 2

This is a very quick trick that I think you may find useful.

Did you ever need to add quotes around a word? Here’s an example: I’m trying to convert a file to JSON and I need to surround the first word with quotes (like the following):

[cc]
{
channel : {
“title” : “RSS Sample”,
description : “A sample RSS Feed”,
link : “http://www.somewebsite.com”,
copyright : “Copyright 2013”,
lastBuildDate : “Tue, 19 Feb 2013”,
pubDate : “Tue, 19 Feb 2013”,
items : [
{
title : “An Item’s Title”,
description : “An item’s description”,
link : “http://somewebsite/sample”,
pubDate : “Tue, 19 Feb 2013”
}
]
}
};
[/cc]

See how title has quotes around it? “title”
Well, I need to go to each line and add a quote before and after. Wouldn’t it be great if you could just quickly surround words with quotes (or parentheses or curly braces… or anything you want?) Well, in the world of VIM, that’s why the Surround plugin was created.

Jeffrey Way shows you how to install and use it if you are using the oldie but greatie (yes I said greatie) editor, VIM:

Wouldn’t it be great if you could use this cool feature with Sublime Text 2? You can. Here’s how:

You need to add two packages. (click here if you don’t know how to install the package installer)

  1. Add the Vim-Surround package
  2. Add the Vintage Sublime Surround package

note: you need them both for this to work

Now you need to make sure you have Vintage mode on in Sublime Text 2 (here’s how)

Now you’re ready to make this work. Let’s do this!

Move your cursor so that it in or on a letter you want to surround with quotes. (make sure you are in command mode of vintage)
Type v i w s

On the bottom of ST2 you’ll see this:

Sublime Text 2 Surround with Quotes opiton

You’ll see I filled the box with a Quotation. You do the same and press enter/return

And that’s it. It may seem like a lot of work for something so small. But trust me. This is something you will grow to love.

Leave a Reply

Your email address will not be published. Required fields are marked *