AddThis Social Bookmark Button

Print

What Is Vim (It's Easier than You Think)

by Matthew Russell
07/11/2006

Editor's note: If you've had a less-than-agreeable experience with Vim in the past and are willing to give it another shot, please ponder these points as you work through this article: 1) there's generally a learning curve involved with any powerful tool, 2) Vim is much more than just your run-of-the-mill text editor, and 3) the effort required to become a proficient Vimmer isn't as much as you'd think: it's comparable to that of learning to touch type.

Vim (Vi IMproved)
Vim is a modal text editor designed expressly for efficient text editing. Vim behaves much like the Unix text editor Vi but with many improvements, including graphical menus and mouse support, syntax coloring, undo/redo support, tabbed views, spell checking, and more. Vim is commonly known as a programmer's text editor because of its powerful features that are convenient for editing source code, but is suitable for any task that involves editing text. Vim is open source and highly portable, making it especially appealing to those who frequently work amongst multiple platforms.

In This Article:

  1. Download and Install
  2. Normal Mode Isn't so Normal (at First)
  3. More Keystrokes: Cut/Copy/Paste and Search
  4. The Vim Tutor
  5. Customizing Keystrokes in Vim

This article gets you up and running with Vim. Read on get the latest version installed, run though a quick overview of how its modal behavior can increase your efficiency, and then delve into some of the more advanced features that you can use to customize your Vim experience.

Download and Install

Vim.org is the undisputed source for all matters Vim. It houses a massive collection of incredibly useful Vim tips, scripts, and documentation, among other things. An interesting anomaly, however, is that you won't find the precompiled Vim 7 binaries for Mac there. To get those, you'll want to go to macvim.org. Go there, and look toward the bottom of the page to find precompiled binaries of Vim 7. Download the archive corresponding to the version of your OS, and unzip it. Inside, you'll find four files: gvim (a shell script), Vim.app (the GUI-enabled Vim application), gvim.app (the helper application that you'll want to use to launch Vim), and the standard README document.

Follow along with this much-expanded version of the README document to get all set up.

  • Drag Vim.app and gvim.app into your Applications folder.
  • Paste the following into Terminal to put the standard startup files in place:
    • cd /Applications/Vim.app/Contents/Resources/vim/runtime; cp vimrc_example.vim ~/.vimrc; cp gvimrc_example.vim ~/.gvimrc

    • All that line does is copy the vimrc_example.vim and gvimrc_example.vim files that are located inside the Vim.app's application bundle into your home directory and renames them to .vimrc and .gvimrc, respectively. In the latter part of this article, you'll modify these files to customize your Vim experience.

  • Copy the gvim shell script into /usr/local/bin/ so that you can invoke gvim from the Terminal.
    • Type open /usr/local/bin/ in Terminal to open that location as a folder window, and drag the script over. You'll be prompted for your password since it's a system location.

    • Next, type which gvim in Terminal to make sure that /usr/local/bin/gvim is the first instance of gvim in your $PATH. If it's not, you'll need to move the instance of gvim so that it appears first, or explicitly modify your $PATH by prepending this instance of gvim to show up first. Adding export PATH="/usr/local/bin/gvim":$PATH to your ~/.bashrc file should do the trick. Remember to source the change you just made by typing source ~/.bashrc, and then type gvim to launch Vim 7. Unlike versions of Vim you may have encountered in a terminal somewhere else, you can simply use the application's File menu or press Command+Q to quit.

  • Make Terminal-based Vim accessible.
    • Although you'll likely spend most of your time in the GUI-enabled version of Vim, you may find times when you need to run it in Terminal; an SSH session is one such occasion that comes to mind. Assuming the gvim shell script is in place in /usr/local/bin, all you need to do is symbolically link to it. In Terminal, typing cd /usr/local/bin; sudo ln -s gvim vim (you'll be prompted for a password) will get the job done.
      • The shell script gvim contains logic that launches either a GUI version of Vim or a Terminal-based version of Vim depending whether you typed gvim or vim to invoke it.

    • Once you're done, type which vim to make sure that /usr/local/bin/vim appears.

Brief aside: It's worth noting that Vim.app and gvim.app do not have the intuitive meanings that "vim" and "gvim" normally have. Traditionally, "vim" refers to the terminal-based version of Vim, while "gvim" normally refers to the version of Vim that runs as a GUI application with menus, mouse support, etc. The current situation for Mac users is that Vim.app is the single application that drives both the GUI-enabled version as well as the Terminal-based version of Vim. The disconnect, however, is that Vim.app is only capable of providing a single document window per application instance (at least for now). Until this issue is resolved, the gvim.app helper application works around the problem by launching separate instances of Vim.app behind the scenes for you. All that really means in the end is that if you want to invoke Vim from outside a Terminal setting (like from your dock), do it with gvim.app, not with Vim.app. Otherwise, you're stuck with a single document window. If you didn't understand a word of that, then just forget about it all except the previous sentence.

Pages: 1, 2, 3

Next Pagearrow