Linux.com has an article about five scripts that make life easy in Vim (for the author at least.) I skimmed it very rapidly to see what the author used, but none seemed too useful to me. This is why I decided to write my own top 5 list of vim scripts.
- BufExplorer1: For the longest time, I worked with Vim by editing one file, saving and exiting, editing another file, saving and exiting and so on. Working with Emacs, I learned to stay in the editor for extended periods of time and opening a lot of files. When I came back to Vim, I needed something to make it easy to edit a large number of files in one session. :ls and :b were passable, but I disliked the two-step operation to switch from one buffer to another. (Note: it was only after I installed BufExplorer that I learned you can Tab-complete buffer names.) The folks from #vim quickly pointed me to BufExplorer, and it’s excellent! You use \be (or in my case, ,be) to display the list of opened buffers in your current window (the list is the same as the output of :ls.) You go over the buffer you want to visit and press Enter and you’re there. It’s quick and easy. I’m so used to it, sometimes I write ,be in irssi.
Some people use minibufexpl, I tried it, but it didn’t seem to play too well along with Project, so I uninstalled it
- Project2: One thing I always liked about IDEs and from the Textmate screencasts was the file list on the left of the screen. You can have that with Vim just by opening a directory, but you can sometimes lose the list and it’s annoying to bring it back. Listing the content of a folder also showed files you didn’t care about. Project.vim is a script that displays only the files you want in a vertical split window that always sticks around (even when you use C-w o.) You start a new project with the :Project foo command. Once that’s done, \C will ask you a few questions (name of the project, absolute path of the project, file filters) and the files and directories will be loaded in that buffer. You write it (:w) and next time you open vim, you do :Project foo and the file list comes back. I found this script to be extremely helpful in projects with a large number of files and directories.
- NERD_Comment3: I write code, and often I want to comment/uncomment large portions of code. I could do it manually, but it’s usually slow, especially in languages such as Python where the comment character comments only until the end of line. NERD_Comment gives you a handful of commands to comment and uncomment code with a simple command. The most basic way to use it, select code in visual mode, press \c<space> and the section will be commented. Select the same section again (use gv) and do the same command, and the code will be uncommented. This is not a big time saver, but it’s quite useful.
- Align4: Align is a plugin to align code according to a list of characters. Suppose you have the following code:
firstname = 'Vincent' lastname = 'Foley' age = 23 height = 170 weight = 180 blog_url = 'http://gnuvince.net' favorite_drink = 'beer'Personally, I don’t like code that’s unaligned like that, I find it hard to read (Damian Conway, the author of Perl Best Practices agrees with me on that point.) The solution is to align the equal signs, but that’s kind of a drag to do manually. The Align script automates this process; the command :Align = will align the visual selection on the = character. You can use the :AlignCtrl command (which has a lot of options) to set how many spaces to pad with, left align or right align, etc.
firstname = 'Vincent' lastname = 'Foley' age = 23 height = 170 weight = 180 blog_url = 'http://gnuvince.net' favorite_drink = 'beer'Small problem with Align however, in UTF-8, it does not deal well with accented characters. I contacted the author about this problem, but I haven’t seen an update so far.
- taglist5: When you are brought into a large project, it’s sometimes hard to learn quickly where things are defined and whatnot. A good way to help is to use taglist (given that ctags supports the language you’re using) which will list classes, methods, functions, variables and other elements of your language and make them easy to access. This makes it easy to jump from one usage of a function to its definition.
1: http://www.vim.org/scripts/script.php?script_id=42
2: http://www.vim.org/scripts/script.php?script_id=69
3: http://www.vim.org/scripts/script.php?script_id=1218
4: http://www.vim.org/scripts/script.php?script_id=294
5: http://www.vim.org/scripts/script.php?script_id=273
June 10, 2007 at 7:48 am
Dbext.vim – ditch those crappy database tools!
http://www.vim.org/scripts/script.php?script_id=356
June 10, 2007 at 7:50 am
If you never use the horizontal and vertical split versions of BufExplorer (by default, \bs and \bv), I would recommend changing the mapping from \be to just \b and removing the other two mappings. After you’ve tried it for a while, you won’t want to go back. :)
June 11, 2007 at 8:05 am
You can comment more than one line at a time in Python. Simply surround the code with triple quotes: “”"
This works because it makes that section of code a multiline string — but without assigning the string to anything the interpreter will just disregard it.