Why Vim?

People ask me why on Earth would I subject myself to such dreadful text editor as vim. With it’s weird mode system, nonstandard keyboard shortcuts and all kinds of strange quirks it is not what you would call a user-friendly piece of software. Most users new to this particular editor hit a brick wall at step one: entering text. When you open vim and try to type, it will do strange things – like beep at you, or display some messages in the status bar. Unless of course you happen to hit a vovel like a or i or o, in which case it will suddenly come alive.

Years ago I have found this little illustration that perfectly describes learning difficulty curves for various common text editors:

Editor Learning Curves

Editor Learning Curves

In my experience this is 100% accurate. Vi and vim are just a bitch to learn to use properly. Unlike most editors you have used in your life, vim is modal. It has a bunch of modes that change the functionality of the keys, shortcuts and behavior. When you want to type something in, you put it in insert mode where it behaves mostly like what you would expect an editor to behave. If you want to move around the file, and issue commands you go into normal mode, and suddenly every single key on your keyboard has at least one or two powerful functions bound to it. This is probably my favorite illustration of just how complex vim is:

Vim Cheat Sheet by ViEMU

Vim Cheat Sheet by ViEMU

You can download full version of this sheet from here. This, by the way, is only a tip of the iceberg. Most keys have additional meanings in specific context. For example i means “enter insert mode” unless it is pressed immediately after another command in which case it usually stands for “internal”. But more on that later.

The point here is that while most editors bind few key commands (copy, paste, skip to the end of line) commands to key combinations (Ctrl+C, Ctrl+P) or control block keys (Home, End, PgUp, etc..) vim binds them to single key strokes, which can be chained in rapid succession. Vim is basically a unix shell for text editing – it gives you hundreds of small commands that can be scripted together to achieve daunting feats in small amounts of time.

Funny part is that the modality and complexity (which is at the same time the editor’s greatest flaw, and greatest strength) is mostly incidental. It is a product of the times when it was developed.

Here is an image that will probably tell you all you need to know about why vim is the way it is. Billy Joy wrote vi (vim’s predecessor) on a dumb terminal like this:

Vim History

Vim History

I shamelessly stole this image from Peteris Krumins’ blog, so full credit for finding this goes to him. But you can read his stuff later, now pay attention. I want you to look at the picture of the keyboard. See anything interesting?

No arrow keys. The designers of the ADM-3A terminal put the arrow keys on HJKL and forced modality onto their users. Billy Joy was using this thing, over a 300 baud connection which meant that every key stroke would take literal seconds to register. Think about that for a second.

Have you ever tried using a very, very crappy ssh connection that made editing files on the server a nightmare? It used to be like that all the time back in the day. Is it any surprise that vi was optimized to have incredibly powerful single stroke commands?

It turns out that the technological limitations of the time pushed Billy Joy into creating something brilliant – one of the most powerful text editing applications ever invented. One that is relevant now as much as it was relevant back in the day. The amount of power it puts at your fingertips is overwhelming. It lets you move around and manipulate text in ways you haven’t even considered before.

Let me give you an example – a simple use case by which you can gauge the value vim brings to the table. Let’s say you are coding something. Suddenly you realize you want to copy the current line and paste it directly below the first. How do you do this? Tell me your process step by step, and let’s count the keystrokes it takes to accomplish this. To be fair, let’s assume the cursor is already on the correct line, but somewhere in the middle of it.

If your first instinct is to take your paw of the keyboard and reach for a mouse, then you are what we in this business call a complete n00b. It’s a novice move. Taking your hand of the keyboard slows you the fuck down. In the time it takes you to locate the mouse cursor, highlight the paragraph I could probably retype the entire line from scratch. No seriously, time yourself one day and check it for yourself. If you are a semi-decent typist you can usually retype a line of code faster than you can mouse-copy it.

Power users and experienced coders will probably do something like this:

  1. Hit Home to skip to the beginning of the line
  2. Hold Shift and hit End to highlight the line
  3. Ctrl+C to copy
  4. Hit End again to de-highlight the line
  5. Hit Enter to insert a new line directly under the first
  6. Ctrl+V to paste

By my count that’s six key strokes, half of which are “chords” (two keys pressed simultaneously) and two motions requiring your right hand leave the home row to hit the Home and End keys on the control block. All in all not bad. Let’s see if a vim user can beat this score.

How do you copy and paste a line in vim?

  1. y y p

That’s it. Three key strokes, off the home row, executed by one hand in a single fluid motion, using no chords. I think it is a clear winner. That’s basically what vim does for you. It makes common operations quick easy and simple.

Ah, but who will remember these cryptic shortcuts? Well, they are not that cryptic. The character y stands for “yank” (a command akin to copying in regular editors). Repeating a command usually applies it to an entire line. So yy copies the current line. The letter p is of course for pasting, and by default vim pastes below the cursor (you could paste above by using upper case P). Not all that cryptic when you realize that most vim commands follow simple mnemonics.

Yan Pritzker apptly explained it like this: vim commands are like a language you can learn:

  • There are verbs: c (change), d (delete), y (yank), p (paste), u (undo)
  • There are nouns: w (word), s (sentence), p (paragraph), b (parenthetical block – something inside parentheses)
  • There are some modifiers: i (inside), a (around), etc..

Eventually you learn to string these into sentences – here are some examples:

  • change word: c w
  • delete around sentence: d a s
  • yank (copy) insides of a paragraph: y i p
  • change text inside next quotation marks c i "

