This is a read-only archive. Find the latest Linux articles, documentation, and answers at the new Linux.com!

Linux.com

Feature

Vim's newest features

By Michael M. Murphree on August 30, 2005 (8:00:00 AM)

Share    Print    Comments   

Vim, or "vi improved," is an open source text editor for multiple platforms. This article gives an overview of vim's latest improvements over vi.

You can find this descendant of Vi on your Linux system by typing alias vi and pressing Enter. You'll probably get alias vi='vim'. For a comprehensive look at the differences between vi and vim, you can enter :help differences at the vim command line.

New features include multiple windows, syntax highlighting, multiple levels of undo, and color themes. All of these improvements are made possible by the use of vim plugins.

Plugins are nothing more than scripts that are written for vim. When executed, vim checks /etc/vimrc or ~/.vimrc (if it exists) to get a list of directories that contain plugins. Each .vim file in those directories is then "sourced" -- read in as a list of instructions to vim. These instructions may be carried out automatically, as in the case of syntax highlighting plugins, or may provide you with additional capabilities that you can take advantage of with a pre-defined key combination, for performing a spell-check, for instance. You can also enter :source <path>/<plugin> to manually source a plugin for testing or temporary use.

The ftplugin directory (usually under /usr/share/vim/<version>) contains plugins that are sourced when particular types of file are opened. They contain key mappings and syntax highlighting rules for HTML, Java, C, and other programming languages. For more information about them, type at the vim command line :help filetype.

Some plugins are installed with your Linux distribution; some you can add through your package manager. Check the /usr/share/vim-scripts/plugin directory if it exists on your system. The best source for additional plugins is vim online.

Once you have downloaded a new plugin, there are several ways to make it available to vim.

  • You can copy the plugin to your ~/.vim/plugin directory, which ensures that it will not interfere with other users on your system. The problem with some plugins is that they may use the same keystrokes as those used by others. If this is an issue, you can manually edit the plugin to change the keystrokes. Look for something like <Leader>te mapped to a function. Normally <Leader> refers to the backstroke (\) key, so a mapping of <Leader>te means that you can use \te in command mode to call a function of the plugin.
  • You can copy the plugin to the/etc/vim/plugin directory, or any directory that is sourced in either /etc/vimrc or ~/.vim/vimrc. If you are using a package manager, such as APT or yum, then plugins that are copied to this directory are updated along with the packages that provide them.
  • You can manually source the plugin with the :source <path/plugin> command. If you manually download and copy a plugin to a directory that is not sourced in /etc/vimrc or ~/.vimrc, then you will have to source it before you can use it.

Some plugins can also be called with vim <path/plugin>, or with a shell script from the Linux command line.

Most plugins come with extensive documentation. If, for example, you download the file newplugin.vim, there might also be a corresponding newplugin.txt file. You can copy newplugin.txt to /etc/vim/doc or ~/.vim/doc, then source the help file with :helptags /etc/vim/doc/ or helptags ~/.vim/doc from the vim command line. This allows you to type :help newplugin to access the newplugin.txt helpfile.

Since vim plugins are basically shell scripts, you can create plugins for just about any purpose you can imagine. For more information on writing your own plugins, enter :help write-plugin from the vim command line.

Among the many good plugins available for vim (including an Emacs emulation plugin), here are nine for you to try.

Tutor

Tutor is generally distributed along with vim. You can call it from the command line with vimtutor. This plugin is a good tutorial for the beginning vi user, as it begins with the basic movement keys and continues through editing, command execution, and creation of a personal vimrc file. Even if you're familiar with vim or vi, you'll probably run across something you've forgotten, or never known.

Vimspell

Vimspell is distributed with vim, beginning with version 6.3. It allows you to run your text file through the aspell or ispell spelling checkers, with any resulting errors highlighted within vim. Vimspell works like most other spell-checkers, allowing you to select alternate spellings, skip words, or add words to your personal dictionary.

Explorer

Distributed with vim, Explorer allows vim to display a directory tree when a directory, as opposed to a specific file, is given as an argument to vim. You can then navigate the directory tree within vim and select a file for editing.

VIFM

Although vifm.vim is available as a standalone file manager, you can copy it to your plugin directory to allow both vifm and vimdiff to be used within a normal vim editing session.

UTL

Universal text link allows you to set hyperlinks within your text documents. Hyperlinks can be used to start applications, open related documents, or bookmark parts of your text document.

