You are in the labyrinth/archive. Click here for the new exmosis.net.

Why I Like Vi

created 2005-06-17 16:38:00

(Up to: Interfaces )

Vi - or Vim to be more precise - is my editor of choice. Many people think that Vi is a geek's editor (which is right, in a sense) but also that it's a step backwards from the Word-processing software that they know. At first, I was inclined to agree, and was suspicious that my own preference for it was more out of cliquey cultism than anything else. But as I progress with Vi - as I learn how to use more and more of it - it has become clear to me that I now use Vi because I really do like it.

I'd like to get to the bottom (or near to it) of why this is so, though. Vi is most certainly different (and when I refer to a "normal" text editor, I mean a GUIdriven one such a Notepad, et al). The main difference, on loading it up for the first time, is that you _can't just start typing and read it straight back. In Vi, you have to switch to the mode most appropriate to what you want to do - for example:

  • "Normal" mode for moving around, manipulating text.
  • "Insert" mode, if you want to add/edit some text.
  • "Visual" mode if you want to highlight/select text.

I think the power of Vi comes, in part, from this distinction. By flitting between modes, it's as if you're moving between "rooms", and in each room you have a set range of options and functionality available to you. This contrasts to "normal" text editors, in which everything can be accessed from the one mode. I'm not saying that one paradigm is better than the other, but perhaps my brain works better if I can switch between contexts, and forget about a whole bunch of functionality that I don't need at one particular time...

After that, the next main difference I would say Vi has to "normal" editors is the way in which functionality is accessed. A visually-interactive GUI-driven editor depends largely on what you can see - maybe this comes out of the fact that everything is available to you at once, and so visual clues are highly relevant to the function you're about to perform. They serve as state, in other words. So, for example, you highlight some text so that when you come to hit Ctrl-C, you know what it is you're copying. In Vi, because you have a choice of modes, this often isn't necessary. Instead, I can choose where I want my copying to stop (or start), place an invisible marker there and forget about it, and then go find the other end, and just copy everything in between. The difference is subtle, but one that I like. (Of course, I can also just choose how many lines I want to copy, which gives me choice and flexibility as I need it).

Perhaps another reason why I prefer Vi is that it's interface may scale better. There are some very simple rules that, once you get the hang of, make it easy to do a lot of more complex things. For instance, I know that if I enter a number and then choose an operation, that operation will be repeated that many times. For instance, if I want to delete 10 lines, I just hit "10" followed by "DD" (delete line). But I can use the exact same paradigm to, say, repeat the last thing I did ("10" then "."), or to find the 10th next occurence of what I'm searching for ("10" then "n").

Having this consistency makes it easier to perform tasks you wouldn't normally do in a GUI-driven editor, which means you tend to wind up doing them more. This is important - the way you perceive editing changes.

Of course, I can also do most of the above with the other "mark a point and jump to that point" paradigm too. Just as with copying, I can set a marker, then quickly choose to delete everything up to the marker. I think this is one of my favourite things in Vi - that "movement" around a document is so generic, such that you can apply it to whatever function you're doing, not just solely entering text.

Take, for instance, replacing text up to a specific point. In a "normal" editor, you can do some of these easily, albeit with more keys being held down at once - shift-control-right selects up to the end of the next word, ready for you to type over it. Shift-home selects to the beginning of the line, etc. In Vi, these examples correspond to "c" then "w" for the first, and "c" then "0" (zero) for the second. Both put you in the "Insert" mode, whereas if you wanted to just delete the area, you'd hit "d" instead of "c".

This method of choosing what you want to do, and then where you want to apply it is another example of splitting movement from functionality. However, I can take this further simply because I'm more "restricted" in what I can do. For example, I can't bring up a nice, neat box, enter some text and hit "Find" to jump to it. Instead, I have to use the keystroke "/". While this does effectively the same thing as the "find" window, it also counts as just another piece of movement. Hence, in the examples above, I can substitute the "where-to" indicator for a search. Doing "c" then "/hello" (and hitting enter) will clear out all the text between my cursor and the next instance of "hello" in the text, ready for me to write in its place.

Once you get used to jumping about using searches, marking invisible points and so on, Vi becomes an incredibly efficient tool.

Update 2005-07-05: Discovered Text Objects in Vi - woohoo!

Also, is using Vi an example of a mental playground?

Update 2005-08-11: Started reading "Sed & Awk" book. Realise that single-character commands are simply a way of representing a function while bypassing more formal language. Realise that functions and objects are merely concepts and that language/characters/GUIs are different ways of representing both. This ties in, therefore, with how people represent concepts in their mind, and why different people like different interfaces. Different Interfaces For Different Minds.

Down

  • (none)
ckpoevtugba pxcbrighton