By the way, that last one can be issued from anywhere – it will jump to the first occurrence of a quotation mark, delete everything inside and put you in insert mode so you can type something in.

Some of the “nouns” only work when preceded by a modifier i or a. For example, you cannot say d s to delete a sentence. You must precede the s with one of the modifiers. Other “nouns” like w work without modifiers.

There are other useful commands that don’t follow this particular pattern but are stand alone and still easy to remember. For example J joins two lines together by concatenating the line below to the current. The t command followed by a character, moves the cursor forward ’till it finds that character. You can also open a new line with o.

You can string vim’s one-character commands to perform all kinds of different operations. And if you botch a command, you just hit u to undo the last change. It is an incredible amount of power at your fingertips.

But if that’s not enough, how about this: in Vim you can rebind any key. Any key in any mode – up to the point where the editor is rendered completely unusable. For example, I bound by F1 key to toggle the NerdTree plugin. Originally it opened the help documents in a new buffer, but never actually used it that way. But you are not limited to just single key – you can bind key combos.

Vim even gives you a freebie key you can use for binding your own combos – the leader key or \. For example, I have the following binding in my configuration:

nmap   i

What does this do? It is essentially reverse of J (join) command. It splits the line at the cursor. In most editors you accomplish it just by hitting enter. In vim, you usually have to enter insert mode (i), hit Enter, then hit Esc to go back to normal mode to continue issuing commands. This annoyed me so I reduced it to two keystrokes. I could have reduced it to one if I wanted to. Or I could extend this binding and make it skip to the end of the line upon successful split. Vim can be molded to your specific needs.

Hell, you can make vim behave like a “normal” text editor. Someone actually bundled that particular configuration and nicknamed it Cream. To me that’s kinda pointless though. It’s like buying a chainsaw, but never putting any fuel in. You lose half the power.

Need more convincing? Vim has macros. It lets you “record” keystrokes on the fly bind them to a key and then re-play them. Let me give you an example. Let’s say I give you a comma separated file like this:

jblack1, Jack Black
tgreen1, Tom Green
bwhite7, Bob White
etc..

