Month of Vim

Recently, after mocking vim users on my company’s internal chat system, one of my colleagues, who I knew to be a fellow emacs user, mentioned that several years ago he’d just decided to try using vim for a while, and had failed to ever switch back. It seemed insane to discard decades of wisdom and muscle memory, but on the other hand, I felt that the quality of my scorn and derision was pretty low since I know only enough vi to get emacs installed.

Also lately I’ve been thinking a great deal about my wasted years of high school and college Spanish, and how I have been unable to escape the feeling that I squandered so much time and study only to find myself unable to communiate with a good number of the people I encounter daily. Learning spanish would not mean discarding english, so sure learning vim ought to be worthwhile even if I just went back to emacs.

I decided to spend one month on the project; long enough that I should not have any excuses for being completely hopeless, but not so long that if using vim was agony I would not suffer too long.

Before ever opening a shell, I ordered a paper copy of Practical Vim, second edition, after a bit of googling turned up several endorsements for it. I am starting this journal a few days after having started the project, but I am very satisfied by the decision to start with a paper book, away from the computer. I am also happy about this particular book, as it avoids the tedious patterns that I encounter in most software books. Drew Neil has a concept about what matters when learning this software, and he goes straight into it with a minimum of fluff.

Although there must be ten thousand different vi/vim cheat sheets on the web, I haplessly landed on this one:

