This feed contains pages in the "vim" category.

This spring I'm taking a class that does all its programming assignments in MIT Scheme. The last time I had to write Scheme for class, we used PLT Scheme, and thus the DrScheme editor. This time, with that option out, I've decided to do the assignments in Emacs. It is, after all, an editor built out of lisp.

I've used vim for the last five years or so. Some people ask me why this is so—I do go to MIT after all, where Emacs was originally written. The answer to that is simply that Debian got to me first, and at the time at least, the people I knew there used vim. I've heard Emacs is good, but up until this point every time I've tried it I've thrown it down in frustration and then couldn't figure out how to exit the damn thing. This time I was more determined, and made it through the initial hump of being completely useless at the editor.

Here are a few of my observations so far, after mucking around for a couple days over a period of about two weeks:

  • The movement commands seem much more awkward to me. Since I'm using the Colemak keyboard layout, I have backspace bound to Caps-Lock, and it is not available to be a Control key. It may be that I just need some more time to get used to emacs not being modal.

  • It's awkward to switch between split windows using C-x o when I have 4-6 open at a time. I'd like to be able to jump between specific ones directly.

  • C-x 3 will always split the window containing the current buffer evenly in two, which makes it difficult to, for example, create three equally sized vertical windows, side-by-side. Vim defaults to creating evenly sized windows even when you invoke a split twice in a row.

  • The paradigm of being able to have e.g. a scheme buffer or a shell as one of my split windows is nice, though I haven't yet gotten used to having to use emacs special bindings to interact with those buffers rather than what I'd use if I'd just invoked the command from a terminal.

  • I noticed that emacs automatically detects the VCS in my directory. It seems incredibly bizarre to me to interact with my VCS from my editor. Do people actually do this?

  • Emacs's use of the tab character to perform code indentation is interesting. It does solve the problem of code being auto-indented when you don't want it to, which sometimes happens to me in vim, but I wonder if it actually ends up saving keystrokes in the end, since I think not auto-indenting is the exception rather than the rule for me.

  • There seem to be two different methods for completion: "dynamic abbrev" expansion, which I believe is analagous to what I'm used to in vim, and M-TAB (what a horrible keybinding, as most window managers will grab this for window-switching), which seems to be some sort of language-specific completion. I haven't yet seen how this can be harnessed since the symbolic completion seems to be irrelevant for scheme.

  • Emacs's syntax highlighting gets at least one thing right about scheme that vim doesn't: extended comments between #| |# patterns.

  • Bookmarks seem waaay more verbose/awkward than vim's marks. C-x r m NAME huh? I like being able to have a very short pattern to mark and jump back to points in a file, like vim's m/` syntax for marks. Maybe I'll need to bind the bookmark functions to something else.

I'm pretty sure at this point that I'm still trying to bend emacs into being vim with different keybindings instead of figuring out how emacs wants to be used. It's also difficult to compare and contrast between the two editors in that my .vimrc contains years of tweaks and customizations whereas my .emacs started out as a clean slate.

There are two things I'm doing to try to mentally separate emacs from vim, to avoid my fingers' muscle memory from becoming confused:

  1. I'm always using emacs in an X window with dark-on-light text, whereas I always use vim in a terminal with light-on-dark text.
  2. I'm only writing scheme in emacs. No other languages so far.

I'm planning to keep working on these programming assignments in emacs, despite it being annoying slower than I would be in vim. Tips and pointers for improving my experience are welcome.

Posted Mon 15 Feb 2010 04:47:09 PM UTC Tags: tags/vim

Recently I found myself wanting to do something a bit weird in a Vim syntax file: run an external command, extract some text from it, and define syntax keywords based on that extracted text.

I'd never written anything more than basic config-file Vim script before, so it turned out that I was in for an adventure in frustrating esotericities of the language. Can I have a vim-like editor with a real extension language yet?

One of these frustrations is that in many constructs of the language, arguments are not automatically evaluated before being interpreted by the surrounding syntax. I assume that this has something to do with functions and other miscellaneous statements (like 'syntax') not being treated the same way.

For example, if I want to highlight a particular word in a syntax file, I use the following:

syntax keyword word1 word2 word3

The words following 'keyword' are taken literally. So if I have a variable named 'word1', it will match on the literal 'word1' instead of the contents of the variable. And I can't dump a list variable at the end of 'syntax keyword' and have it do what I mean either.

The solution is to construct a string containing the statement you want, and then manually evaluate that:

let s:syntax = 'syn keyword ' . s:group . ' ' . join(s:list)
exec s:syntax

Where 's:group' is a script-local variable that contains what syntax group I want these keywords to belong to, and 's:list' is a list of the keywords. Why 'syntax keyword' doesn't just take strings normally and evaluate variables if they're given, I do not know. Figuring out the right way to present arguments is very confusing.

Thanks to James Vega on #vim for pointing out the way to work around this to me. I never would have figured it out myself.

Posted Tue 18 Aug 2009 10:22:41 AM UTC Tags: tags/vim