Let’s say it has 6,000 lines. I want it transformed into this:

  • Jack Black
  • Tom Green
  • Bob White
  • etc..

    How do you do this quickly? Perl? Sed? Awk? All of that will require testing and fucking around. Optimistic estimate is that it will take you at least 10-15 minutes to write the script, and maybe another 5 to make sure it works for all the lines.

    Me? I can do it in less than five minutes in vim? How? By using macros, and carefully choosing my editing commands to that they are generic and play off the common features on all the lines.

    1. Press q a to record keystrokes and bind them to “a”
    2. Hit I to enter insert mode at the start of the line
    3. Type in <li><a href=”http://example.com/~
    4. Hit Esc to go to normal mode
    5. Hit t , to put the cursor on the comma.
      Since you know you are working with a csv, you can expect a comma followed by a space on every line. This will always work, regardless of the length of each username.
    6. Hit s to delete the comma and enter insert mode
    7. Type in “>
    8. Hit Del to remove the extra space to the right
    9. Hit Esc to go back to normal mode
    10. Hit capital A to skip to the end of the line and enter insert mode
    11. Type in: </a></li>
    12. Hit Esc
    13. Hit q to stop recording

    I just taught vim how to do one line. I can now put the cursor on another line and hit:

    @ a

    This will replay the macro, and boom – the line will be turned into a link. Or better yet, I could type this in normal mode:

    :2,$ norm @a

    This basically tells vim “On lines 2 through $ (where $ means end of file) go to normal mode, and run the macro stored under a”. Wham, bam! We have the entire file done. And all I did was simply re-format the first line and then applied that template to the rest of the file.

    Still not impressed? Geez, it’s hard to impress you, isn’t it.

    There are plugins. Thousands of them. As I said – vim can be reconfigured quite easily. It is not as much that it has a plugin architecture and limited API (like Eclipse for example), as it has an scripting language (VimL) that lets you automate, redefine and hack everything – including changing standard behavior. Vim Plugin writers have been known to rip out neat functionality from other editors and transplant it into vim whether it makes sense or not. Plugins can make the editor do all kinds of crazy things:

    1. Fugitive – gives you git integration. For example you can do :Gblame from the editor to get a nice in-editor, two pane blame log.
    2. Syntastic will run your code through the compiler/interpreter in the background like an IDE
    3. SnipMate – gives you TextMate’s code snippets feature

    There are many more – these just happen to be some of my favorites. There is a much bigger list in the forum.

    Still not impressed? How about this: vi is ubiquitous. Vim is a superset of vi – so if you learn to use it well, you will also learn vi by extension. And vi is installed by default on just about any unix derived system out there. Chances are that one day you will have a web server of your own to maintain – maybe for work, maybe for fun, maybe for your startup that will change the landscape of social networking forever. That server will likely run a stripped down version of Unix, Linux or BSD. Why? Well, you want it to succeed, do you? Running windows on your production server is basically like aiming to fail. No, you will be a professional and you will be running unix-like system like big boys and girls do. Windows servers are what pointy haired MBA degree recipients straight out of school want to use – we are hackers. We are better than that.

    Anyways, your unix like server will probably be running headless on some server rack. And you will manage it by ssh-ing to it. And you will likely configure it by editing text files using vi, because that’s what is going to be on the machine. Yes, you could install another editor on there – like Pico for example. But that’s just pathetic. You don’t want to be that guy. Do you know what Pico stands for? It’s an acronym for “Don’t Know How To Use Vi”. Besides, you can’t always rely on having root privileges and ability to install new software. And shared hosting companies will usually not be nice and install Pico for you.

    The point is that if you know vi (you don’t have to be a pro at it, just know how to use it enough not to look like you are having a seizure at the keyboard) you can log into any Unix, Linux, BSD or Mac machine and fucking rock that shit like a pro. Your peers will be like “Woha, this guy knows his stuff!” and women will be totally like “I want to have his babies!”…

    Ok, that last one was a lie. Vi skillz won’t get you anywhere with the ladies. Unless maybe with really awesome and cool geek ladies that can appreciate that sort of thing but that’s besides the point. The point is that vi is the most ubiquitously installed editor out there, and one most people don’t know how to use. If you do, that makes you more efficient than them. Which, is generally a good thing.

    Still not impressed? You are an Emacs user, right? Listen I won’t convert you. Emacs is a whole different animal. I think it was Steve Yegge who said that Emacs is not a text editor. It is a feature full lisp based framework that can be used for text processing or writing text processors – or both at the same time. It is even more mutable and hack friendly than vim, and it’s internal language Elisp is actually more powerful (and more elegant, your stance on lisp parethesisis notwithstanding) than the ugliness that is VimL. If you are using Emacs, keep using it.

    Hell, if you are using Java you should probably keep using Eclipse. Similarly you probably shouldn’t ditch Visual Studio and hack your C# code in vim. Emacs and IDE’s are useful – they have tools that will make your life easier. The IDE’s don’t have vim’s raw text manipulation power, but they make up for it by having great integrated debuggers, GUI building tools and etc. But if you are hacking in Perl, Python, PHP, Ruby or something like that, vim is usually a good choice.

    Is it the best editor in the world? I don’t know. I guess it depends what you are doing. The bottom line is that you should choose a tool that fits the particular problem you are trying to solve. Not all problems are nails. If you try to apply a hammer to a philipsh-head you are probably gonna screw things up somewhere down the line. But vim is a great editor and you should definitely give it a chance. Especially if you have been discouraged by the steep learning curve before.

    This entry was posted in Uncategorized. Bookmark the permalink.



    59 Responses to Why Vim?

    1. When we all started using the GUI, that part of the brain that took imagination to understand concepts of the operating system went away.

      I believe I gained a bit by having to navigate around the linux os within terminal (it made things clearer), we are all taught within school to use Word (which is highly monopolistic don’t you think?)

      I suppose they had to come up with a standard. As it stands, we have keyboards with arrows on them, gui’s with nice, configurable macros guided by buttons.

      As long as the interface isn’t arbitrarily mazelike and unorganized, it remains a higher used medium as an editor. Unfortunately we do not guide our users in how to use a keyboard properly. I still type with only 4 fingers (total) because I’m an idiot.
      Yet I find myself typing fast, it still means I wasn’t properly trained.

      I hope that at some point we will no longer have to use keyboards. And at that point all of it will be fruitless.
      But to get there would require artificial intelligence,
      and at some point maybe even that would require maintenance.

      We’ll see. As it stands we are not using dvorak, and remain dazzled by gui interfaces.
      To an extent, it bothers me. And to a lesser extent, it doesn’t.

      Reply  |  Quote
    2. Luke Maciak UNITED STATES Google Chrome Linux Terminalist says:

      The Word thing – that’s just marketing. The following memes have been hammered into the shared consciousness of the general public until they became self evident truths that people repeat by rote:

      – You can’t run a business without Microsoft Office
      – Macs are better for graphic design

      Both statements are equally silly and false these days, but people still hold on to them. We know better. To wit, the course I teach is run by CS department. Our curriculum specifies that I should allow/encourage students to use Open Office for lab assignments. Some teachers completely transitioned their lab exercises away from Microsoft products.

      I choose to still do some in-class stuff on Word/Excel/PPT because I expect that’s what the students will see at work upon exiting college. Perpetuating monopoly? Maybe.

      Microsoft is dying though. It is struggling to find it’s way in post-pc landscape. Win8 is their desperate attempt to put themselves back on the market, but it looks like a complete disaster that will push a lot of clueless desktop users into the warm embrace of Apple. Even though OSX has a fucked mouse acceleration bug they haven’t bothered to fix in a decade, they have not removed mouse navigation in lieu of tabled model yet.

      Right now they are failing hard at reinforcing the “Office == Business” meme and they are bleeding users. People are leaving in droves. Big corporate behemoths are still buying Office licenses, but small mom-and-pop shops and startups are actually doing just fine using alternate products. Or no products at all – hosting their WYSYWYG stuff in the cloud with Google. This was unthinkable a decade ago. Microsoft is becoming irrelevant one failed venture at seeing it write in agony makes me smile.

      I guess this is all about comfort level.

      – LaTex is more powerful than WYSIWYG
      – Dvorak is allegedly faster than Qwerty
      – vim is better than non-modal editor

      Different tools for different people with different purposes. Not everyone will use the better, more powerful tools – but that’s ok.

      Reply  |  Quote
    3. Adrian NETHERLANDS Opera Windows says:

      Whenever I get a chance to use linux (I fuck around with Arch Linux once in a while), I always love using vim. But outside of the linux eco-system, I’ve never really had any need for it. /r/fossworldproblems

      I write my articles in notepad++ and if I need something with a real layout, I use Google Docs.

      Reply  |  Quote
    4. Luke Maciak UNITED STATES Google Chrome Linux Terminalist says:

      @ Adrian:

      I use vim across 3 platforms: Ubuntu, Windows and OSX. I use the same .vimrc and plugins on all 3 platforms sychronizing them via Git repository. It works quite well for me. :)

      Reply  |  Quote
    5. juliob_m SPAIN Mozilla Firefox Ubuntu Linux says:

      “You can’t run a business without Microsoft Office”. i’m sorry but its true. i work as it manager and i can say that is too dificult change minds about “working with documents”.
      i use privatly mint, but i always have to buy office and windows licenses. its a pity

      Reply  |  Quote
    6. Ron NEW ZEALAND Mozilla Firefox Linux says:

      It almost seems the emacs and vim, that while very different are closer to each over then any other form of editor, almost ironic, giving the history of flaming between the two.

      For your example before thou in emacs C-S-Backspace (Ctrl Shift and backspace) not great but not horrible

      Reply  |  Quote
    7. Alan UNITED STATES Google Chrome Windows says:

      vim totally rocks for academic writing with LaTeX. Emacs has a good environment too, and I started out evaluating both. What killed emacs for me was no apparent way to do soft word-wrapping. I like to write my LaTeX sentences on individual lines so I can reorder them easily. So soft word wrapping is important to me.

      Anyway, it took me a long time to get comfortable, and I’m still learning it, but I love using vim as an editor. I do like other tools for writing serious code, but when it’s LaTeX or simple projects, I go to vim.

      Basically, what you said.

      Reply  |  Quote
    8. Francisco JAPAN Google Chrome Linux says:

      As much as I get what you meant, it took me less than a minute to write an awk one-liner that does just what you did with vim macros ;)

      Just in case someone is wonderign what that would be:

      awk -F”, ” ‘{print ““$2”“}’

      Reply  |  Quote
    9. Francisco JAPAN Google Chrome Linux says:

      As much as I get what you meant, it took me less than a minute to write an awk one-liner that does just what you did with vim macros

      Just in case someone is wonderign what that would be:

      awk -F", " '{print ""$2""}'

      *Please delete my comment above ;)

      Reply  |  Quote
    10. pjl PARAGUAY Mozilla Firefox Linux says:

      jaja i love your post. I started use vim for one year, then i pass to emacs to this days. Like you say emacs is a diferent animal. I like more emacs than vim, but these matters is always going to be a thing of taste. What editor goes more with your personality ?. That is the key.

      Reply  |  Quote
    11. Mcai8sh4 UNITED KINGDOM Safari Mac OS Terminalist says:

      When I first started with *nix, I was kind of forced to use vim (at the time I didn’t know about any other editors), my thought were “this seems a silly way to do things” but I plodded on regardless.

      Then, when I tried a new distro, I found nano (I think), and used that for a while. Shortley after I found vim-tutorial, ran through that… And then it clicked!

      For years now I have been using vim for most of my text based stuff (or gvim on windows). Writing code, making notes, editing config files…..

      Every time I read something about vim, I tend to learn something new… It’s an awesome piece of stuff.

      I also use vim to quickly edit/sort/compile my expenses for work. Export bank statements/phone bills… In to csv, then use Vims magic to quickly sort out the relevant lines, leaving the private stuff out of the way, then reformat everything so it neat and easy to read. A 2 hour job now takes a few minutes. And anyone watching me do it thinks it’s magic!

      Vim might not get you the girls, but it gives you more time to trick seduce them!

      Reply  |  Quote
    12. Tomek POLAND Opera Linux says:

      Some time ago I was looking for an editor to work with DocBook and after some research I’m a happy vim user now (see http://www.kaczanowscy.pl/tomek/2010-09/a-perfect-environment-for-docb ook). It is really a powerful tool, even though I feel I still use only a tiny percent of its features.

      Reply  |  Quote
    13. JoeDreamer UNITED KINGDOM Google Chrome Windows says:

      Try “M-x visual-line-mode”.

      @ Alan:

      Try “M-x visual-line mode”.Alan wrote:

      vim totally rocks for academic writing with LaTeX. Emacs has a good environment too, and I started out evaluating both. What killed emacs for me was no apparent way to do soft word-wrapping. I like to write my LaTeX sentences on individual lines so I can reorder them easily. So soft word wrapping is important to me.

      Anyway, it took me a long time to get comfortable, and I’m still learning it, but I love using vim as an editor. I do like other tools for writing serious code, but when it’s LaTeX or simple projects, I go to vim.

      Basically, what you said.

      Reply  |  Quote
    14. Luke Maciak UNITED STATES Mozilla Firefox Windows Terminalist says:

      @ Ron:

      Oh, yes – they are very close though designed for very different purposes. Emacs was designed for programming on high end machines with high bandwidth local connection. Billy Joy wrote vim to create an editor that was full featured and could be used over a 300 Baud modem. The core purpose was the same – to make an editor to end all editors. Both mostly succeeded. :)

      @ Alan:

      Yeah, it’s kinda funny. After few months, maybe few years of use you can probably claim you know Visual Studio or Eclipse inside out. With Vim – you probably only scratched the surface. :P

      @ Francisco:

      Pssst, that won’t work. It will output:

      Jack Black
      Tom Green
      Bob White

      You are missing the href section. See what I mean about debugging? It took you two minutes to write that, then probably a minute to run it on a 6,000 record file. Then 30 seconds to realize you messed up. Another 2-3 minutes to fix it and run it again. Then that iteration may still have a typo or something.

      The advantage of me using a Vim macro is that I immediately see what I’m doing. Furthermore I can plan my moves “live” so to speak. I can strategically pick the key strokes best for the data and see hot it affects it immediately. :)

      But you are making a good point. Here is the thing – say you created that awk script and you saved it in your home dir as “convert.awk”. Here is another thing vim will let you do:

      1. Open the file
      2. ggvG
      3. :!~/convert.awk %
      4. Bam! The text in the file gets replaced by output of your script.

      @ Mcai8sh4:

      When I was an undergrad, they gave us shell accounts and taught us Pico and Pine. I thought I was a badass when I learned to used them efficiently. Then I discovered vim and how powerful it was so I would scoff at the Pico users. Sadly the vi version on the Solaris box we were using was old… But I had full access to gcc.

      So I compiled the latest and greatest vim and simply installed it in my home dir. I did the same for mutt, screen, and bunch of other tools. Then I taught bunch of other students how to do that… Then they took my shell account away because of “suspicious activity”. :P Fun times!

      @ Tomek:

      Nice. I’m more of a LaTex guy myself, but yeah – vim is well suited to that kind of work.

      Reply  |  Quote
    15. Scott UNITED STATES Mozilla Firefox Linux says:

      A simpler way of splitting lines (the reverse of joining them) is

      r<cr>

      which replaces the character at the cursor with a newline. No need to go to insert mode.

      Even easier for your particular macro example is a search and replace:

      :2,$s#\(.*\)#<li><a href="http://example.com/~\1</a></li>#
      :2,$s/, /">/
      

      This is also probably faster than a macro.

      Vim is installed in both Linux and Windows on my machine. On the latter, I use it to clean up text copied from PowerPoint, which puts characters where newlines belong, and I have a custom key binding to convert those to newlines. What was a several-minute job by hand is reduced to a single key press.

      I also share a dropbox with a guy at my church, and we pass notes through a text file that uses Notepad’s .LOG feature. A mapping in Vim creates log entries formatted exactly like Notepad does.

      My major use for Vim is writing prose. Nothing beats it for editing, especially when you consider the pathetic editing commands that word processors provide: ctrl-c/ctrl-x and ctrl-v. (Yes, I know that Emacs has awesome editing features, too. But, in spite of claims on its web site that it allows users to touch-type commands, those commands are still key chords. That’s not touch-typing in my opinion.) Word processors actually discourage editing with such crippled commands and distract from the process of writing with all kinds of buttons and controls for formatting the text and the page. I only use them after the text is composed and edited and only to format documents. When I surmount LaTeX’s learning curve, maybe I will use that instead. Not unlike what I had to do to learn Vim.

      Reply  |  Quote
    16. vi is a ubiquitous Unix tool. Great for editing config files over a laggy ssh line across half the globe, or disaster hotfixes on the production system. But VIM is an Emacs wannabe based on vi. Featureful, programmable, but in an ugly language wich is based on ex.

      Neal Stephenson once wrote: “If you are a professional writer–i.e., if someone else is getting paid to worry about how your words are formatted and printed–emacs outshines all other editing software in approximately the same way that the noonday sun does the stars. It is not just bigger and brighter; it simply makes everything else vanish.”

      Reply  |  Quote
    17. Scott UNITED STATES Mozilla Firefox Linux says:

      VIM is an Emacs wannabe based on vi

      That’s a stretch, and quoting a thirteen-year-old article to support your point doesn’t strengthen your claim, especially when Vim was only at version 5.5 as of late 1999, the year that article was published.

      Reply  |  Quote
    18. Alex Reinisch UNITED STATES Google Chrome Mac OS says:

      Just another reference: cheat-sheet.
      I really liked the way you laid out your argument. Very strong. I’m working my way through that first part of the vim learning curve now… your words are encouraging.

      Reply  |  Quote
    19. Larry Battle UNITED STATES Opera Windows says:

      You converted me to vim at the”yyp” example.
      Also, Alex Reinisch created an excellent vim cheat sheet.

      Reply  |  Quote
    20. Jason UNITED STATES Google Chrome Mac OS says:

      @ juliob_m:

      You can use OpenOffice instead. It reads and writes Word documents. In addition, it is free.

      Reply  |  Quote
    21. Dan UNITED STATES Mozilla Firefox Linux says:

      Great article! Bonus points for casual use of the f-bomb. :D

      IMHO, what really rocks with vim (or most vi clones) is positional search. Turn a list of filenames into a script? Easy:

      :g/^/s//scp /
      :g/$/s// root@mycomputer:\/tmp/

      Not to say there aren’t easier ways to do this, but it’s still a good example of what makes vi unique.

      Reply  |  Quote
    22. Scott UNITED STATES Mozilla Firefox Linux says:

      @Albertas Agejevas quoted Neal Stephenson:

      Neal Stephenson once wrote: ‘If you are a professional writer–i.e., if someone else is getting paid to worry about how your words are formatted and printed–emacs outshines all other editing software in approximately the same way that the noonday sun does the stars. It is not just bigger and brighter; it simply makes everything else vanish.’

      In a Forbes interview last year, David Ewalt asked:

      [Ewalt] Are you still using Emacs?
      [Stephenson] I use Scrivener.

      Neal Stephenson Talks About Video Games, The Metaverse, And His New Book, REAMDE.

      Enough said, apparently. If you are going to troll, at least make sure you are on solid footing when quoting sources. This one has changed his mind about using Emacs for professional writing, and it dilutes the authority of his prior position. I was able to find this by searching on Google for his name and a selection from your quote. This took me less than two minutes. And I found the link on the Emacs Wiki, of all places! For a troll, this is pathetic.

      In your defense, you are certainly not the only one making this mistake. I found several other websites with recent articles about Emacs that cite Neal Stephenson’s remarks from 1999 extolling the virtues of using it for professional writing.

      None of this is to put Emacs down. It is clearly a truly awesome editor. But like Vim, it is not for everyone. I don’t subscribe to the idea that to love Vim is to hate Emacs, or vice versa.

      You also claimed that Vim is an Emacs wannabe. This is demonstrably false. Emacs tries to be all things to all of its users. That’s why it comes with a mail client, a news reader, a web browser, and numerous other tools, such as a text editor. Vim tries to be good only at editing text. It comes with little else. Those things may be added as extensions, but they are certainly not part of the Vim distribution.

      Reply  |  Quote
    23. Luke Maciak UNITED STATES Mozilla Firefox Windows Terminalist says:

      @ Scott:

      Good point, search and replace could have been faster. I wanted to showcase macros though so I went with that. But yes, it is worth mentioning that vim lets you run regexps on your document quite easily.

      @ Albertas Agejevas:

      Agreed, VimL is quite ugly and inconsistent. Elisp is not perfect either, but it is a lisp dialect which makes it by far more elegant and useful than clunky VimL.

      @ Alex Reinisch:

      Nice one! Bookmarkd!

      @ Larry Battle:

      :D

      @ Jason:

      Nah, he probably can’t. Kinda like in my day job, 90% of the office is inexplicably married to Office. In fact, we have a dozen users are required to have:

      – Office 2000 – for the Microsoft Binder feature which is (ab)used by one of our clients (that feature was cut from later versions of office)
      – Office 2003 – for another clients who uses a custom made .NET library that manipulates Excel file, but does not work in 2007
      – Office 2007 – for yet another client whose excel files always exceed row limit

      The worst part is that we can’t do anything about it – it’s all forced upon us by the clusterfuck setups of the people who pay us monies.

      @ Dan:

      And then you can run it and capture the output in the same buffer with:

      :r! %

      @ Scott:

      To be fair, Stephenson’s change of heart does not really make his previous statements invalid. When he talked about Emacs, Scrivner did not exit yet. Yeah, he found a better tool, but for a while Emacs was his main writing instrument and that still says something about the editor.

      Personally I have nothing against Emacs. It is better at doing certain things, vim is better at doing others. It’s a matter of preference really. As long as you’re not using Word, or some other WYSIWYG contraption you should be fine.

      But yeah – you are right. Vim’s focus is more narrow. It is a unix tool first and foremost – aims to be small and do one thing only. The difference between vim and Emacs is that Emacs can be used as a mail client, while vim is used by mail clients such as Mutt.

      The old joke about Emacs is that it is essentially an Lisp based operating system. :P

      Reply  |  Quote
    24. Hey. Great post.
      Years ago, a linux buf, just played some magic on about 600 html pages and took out the requiredtext in a CSV format. I now understand how he did it. Thanks.
      I just have 1 query. Can we highlight sections in HTML pages (div) or {}. This is what holding me from using it. I am ST2 on Ubuntu now and this feature (also available in notepad++, a better view) is saving lives.
      Think Ezy

      Reply  |  Quote
    25. Luke Maciak UNITED STATES Mozilla Firefox Windows Terminalist says:

      @ Nitin Nanivadekar:

      Can you clarify what you mean? Do you mean syntax highlighting? Yes, vim has that. It depends on the color theme. My looks like this: http://i.imgur.com/hpN9J.jpg

      Do you mean visually selecting/highlighting stuff inside tags? Sure vim has that too.

      Let’s say you have some HTML like this:

      Title

      Here is some text.

      More text.

      Now, put your cursor anywhere on within the div tag. Let’s say your cursor is on the letter c in “class” right now. Now hit:

      v i t

      Everything inside the div will be selected (but not the div tags themselves). Type in v i t y to select and yank/copy it.

      Move the cursor inside one of the p tag and it will select insides of that. You want the div tags to be included in the selection? Type in va t instead.

      Mnemonics: visual inside tag, visual around tag

      Reply  |  Quote
    26. Alex Reinisch UNITED STATES Google Chrome Mac OS says:

      Oh no… I did NOT create that cheat sheet I linked to. I did NOT intend to imply ownership/authorship. Sorry for any confusion.

      Reply  |  Quote
    27. William UNITED STATES Netscape Navigator Mac OS says:

      Why call him “Billy” Joy?

      My biggest disappointment in the iPad is how cumbersome it is to use the standard keyboard with vi. The same issue would apply to emacs, of course.

      Reply  |  Quote
    28. Luke Maciak UNITED STATES Mozilla Firefox Windows Terminalist says:

      @ Alex Reinisch:

      Heh, no worries. Thanks for clearing that up. You could have totally taken credit for it, and none of us would be the wiser. ;)

      @ William:

      I think that’s what he calls himself. Most of interviews I have read with him referred to him that way. Some people prefer the shortened version of their name I guess. I know a James who prefers to be called Jamie and that’s how he signs most of his stuff.

      Reply  |  Quote
    29. William UNITED STATES Netscape Navigator Mac OS says:

      @Like, Re: “Billy”:

      Sorry, I meant that I have always seen him use the name “Bill”, never “Billy”. Not a big deal, but the endearing diminutive sounded condescending.

      Reply  |  Quote
    30. William UNITED STATES Netscape Navigator Mac OS says:

      And speaking of mangled names, autocorrect fixed “Luke” to “Like”. My apologies. :)

      Reply  |  Quote
    31. ontobelli MEXICO Mozilla Firefox Linux says:

      I’m not impressed yet, but nice try. LOL

      The first editor I learned in my life was WordStar.

      My experience with vim have been painful. I have to kill vim so many times because I have no idea how to exit it. Is the less intuitive program I have used in my life. But I want to learn it at least for basic editing configuration files in Linux.

      Have you tried UltraEdit? LOL

      Reply  |  Quote
    32. Luke Maciak UNITED STATES Mozilla Firefox Windows Terminalist says:

      @ ontobelli:

      You exit it by pressing : q in normal mode. : w q to exit and save changes, that or Z Q or : q ! to quit without saving.

      UltraEdit? You mean the commercial $90 per seat package? Nope, have not tried it.

      Reply  |  Quote
    33. ontobelli MEXICO Mozilla Firefox Linux says:

      @ Luke Maciak:

      Thanks. I have learned how to exit in a basic tutorial, some time ago.

      Yes, UltraEdit ($60 fox Linux). It’s nice and powerful but expensive and probably not more powerful than vim and emacs, but I think easier for a beginner. It supports column editing and hex editing. Does vim is capable of that kind of editing?

      Reply  |  Quote
    34. Luke Maciak UNITED STATES Mozilla Firefox Windows Terminalist says:

      @ ontobelli:

      Yes and no. No, vim does not have a native hex mode. You can however view dumps of binary hex files by doing: : % !  xxd

      The end result will look like this: http://i.imgur.com/rzgq5.png

      Note that this is not true hex mode. You are just piping he file through the xxd hex dump utility that ships with vim.

      Reply  |  Quote
    35. Scott UNITED STATES Mozilla Firefox Linux says:

      @ ontobelli:

      For column editing, there is a special visual mode. When you type ctrl-v, you can select a column of text. Then, enter insert mode, make changes, which only show on the first line while editing, and return to normal mode. When you return to normal mode, the changes you made to the first line are propagated to the rest of the lines covered by the original highlight.

      Reply  |  Quote
    36. ontobelli MEXICO Mozilla Firefox Linux says:

      @ Luke Maciak:

      Thanks. Not really the same thing. In this one UE is better.

      But *nix has many free options to hex editing anyway.

      @ Scott:

      Thanks Scott. Very useful that kind of editing sometimes.

      Reply  |  Quote
    37. Colin UNITED STATES Internet Explorer Windows says:

      Perfect timing. I’m giving an introductory training course on Vim in a couple days. I’m by no means an expert, not even close, but I’ve seen too many people at work really bumbling around with it. Would you mind if I stole your keystroke saver example?

      By the way, the tutorial videos here are excellent. I mostly learned Vim by watching them and working along with the video since he uses keycastr: http://www.derekwyatt.org/vim/vim-tutorial-videos/vim-novice-tutorial- videos/

      Reply  |  Quote
    38. Luke Maciak UNITED STATES Google Chrome Linux Terminalist says:

      @ Colin:

      No problem. :) Steal away. Although if you could give me credit somewhere in like a footnote that would be super awesome of you.

      Reply  |  Quote
    39. Colin UNITED STATES Mozilla Firefox Windows says:

      No problem. I’ll include a link in the references.

      Reply  |  Quote
    40. heytrav NEW ZEALAND Google Chrome Mac OS says:

      Great article. Never knew you could do that with q.

      Reply  |  Quote
    41. nemo UNITED KINGDOM Mozilla Firefox Windows says:

      That’s nice, but here’s my favourite editor – Zap – being even more awesome:
      Twitpic link

      That’s four windows onto the same TTF file, all displaying the contents in different modes and all simultaneously editable. One window acting as a console running a script disassembling the same TTF. And one editing text – in this case converting some CSV into HTML using a macro I created like this:

      1. Ctrl-L to start learning
      2. Type <li><a href="http://example.com/~
      3. Shift-Right to skip the word
      4. Delete, Delete to remove the space and comma
      5. Type >
      6. Ctrl-Right to go to the end of the line
      7. Type </a></li>
      8. Down, Ctrl-Left to get to the next line
      9. Ctrl-L to stop learning.
      10. Lean on Ctrl-Shift-L

      Of course, you’d have to be running RISC OS to run Zap, so you may have to make do with some less powerful editor on other platforms. ;-)

      Seriously though, there’s no such thing as the “best” editor – different editors have different strengths, and I use three different ones regularly. And none of them are Vim. :-p

      Reply  |  Quote
    42. Luke Maciak UNITED STATES Google Chrome Linux Terminalist says:

      @ nemo:

      Pretty neat! I have never heard of Zap before, but it seems like it would be a worthy contender in the text editor wars, if it was ever to be ported to other platforms.

      Reply  |  Quote
    43. nemo UNITED KINGDOM Mozilla Firefox Windows says:

      @ Luke Maciak:
      As it happens there’s a Vim port for RISC OS too. You’d feel right at home.

      As for Zap being ported, no chance. It’s hand-written ARM machine code! The screenshot is from an emulator running on Windows though, and it won’t be long before everything is a virtual machine of some description. :-/

      Reply  |  Quote
    44. AkitaOnRails BRAZIL Safari Mac OS says:

      Great article. As a shameless small propaganda, if someone here is interested in trying a full blown Vim that may put your favorite IDE to shame, try my vimfiles set available at http://github.com/akitaonrails/vimfiles. It may be more than most need, but for novices it offers everything configured out in a whole package to install and use.

      Reply  |  Quote
    45. I learned to use vi out of necessity. Being a UNIX system administrator, I find myself on a variety of flavors of UNIX (Solaris, Linux, HP-UX, MacOS). One constant on every version of UNIX is vi (as far as I know). Sometimes, easy-to-use editors like emacs and pico need to be added or are just not available. Once I learned vi, I found myself being a better typist. I could do a lot of magic with simple keystrokes. The most used combo for me is “yyp” since I edit config files on a regular basis and I want to preserve the original settings, just in case.

      This is a great tutorial. Thanks for sharing it with us.

      Reply  |  Quote
    46. Luke Maciak UNITED STATES Google Chrome Linux Terminalist says:

      @ Craig A. Betts:

      I use the NerdCommenter plugin which lets me do the following:

      \ c c – to comment out a line
      y y p x – to copy, paste and remove comment mark

      Reply  |  Quote
    47. Pingback: Random links on Vim « Carno's blog PHP

    48. jdg UNITED STATES Google Chrome Windows says:

      @ Luke Maciak:

      I am just starting to use VIM, and I have a git repository setup, however I am having some difficulties keeping the directories straight so that my vimrc and vimfiles (or .vim) work properly on all three operating systems. Do you have any pointers for this? Thanks a bunch!

      Reply  |  Quote
    49. Luke Maciak UNITED STATES Google Chrome Linux Terminalist says:

      @ jdg:

      I actually do. I outlined my method in this post. I hope that helps.

      TLDR – copy .vimrc into .vim/ and then create a .vimrc symlink in ~. In the post I show how to do it on Windows too.

      Reply  |  Quote
    50. Carp UNITED STATES Mozilla Firefox Windows says:

      Two comments. First, as someone else pointed out, using a substitution command is a lot easier than using a macro in that little example you gave. I understand that you were trying to explain macros, but one command is a lot quicker and easier than going through all the trouble of creating a macro.

      The other thing I’d say is that the learning curve shown for vi is a bit misleading. I agree about the extremely steep initial learning curve, but to show it flatten completely is to discount the complexity of vi. I’ve been using vi since the early or mid-eighties (when we received Berkeley Unix 2.9 for PDPs), and while I’m pretty good at it, every one in a while I still see a new trick. Actually, I think I’d say for regular expression usage alone, that flat line needs to continue up a bit, as most people never really master regular expressions.

      Finally, and it’s perhaps been too long for me to make a real assessment of this, but usage was at least loosely based on ‘ed’. The ‘y’ command was there, as were regular expressions, substitutions, etc. Not as fully functional as in vi, but if you had been using ‘ed’, as I was at the time, ‘vi’ was different, yet recognizable as being related to ‘ed’.

      Reply  |  Quote
    51. Neto ARGENTINA Mozilla Firefox Windows says:

      @ juliob_m:

      Julio, ya que eres Español, te contesto en español. Probablemente, no hay razón por la cual no puedas usar LibreOffice (u OpenOffice).

      La funcionalidad está y es muy buena. Soporta tanto los estandares abiertos odt como los de MS (.doc, docx, etc), a veces mejor, que las diferentes versiones de MS. Es rápido, intuitivo y trabaja bien con archivos muy grandes.

      tl,dr translation: Libre/OpenOffice work just as well, it’s sometimes more compatible unlike different MS Office versions and it’s fast. Probably no reason not to use it.

      Reply  |  Quote
    52. Very useful. Thanks :)
      ———————
      Bardzo ciekawa strona + fajnie widzieć dobry tech-blog pisany przez “swojego” :)
      Pozdrawiam

      Adam

      Reply  |  Quote
    53. Fuzz Leonard UNITED STATES Netscape Navigator Mac OS says:

      Enjoyed the article but it did not take literal seconds to register a single keystroke at 300 baud. Given 8 bit ASCII you can do 18 round trips per second.

      Reply  |  Quote
    54. Giordano BRAZIL Mozilla Firefox Windows says:

      If anyone needs to go out of their way to try to explain why they’re using something as trivial as a text editor — and backing up his explanation with niche, biased examples such as “Suddenly you realize you want to copy the current line and paste it directly below the first. How do you do this?” (and that is very intuitively achievable in Netbeans that I don’t even think is excellent, but I digress) — then this is the very symptom that the software in question, Vim, is not worth the trouble. The sure trouble.

      Reply  |  Quote
    55. Pingback: Quickly Learn emacs and vim | Seita's Place UNITED STATES PHP

    56. Pingback: Vi/Vim | Michael S. Morrow UNITED STATES PHP

    57. Pingback: Vlad Mihalcea's Blog | Why Unix utilities are worth learning UNITED STATES PHP

    58. Pingback: Avalanche of sheep | Your guide to a damn light Arch Linux with i3 and text apps WordPress

    59. Pingback: To Vim or Not to Vim « FlatIron School WordPress

    Leave a Reply

    Your email address will not be published. Required fields are marked *