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

ERNOS: Erlang Networked Operating System

I've been reading Dreaming in Code lately, and I really like it. If you're not a dreamer, you may safely skip the rest of this post ;) In Chapter 10, "Engineers and Artists", Alan Kay, John Backus, and Jaron Lanier really got me thinking. I've also been thinking a lot about Minix 3 , Erlang , and the original Lisp machine . The ideas are beginning to synthesize into something cohesive--more than just the sum of their parts. Now, I'm sure that many of these ideas have already been envisioned within , LLVM , Microsoft's Singularity project, or in some other place that I haven't managed to discover or fully read, but I'm going to blog them anyway. Rather than wax philosophical, let me just dump out some ideas: Start with Minix 3. It's a new microkernel, and it's meant for real use, unlike the original Minix. "This new OS is extremely small, with the part that runs in kernel mode under 4000 lines of executable code.&quo

Haskell or Erlang?

I've coded in both Erlang and Haskell. Erlang is practical, efficient, and useful. It's got a wonderful niche in the distributed world, and it has some real success stories such as CouchDB and Haskell is elegant and beautiful. It's been successful in various programming language competitions. I have some experience in both, but I'm thinking it's time to really commit to learning one of them on a professional level. They both have good books out now, and it's probably time I read one of those books cover to cover. My question is which? Back in 2000, Perl had established a real niche for systems administration, CGI, and text processing. The syntax wasn't exactly beautiful (unless you're into that sort of thing), but it was popular and mature. Python hadn't really become popular, nor did it really have a strong niche (at least as far as I could see). I went with Python because of its elegance, but since then, I've coded both p