Calendar

Calendar adds a calendar display to the side or bottom of your vim session. You can attach notes to each date of the calendar.

MRU

The Most Recently Used file list allows you to type :MRU at the command line to display a list of those files most recently edited. This is useful for system administration, especially when you want to see what you've been up to as root.

winmanager

If you find the filetype plugins helpful, then winmanager may also be of real value to you. Entering :WMToggle at the vim command line opens two small panes to the left of your text editing session that display a directory browser and a buffer browser. The result is a small, fast, powerful integrated development environment that provides syntax highlighting and key mappings customized for specific languages. Ctrl-w allows you to use the h, j, k, and l keys to move between windows as you would between characters in vi/vim. You can combine other plugins with winmanager, including a tag explorer, which you can access with the Ctrl-n key combination from the directory explorer window.

Tetris

Yes, Tetris is available for vim, with high score and Traditional or Rotating game play. In Rotating, the columns continuously move left, off the screen, and back to the right again. If for no other reason than to play Tetris on an ASCII console, you should try this out.

In addition to plugins, there are many more features and versions of vim available. Some that are worthwhile are:

Gvim -- Known as the "official" vim GUI session, gvim is excellent for beginning to experienced vim users. Gvim allows you to use a scrollbar, mouse, menus, and cut and paste in a GUI-friendly manner without sacrificing any of the vi/vim keystrokes or conventions.

Cream -- Another X-capable vim session, aimed specifically at the beginning vim user. Cream includes more formatting options and extensive helpfiles.

Vigor -- It's "Clippy" for vim. Best for the vi-phobic.

The growth of vim is staggering. There are currently more than 1,300 plugins available at vim online, some of which are bound to make your life easier or a little more fun. Taking advantage of such a wealth of hard work and talent is more than just good fun; it's good sense.

Michael M. Murphree has been a Linux user for more than a decade. He administers high-performance computational clusters and is certified LPIC-2 by the Linux Professionals Institute.

Share    Print    Comments   

Comments

on Vim's newest features

Note: Comments are owned by the poster. We are not responsible for their content.

The only feature I want

Posted by: Anonymous Coward on August 30, 2005 11:41 PM
Is an even faster, easier way to uninstall it.

#

Re:The only feature I want

Posted by: Anonymous Coward on August 30, 2005 11:50 PM
# rm -fr /

#

Re:The only feature I want

Posted by: Anonymous Coward on August 31, 2005 03:07 AM
You should uninstall yourself.

Cheers.

#

gvim..

Posted by: Anonymous Coward on August 31, 2005 12:58 PM
Do these features get added to gvim too?

#

Re:gvim..

Posted by: Anonymous Coward on August 31, 2005 08:30 PM
Yes. gvim is just a simple Gtk wrapper around the exact same code as Vim.

#

New?

Posted by: Anonymous Coward on August 30, 2005 07:06 PM
These are new features? Not really.

#

Vim difficult

Posted by: Anonymous Coward on August 30, 2005 08:09 PM
Vim is difficult, and I have no idea how to use it, same goes for emacs.

I like to use nano (or pico) because it is good and very simple.

Isnt there any text editor like "edit" that come in msdos?
(It has a menu like File, Edit, Help etc)

#

Re:Vim difficult

Posted by: Anonymous Coward on August 30, 2005 08:23 PM
I have to agree about vim being hard to learn.

I spent quite a long time learning to use vim and it is very powerful once you master the tao of vim. I went through the emacs tutorial, but emacs is way to much ctrl-shift-this and meta-that. Emacs seems harder than vim. Of course, people get quite passionate about their text editor.

After spending a lot of time with many editors, I settled on nano. It has lots of great, powerful features and is easy to learn and use. I use it probably 2-4 hours a day.

#

Re:Vim difficult

Posted by: Anonymous Coward on August 30, 2005 11:57 PM
Try 'nedit'.

#

Re:Vim difficult

Posted by: Administrator on August 31, 2005 11:36 AM
Vim is not difficult to learn, and GVim, in particular, is even easier, because it has a graphical user interface. I agree with the person before me, if you want easy and you want a graphical editor, try out NEdit. It is as extensible as Vim, but the defaults are easier to deal with.

Both Emacs and Vim are difficult to really thoroughly learn because there is so much to them, but some variant of Vi is important to know, because it is the one editor common to virtually all UNIX and Linux systems (except for a really primitive editor, ed, which is a line editor, and also very prevalent).