[https://hea-www.harvard.edu/~fine/Tech/vi.html]

and then spent several days trying to find it again after forgetting to bookmark it. I like this one in particular although I am unsure why.

I spent a couple of hours over the first weekend trying some of the examples in the book, which was enjoyable. I then experimented a little, editing a couple of files that I needed to change for work.

My method so far has been to avoid creating a vimrc file. I’ve been through the process of creating a pathologically enormous editor configuration file that must be schlepped from machine to machine, carefully curated and organized and so on. My goal with vim is to adapt to the editor, rather than trying to adapt it to me. The reason for this is that I have not made any conclusions about whether, at the end of this month, I will switch from emacs to vim. Instead, I look at this as a short term assignment to a remote office abroad; I am there to absorb as much of the culture as possible. Perhaps I will stay, probably not.

Other resources include a graph-ruled steno book. The steno book is a liability, because I have to remember to take it with me if I want to use it as a resource. Because there are so many commands to remember, I initially thought I’d use the steno book to record things I felt were juicy, but possibly difficult enough, to remember

One concession I made to the minimal-vimrc policy was to add:

noremap <Up> <NOP>
noremap <Down> <NOP>
noremap <Left> <NOP>
noremap <Right> <NOP>

to try to prevent repeating the mistake I made with emacs, which was to prefer the arrow keys for most movement, especially now that I don’t have to hold a modifier to use the non-arrow movement keys.

I did notice today that unmapping the arrows that way doesn’t stop them working in insert mode, which makes sense, although I wonder whether I should get into the habit of switching modes (maybe using the one-shot-normal-mode thing, ctrl-o or whatever it is) when I find myself arrowing around. Haven’t decided yet.

Week Two

Things which I’ve had trouble with:

  • In emacs I usually edit text in a terminal; prior to switching to the XMonad window manager, I usually left xterms in an 80 column width and I had never gotten around to setting the paragraph fill width to 80 columns. The result of this was that I developed the tic of hitting fill-paragraph compulsively to reflow paragraphs.

  • Having no .vimrc, I had no default textwidth, and because with the tiler, I get xterms having all manner of column widths, I elected to add:

    set textwidth=80

  • I struggle to remember “gqG” or “gqq” to reflow column width after inserting something; I kept accidentally entering “qqg”, which got me into record mode, which I couldn’t figure out how to get out of.

Week Three

At some time during the past week, I felt I achieved a degree of fluency with vim that allows me to do a few things more quickly with vim than with emacs. Also I noticed that I began having some trouble not using vim commands in emacs, so there’s some muscle-memory involved now.

Something that I find myself doing with vim that I have never done with emacs is narrating a sequence of commands to myself as I enter them. This has the effect that performing operations feels more purposeful and less instinctive. Although I am definitely far faster using emacs than vim at the moment, I could actually articulate to another person how to perform a particular transformation on text with vim, whereas with emacs I think I could do it with my hands, but not with words.i

I don’t think this is a failure with emacs the software, but rather with how I learned emacs. I did not learn, for example, the emacs forward-char and backward-char commands, and then learn that they were bound to \<c-f> and \<c-b>. In fact I didn’t learn those commands at all until later, I started by whacking the arrow keys furiously, until at some point I finally discovered word-wise movement in emacs and then became aware that there were character-wise movements and some of them might be bound to keys I was using.

I think my comparatively rapid progress with Vim is due partly to coming at it with an appreciation for understanding the commands as opposed to just being able to make them happen.

  • using visual modes often

Initially I avoided using visual mode, not for any ideological reasons but simply because I thought it’d be good to be aware of a normal-mode approach for dealing with common kinds of challenges. I found a few cases where I needed to do actions on several lines, so macros became my hammer. In some cases macros felt clumsy; googling turned up suggestions for using Column Visual mode. During the third week I wound up returning to solution many times.

A source of confusion when using Column Visual is that once I’ve hit Shift-i, Shift-a etc, I was nervous that I’d aborted what I’d started; hitting Esc didn’t seem to change anything, but hitting Esc twice of course does. I need to understand the significance of that detail.

  • Not positioning first then mode-switching

I often find myself forgetting about normal mode commands like A, and I start scooting myself toward the end of the line with first arrow keys and then word motions and then ‘$’, just so I can then hit A to append.

  • Using ctrl-o often

I like being in normal mode as much as possible, since if nothing else it means that I’m frequently concluding insert sessions so that they can be undone in manageable chunks. Ctrl-o makes these transitions seem cheaper.

  • Favoring the shell for bulk transformations

In emacs, I never learned to do the equivalent of vim’s shell filtering. Instead, I tended to either use features from modes or to write elisp that would do transformations that were unwieldy with query-replace-regexp. My first thought with vim’s filtering was that it seemed barbaric, until I got the hang of the visual modes and realized that I could use the years of skill that I have for performing transformations on text with shell commands, but over limited regions and without having to exit the editor.

Week Four

The experiment is drawing to a close. Here are my observations

  • Four weeks was plenty of time for an experienced emacs user to achieve luency in vim. Obviously there’s a lot I haven’t tried yet, but I can now do just about everything with vim that I would do with emacs albeit in some different ways.

  • Because a great deal of bulk manipulation in vim can be done from column-visual mode, I would definitely spend more time working on mastering emacs rectangular selection mode. I was never able to remember how to use it with emacs, which is a shame because using it in vim makes certain kinds of actions very convenient.

  • I do miss emacs server/client, but its not necessarily a deal breaker. There are of course ways to so similar things with vim, but I haven’t invested much time in studying them yet because there are also a few irritations about emacsclient as well- the proliferation of buffers, etc.

  • Automatic resizing of panes in emacs was something I took for granted, but I can get it in vim with:

    autocmd VimResized * wincmd =

  • Getting over the C-w C-o habit for switching panes was a pain in the ass.

  • Using vim on a remote machine is much less painful that using emacs on another machine. My .emacs.d is not massive but I am definitely reliant on it. With vim and my minimal configuration I almost don’t notice the change.

  • I need to find a better pattern than entering “:set paste” all the time when pasting. I know there are slicker alternatives.

  • Typing :bnext is kind of annoying, need to investigate alternatives.

  • There are a few things I miss about magit a lot, such as the way it wraps “git add –patch”.

  • A constant source of frustration when editing Python in emacs was that I was that I never tended to think of lines being aligned to tab stops, but rather that there were a certain number of clicks over that I wanted to tab key to make the line, and if it guessed wrong I’d be annoyed. Initially I wanted to avoid getting hooked on autoindentation all over again in vim, so I started just thinking about indentation in terms of numeric numbers of tabs. This was a revelation and I now feel happy that I don’t care about auto-indentation even though its available.

  • I’ve still had emacsclient with org-mode running the whole time, but to be honest I’ve never cared for any of the org-mode features beyond the folding, which is basically just outline mode. I’ve discovered vimwiki and and am going to experiment with it a little.

  • I now fear that switching back to emacs would require a few weeks to stop typing vim commands all of the damned time, so in a very real sense I laid and sprang my own trap with this experiment. I’m not sure I want to switch back now, not because I’m so charmed by vim, but because I like it just enough that the bother of switching back doesn’t seem worth it.

I do think that if I wind up switching back to emacs, I’d be likely to consider evil mode, probably not spacemacs as I worry that it suffers from the does-too-much problem that confounded me about many of the modes. Also I think if I do switch back to emacs, I’d be likely to approach many kinds of editing problems in a different way. So in much the same way that learning spanish might have a positive influence on how I speak English, I think that learning vim more than superficially has made me a better editor of text, regardless of whether I am using vim or emacs.

For that reason, I think I’ll continue with using it, as I think perhaps a year of use will be more revelatory of shortcomings. Perhaps this time next year, I’ll be able to declare a winner.