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

Ubuntu 20.04 on a 2015 15" MacBook Pro

I decided to give Ubuntu 20.04 a try on my 2015 15" MacBook Pro. I didn't actually install it; I just live booted from a USB thumb drive which was enough to try out everything I wanted. In summary, it's not perfect, and issues with my camera would prevent me from switching, but given the right hardware, I think it's a really viable option. The first thing I wanted to try was what would happen if I plugged in a non-HiDPI screen given that my laptop has a HiDPI screen. Without sub-pixel scaling, whatever scale rate I picked for one screen would apply to the other. However, once I turned on sub-pixel scaling, I was able to pick different scale rates for the internal and external displays. That looked ok. I tried plugging in and unplugging multiple times, and it didn't crash. I doubt it'd work with my Thunderbolt display at work, but it worked fine for my HDMI displays at home. I even plugged it into my TV, and it stuck to the 100% scaling I picked for the othe

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 B

Creating Windows 10 Boot Media for a Lenovo Thinkpad T410 Using Only a Mac and a Linux Machine

TL;DR: Giovanni and I struggled trying to get Windows 10 installed on the Lenovo Thinkpad T410. We struggled a lot trying to create the installation media because we only had a Mac and a Linux machine to work with. Everytime we tried to boot the USB thumb drive, it just showed us a blinking cursor. At the end, we finally realized that Windows 10 wasn't supported on this laptop :-/ I've heard that it took Thomas Edison 100 tries to figure out the right material to use as a lightbulb filament. Well, I'm no Thomas Edison, but I thought it might be noteworthy to document our attempts at getting it to boot off a USB thumb drive: Download the ISO. Attempt 1: Use Etcher. Etcher says it doesn't work for Windows. Attempt 2: Use Boot Camp Assistant. It doesn't have that feature anymore. Attempt 3: Use Disk Utility on a Mac. Erase a USB thumb drive: Format: ExFAT Scheme: GUID Partition Map Mount the ISO. Copy everything from