Concerning those who say that Emacs has Ctrl this and Esc that, Emacs has flexible bindings that can be set up any way you want them. Only the default bindings are full of Ctrl and Esc sequences. Emacs can also take on Vi like bindings, Wordstar like bindings, Digital's old EDT bindings, and any bindings that anyone cares to create. Believe it or not, Vim can also emulate Emacs! So both of them are incredibly powerful and flexible. IF you equate that with difficult, so be it. I'll take difficult if defined THAT way any day! I prefer flexibility over total simplicity.

That said, I use numerous text editors. The most common ones I use are GNU Emacs, Gvim, and NEdit.

#

Re:Vim difficult

Posted by: Anonymous Coward on August 31, 2005 01:44 AM
it's not difficult, you're just lazy and stupid.

#

Re:Vim difficult

Posted by: Anonymous Coward on August 31, 2005 03:04 AM
It's not difficult, it's just another way of text editing!

#

Re:Vim difficult

Posted by: Anonymous Coward on August 31, 2005 05:29 AM
<a href="http://freshmeat.net/projects/mpmp/?branch_id=14034&release_id=205225" title="freshmeat.net">Minimum Profit</a freshmeat.net> text editor looks and feels like the Microsoft DOS Editor. In Debian, 'apt-get install mped'.

#

RTFA and use cream

Posted by: Anonymous Coward on August 31, 2005 12:36 PM
most people find gvim difficult because they don't understand what a modal text editor is.

That's why the article mentioned 'cream.' It makes vim 'friendlier' by making it nonmodal and adding useful plugins. Everything will be in the menus, just as they are on Word or 'edit' or other programs.

#

Re:Vim difficult

Posted by: Anonymous Coward on August 31, 2005 11:10 PM
Yes there is, there is an editor called LE thats just like the old dos Edit program.

#

Re:Vim difficult

Posted by: Anonymous Coward on September 02, 2005 05:35 AM
I thought vim was difficult to learn too until I followed the instructions in 'vimtutor'. The commands it explains are sufficient to use vim decently. Then if you want to learn something more read some text on the internet, they're very useful.
I have to say that using vim isn't hard at all and it's far easier from using emacs and other weird editors... Moreover it's simple, full of features and extensible too.

#

Re:Vim difficult

Posted by: Administrator on August 31, 2005 07:39 AM
I kinda like that edit program in MSDOS... I wonder if Wine can run DOS programs? I've never tried though.

Vi doesn't seem THAT complicated to me, except that whenever I change distro or anything, it seems to work differently for some reason and it's really baffling. I used FreeBSD for like two months and I still barely manage to get it to let me enter text or delete a line. I'm used to the one that comes with Redhat though.

Personally I only ever use it when working over SSH anyway, normally I just use the text editor that comes with Gnome. Simple!

#

Re:Vim difficult

Posted by: Administrator on August 31, 2005 03:09 PM
I kinda like that edit program in MSDOS... I wonder if Wine can run DOS programs?


Wine does contain a DOS emulator. Windows runs DOS programs so Wine will try too.

<a href="http://www.dosemu.org/" title="dosemu.org">DOSEMU</a dosemu.org> is a DOS emulator for linux, which may work better.

#

Re:Vim difficult

Posted by: Administrator on August 31, 2005 03:57 AM
yes, it's definitely difficult, but it's absolutely worth it. When I first switched to Linux, I used pico, because I didn't think I'd ever be able to learn Vim, but when I put some serious time into learning Vim later, I regretted not having tried to do it earlier. The payoff is more significant for certain kinds of editing. If you are doing programming, no matter how long it takes to you to learn vim, the increase in productivity will more than compensate you for the effort.

#

Simple VIM Reference

Posted by: Administrator on September 24, 2005 05:00 AM
For beginners a good reference is at

<a href="http://simpletutorials.com/vim/index.php" title="simpletutorials.com">http://simpletutorials.com/vim/index.php</a simpletutorials.com>

#

vimspell

Posted by: Anonymous Coward on August 31, 2005 03:00 AM
Nice. Always wanted something like this. Thanks for the tip!

#

baffled

Posted by: Anonymous Coward on August 31, 2005 03:15 AM
errr, none of those features are new? and none of them require plugins. they've been there for ages...

#

Re:baffled

