Skip to main content

Vim: Gimme More Magic

I spent an hour reading about TextMate to get a feel for what I'm missing since I know it's so popular. I'm sure it's a lovely editor, but I have such an emotional attachment to Vim, Linux, free software, etc. Anyway, I'm sure you're tired of hearing me talk about that ;)

Anyway, I tried out the snippetsEmu plugin. It's a plugin that provides TextMate style snippets. Once you have it installed, you can edit a Python file, type "def<tab>" and it'll start doing interesting things.

I can see the appeal of snippetsEmu for more verbose languages. It knows how to type "public static void main" ;) However, it's hard to get excited about it in Python. Python has such low syntactic overhead that it's faster for me to just type things out, especially considering I'm a touch typist. It'd probably make more sense in Ruby, where you have to type "end" all the time. Nonetheless, I'm happy to have someone tell me how to use snippetsEmu more effectively.

I also tried out xmledit. That one's a keeper. Once you have it installed, you can type "<p><tab>" and it'll automatically add "</p>". Hit ">" again, and it'll even put the two tags on separate lines and position your cursor between them. Very nice! The one trick to remember though, is that when you install xml.vim into your ~/.vim/ftplugin directory, remember to symlink it to html.vim so it works for HTML too.


Arnar Birgisson said…
Hey there,

I'm an avid Vim fan as well, it is like my third arm. However, I fell for TextMate as well and bought a license. I now use both pretty much fifty fifty, depending on what kind of editing I'm doing. I especially benefit from how TextMate handles projects.

As for snippets, yes, it is hard to get excited over them for plain Python. However, I have found them to be very useful in the Python context, for example when doing repetitive stuff like SQLAlchemy tables and mappers, other ORM models, and in general any code that is has to have some specific form to be used by libraries through introspection.

For an example, I have two snippets triggered by "table" and "col" for writing SQLAlchemy table definitions. "table" expands to

xxx = table("xxx",
[cursor here]

where xxx are synced, and "col" expands to

Column("xxx", Integer, nullable=false)

with the cursor going through the parameters in order to change or remove them.

So, for me at least, snippets are very useful in Python, although not for plain vanilla Python but rather for library-dependent code format.

xmledit looks good, thanks for that pointer.
Anonymous said…
I just switched back to Linux from about a year on OS X (with TextMate etc).

I really never used the snippet things, ever. I read about them on multiple occasions, tried some out and just never felt much interest.

I did like the simple "jump to a file in my project with name like X" but I can do that easily (and not just for files but classes, functions, etc) ctags + tselect. I'd say you aren't really missing anything.
bsergean said…
For the snippets stuff, what about iabbrev on vim ?
You don't have the "Tab make me switch to the next xxx" thought, but there is a way to do that in Hacking vim.

Viva vim !

BTW I just discovered c% (in the Office vi plugin blog) and using f to navigate throught long lines, editing CSV with ; as the C, with
cf; and f; to navigate.
jjinux said…
> So, for me at least, snippets are very useful in Python, although not for plain vanilla Python but rather for library-dependent code format.

Awesome comment. Thanks!
jjinux said…
> BTW I just discovered c% (in the Office vi plugin blog) and using f to navigate throught long lines, editing CSV with ; as the C, with
cf; and f; to navigate.

Can you write more? I know about f and I know what CSV is, but I don't understand the rest of what you're saying.

bsergean said…
The message was rather cryptic ... sorry. I was refering to this link tip.

Example #2: smart ranges

Right now I'm listing all my book in a file, to become the input for a toy webapp. The format is CSV. Let's say I have this line:

Isaac Asimov ; Fondation ; Folio_SF

I have another book of Asimov, so I do

* Yp to duplicate the line
* j to go one line below
* f; to go to the first ;
* cf; to replace the book name and go to insert mode, and type the name of my second Asimov book. Instead of using c%, my {motion} is f; -> cf;
bsergean said…
The viemu guy explains how he came to vim, and that's quite fun. I think that with all the mobile platform (eee pc), vim is gonna be handy to type, that's for sure. (just having to hit the delete on my laptop hurt me while typing this, instead of Ctrl-w or Ctrl-h ...)

BTW, do you know vimperator ? It has some quirks (I is the magic touch for escaping all chars (gmail or FB, sites with lots of JS I believe)), but it's working well for me.
jjinux said…
> The message was rather cryptic ... sorry. I was refering to this link tip.

Great comment. Thanks for the link!
jjinux said…
> BTW, do you know vimperator ?

I haven't taken that dive yet ;)

Popular posts from this blog

Drawing Sierpinski's Triangle in Minecraft Using Python

In his keynote at PyCon, Eben Upton, the Executive Director of the Rasberry Pi Foundation, mentioned that not only has Minecraft been ported to the Rasberry Pi, but you can even control it with Python. Since four of my kids are avid Minecraft fans, I figured this might be a good time to teach them to program using Python. So I started yesterday with the goal of programming something cool for Minecraft and then showing it off at the San Francisco Python Meetup in the evening.

The first problem that I faced was that I didn't have a Rasberry Pi. You can't hack Minecraft by just installing the Minecraft client. Speaking of which, I didn't have the Minecraft client installed either ;) My kids always play it on their Nexus 7s. I found an open source Minecraft server called Bukkit that "provides the means to extend the popular Minecraft multiplayer server." Then I found a plugin called RaspberryJuice that implements a subset of the Minecraft Pi modding API for Bukkit s…

Apple: iPad and Emacs

Someone asked my boss's buddy Art Medlar if he was going to buy an iPad. He said, "I figure as soon as it runs Emacs, that will be the sign to buy." I think he was just trying to be funny, but his statement is actually fairly profound.

It's well known that submitting iPhone and iPad applications for sale on Apple's store is a huge pain--even if they're free and open source. Apple is acting as a gatekeeper for what is and isn't allowed on your device. I heard that Apple would never allow a scripting language to be installed on your iPad because it would allow end users to run code that they hadn't verified. (I don't have a reference for this, but if you do, please post it below.) Emacs is mostly written in Emacs Lisp. Per Apple's policy, I don't think it'll ever be possible to run Emacs on the iPad.

Emacs was written by Richard Stallman, and it practically defines the Free Software movement (in a manner of speaking at least). Stal…

JavaScript: Porting from react-css-modules to babel-plugin-react-css-modules (with Less)

I recently found a bug in react-css-modules that prevented me from upgrading react-mobx which prevented us from upgrading to React 16. Then, I found out that react-css-modules is "no longer actively maintained". Hence, whether I wanted to or not, I was kind of forced into moving from react-css-modules to babel-plugin-react-css-modules. Doing the port is mostly straightforward. Once I switched libraries, the rest of the port was basically:
Get ESLint to pass now that react-css-modules is no longer available.Get babel-plugin-react-css-modules working with Less.Get my Karma tests to at least build.Get the Karma tests to pass.Test things thoroughly.Fight off merge conflicts from the rest of engineering every 10 minutes ;) There were a few things that resulted in difficult code changes. That's what the rest of this blog post is about. I don't think you can fix all of these things ahead of time. Just read through them and keep them in mind as you follow the approach above.…