Posted by: Anonymous Coward on August 31, 2005 04:08 AM
Yeah... all the stuff it mentions in the beginning as "new" is just what Vim has that Vi doesn't. Those things have been there for years.



My favorite feature in Vim, though, is<nobr> <wbr></nobr><tt>:help uganda</tt>.

#

Re:baffled

Posted by: Administrator on August 31, 2005 08:15 PM
No, they're not new to vim, but they are made available through plugins (usually distributed with the vim installation). Please see my later comment to the article itself. Sorry for the confusion.

Mike

#

Huh?

Posted by: Anonymous Coward on August 31, 2005 04:58 AM
This isn't new at all. This article is covering things that have been around for a very long time, and it isn't doing a very good job of it. Please try harder next time.

#

Re:Huh?

Posted by: Anonymous Coward on August 31, 2005 07:53 PM
The original title was "ten good plugins for vim", the purpose being to highlight handy features available for vim that are not in straight vi. I agree, they're not all new, but some users might not be aware of them, and should be.

Mike

#

Re:Tetris and spellcheck?

Posted by: Anonymous Coward on August 31, 2005 08:09 AM
Since Microsoft Notepad (which is the text editor to which you should compare vim) does *not* have a spell checker, I think it's pretty worthwhile pointing out that vim does!

#

Re:Tetris and spellcheck?

Posted by: Administrator on August 31, 2005 12:25 PM
Notepad, as far as I know, hasn't really had any mentionable development work done on it in at least a decade. Best as I can tell, the version I have with WinXP and the version I have on my Win 3.11 are virtually identicle. Last time I tried to print something with it, it actually just sent raw data to the printer instead of using the Windows print driver.

You really shouldn't have to compare Vi to what is practically abandonware. And I don't mean that as a jab to Vi, Vi is fine, I'm just saying that it's not really that noteworthy to beat notepad at anything.

Wordpad is more equivalant, even though it has a few rich-text features. Or GEdit and NEdit. Vi still has way more features than Wordpad, but that's a more fair comparison.

Notepad is more like... Well, a notepad. Not a developer tool or a complete text editor. The name is pretty self-explanatory. I think the equivalant here would be KNotes or echo & cat or something.

More importantly, nobody actually uses notepad. There are two kinds of computer users, really. Those who will use Word to write a plain text document and probably don't know what Notepad is, and those who already know a spellchecker isn't that notable.

#

Re:Tetris and spellcheck?

Posted by: Anonymous Coward on August 31, 2005 12:31 PM
No MS plain text editor has had spell check.

#

Re:Tetris and spellcheck?

Posted by: Anonymous Coward on August 31, 2005 08:29 PM
I think nano and pico would be good to compare to Notepad. They'd probably still win.

#

More Programming Productivity with Vim?

Posted by: Anonymous Coward on September 01, 2005 01:52 AM

I have never really understood what people mean when they say "increase in programming productivity" when pushing Vim to newbies. Most of the really useful programming plugins are really only useful/intuitive with the GUI version of Vim. And a lot of the features that, at least in my case, increase programming productivity are either poorly implemented or missing.


I use Eclipse for my projects. I use vim whenever I need to drop to a command line and have to use a text editor. I use Emacs whenever I find myself on a command line and need a more intuitive editor, editing a large file and then doing regex-based search and replace at least is faster under Emacs. Personally I don't recommend Vim or Emacs to newbies because they will likely spend most of their time figuring out how to work with the editor instead of actually writing code (which should be their focus as newbies). And personally I don't use Vim or Emacs for very large projects because they can be very difficult to manage under either editor.


As for experienced programmers coming from Windows to Linux/Unix, I don't see the point of recommending vim to them either. Some of the things I look for in a text editor for programming are:


  • Object/Class/Function browser
  • Multiple project management capability
  • Interproject dependency resolution
  • Automatic code formatting/re-indenter/beautifier
  • Code autocomplete
  • Source code syntax checking
  • Build project in the background
  • Automatic TODO checklists from source code comments
  • Syntax highlighting
  • Multiple editor windows
  • Extensible through plugins
  • Regular expression search and replace

Of all the editors/IDE I've tried (including Vim, Emacs, Komodo, JEdit), only Eclipse has come close to my expectations. Emacs comes a close second.

#

Re:More Programming Productivity with Vim?

Posted by: Anonymous Coward on November 20, 2005 02:14 PM
The primary reason why Vim is such a good choice to me seems to be based off the fact that learning Vim has more mainstream availability in a production environment. Today's newbie could be next year's junior sysadmin. Anyone learning Vim will get the basics of vi under their belt, and any UNIX/Linux system they hop onto will have vi available. This is not as true for other text editors, Emacs included. Vim provides a great deal of power and almost all the same features as some of the more targetted development environments/text editors, can be extended with a healthy selection of plugins, can be remapped and scripted to better accomodate an almost endless variety of development or authoring environments, and anyone that takes the time to elevate themselves to intermediate or master can do some truly awe-inspiring things that Windows notepad.exe only dreamed of being able to do so effortlessly.

Much like Lisp, once you 'get' vi and vim, you'll understand. Try it and see.

#

Re:More Programming Productivity with Vim?

Posted by: Administrator on September 01, 2005 03:21 AM
Vim improves productivity in several ways. It allows me to perform code transformation and refactoring at a very fast pace, it allows me to use abbrev and a scriptable templating system to automate some code generation, it allows me to integrate support for my own build and test frameworks, and it also facilitates extremely rapid navigation between different related files.


I'm used to managing my projects from the command line myself, I don't like using a canned project management system, so applications like Eclipse just get in my way. I can understand why other people might prefer to let the IDE handle all of that for them, but I can really work much faster when I do things my way.


As far as your list of features is concerned:


  • object/class/function browser - I use the Vim TagList plugin, which gives me a complete browser that I can easily extend and configure


  • project management capabilities - I use Vim's ruby bindings to integrate support for my own project management script system

  • automatic code formatting - the indent command does just fine for C code, and I use a couple of other utilities for other languages. I have a single binding assigned to beautification and associate the right command with it for each relevant file type

  • code autocomplete - Unfortunately, Vim doesn't have a global code auto-completion feature yet, but there are some plugins that can use etags to provide simple code completion features for specific languages

  • syntax checking - once again, I do this in vim with external tools that I have integrated

  • build project - I have my own build system that will allow me to perform a background build and display the results in a new buffer split

  • automatic todo checklists - well, Vim doesn't exactly do GUI checklists or anything, but I do generate visual todo lists from comments and I can use my scripts to jump to specific todo items

  • syntax highlighting - I'm willing to bet that Vim provides syntax highlighting support for a broader number of file types than eclipse currently can

  • multiple editor windows - in vim we can have an unlimited number of buffer splits and we can have visible and non-visible buffers. It is also possible to start multiple instances, thereby creating more than one window

  • extensible through plugins - vim is extremely extensible and plugins can be written in perl, python, ruby, tcl, or vim's own scripting language.

  • regular expression search and replace - hell yes. Vim has extremely powerful regexp search and replace capabilities and vim also makes it very easy to use command line text transformation tools like sed and awk from within the editor

#

Re:My mistake

Posted by: Anonymous Coward on September 01, 2005 04:11 AM
You got that 3 week old compilin' kernels yet? Congrats. You're forgiven!<nobr> <wbr></nobr>:^D

#

Tetris and spellcheck?

Posted by: Administrator on August 31, 2005 07:48 AM
I thought pretty much every text editor had spellcheck. I think Microsoft and Claris and whoever were bragging about that in the 80s or something.

From what I'm reading in other posts, looks like Vim already had spellcheck too anyway, so I'm not even gonna call them 'catching-up'. Bragging that a text editor can check your spelling in 2005 is more than a tad silly.

I'm guessing the article's author saw a new post and missed the date on it. *shrugs*

#

My mistake

Posted by: Administrator on August 31, 2005 08:12 PM
I have to take the blame for not catching a change in the title of the article when it was sent to me for review. Consider this more of a "good/handy plugins" article than a "newest features". I know that not all of the plugins listed are new to vim, and the main thrust should be that plugins can be used to give vim more capabilities than vi. I plead the "New Father" defense (ages 2, 1, and 3 weeks).


Mike

#

Vim's newest features

Posted by: Anonymous [ip: 70.113.4.75] on July 30, 2007 12:37 AM
I'm trying to read this page on a fresh installation of Slackware 12 using a new version of Firefox. The text in the body of the page is too small to read. Ctrl + just messes up the formatting.

Can you offer suggestions. I've searched your site without success.

Larry

#

This story has been archived. Comments can no longer be posted.



 
Tableless layout Validate XHTML 1.0 Strict Validate CSS Powered by Xaraya