views:

3243

answers:

25

The Pragmatic Programmer recommends that you should use one text editor for everything. My chosen weapon editor is Vim.

So I want to collect all the ways in which Vim (and the Vim keybindings) can be used and setting up your computer to make Vim work well. This includes how to embed Vim in your IDE, web browser, email client, command shell ...

But I don't want Vim tips - there are other questions for them. I want tips to get into Vim, or Vim mode. Though tips about Vim mode not in an editor would be allowed (e.g. tips for vi mode when using Bash).

Update: Going quite well so far, with ways to edit in Vim/gVim, or to get vi mode in Firefox, Safari, Thunderbird, many IDEs and command line applications, MS Outlook and Word. But I'm wondering if there are more. Particular applications I wonder about include

  • OpenOffice.org
  • KOffice
  • Kmail
  • Evolution
  • Internet Explorer
  • GIMP and Photoshop ... (only joking ;)
+12  A: 

For Thunderbird, the external editor extension allows you to use gVim to write your emails, or you could use Vimperator's sister extension - muttator.

Hamish Downer
+10  A: 

For Firefox, It's all text and ViewSourceWith allow you to use an external editor for text boxes. You generally want to use

gvim -f

The -f option means that will not fork a process, so this allows the calling program to wait until gVim closes. Without the -f option the above plugins won't work very well ...

If you want to go further then investigate the vimperator. Scroll pages with hjkl, go back and forward with H and L, and many more keybindings familiar to Vim users.

It is not at version 1.0 yet, but jV makes text areas work like vi.

And finally there is an experimental way to directly embed the actual Vim in Firefox using embedded editor - though it requires mozplugger and will only work on Linux.

For more details see this question about using vim with firefox.

Hamish Downer
The main thing I don't like about It's All Text is that I can't find any way to launch the external text editor using the keyboard. What good is it if I have to use my mouse to launch the editor?
Chad Birch
@Chad Birch: If you look at the preferences for It's All Text, you'll see there is a "Hot Key" preference that allows you to set a keyboard shortcut. I use Ctrl-E
Hamish Downer
try vimperator )
dysmsyd
+4  A: 

You can set your keyboard to swap Caps Lock and Escape.

With the standard Ubuntu/GNOME desktop, go through the menus: System -> Preferences -> Keyboard -> Layouts tab. Then hit the "Layout Options" button, click on the triangle next to "Caps Lock key behaviour" and select "Swap ESC and CapsLock".

Not strictly part of Vim, but it makes Vim so much nicer to use.

Also see this question about making the ESC key easier to get to.

Hamish Downer
I guess that this would be cool. But I tried it and now I know that I wouldn't survive the first three days.
innaM
Swapping is a bad idea because you end up hitting caps lock by accident instead of ESC. Better to get rid of the caps lock functionality entirely and have both of those keys produce an ESC. Unless of course you actually find caps lock useful.
intuited
@intuited: I do find caps lock useful once in a while. I never reach up to the ESC key normally. But I guess having both be ESC might be useful for people in transition.
Hamish Downer
+4  A: 

There are some Vim plug-ins for Eclipse, see http://www.vimplugin.org/.

There is also a commercial one at http://www.viplugin.com/viplugin/.

Also, Eclim is a layer that connects headless Eclipse to Vim, giving it code completion abilities, and an understanding of Eclipse projects: Eclim home page

Adrian Mouat
I'm a user of viplugin. It works but it's not great. However it's better than nothing.
Peter Severin
+12  A: 

When using Bash, you can do

$ set -o vi

to enable vi editing mode. You start in insert mode, but you can press Escape and go forward and backwards with h and l, delete the previous word with db (or dB for back to the previous gap defined by spaces) ... If you like it, stick

set -o vi

in your .bashrc file.

Also see this question about vi mode and readline.

Hamish Downer
This is covered by adding 'set editing-mode vi' to .inputrc
graywh
@graywh: it is, but sometimes you just want a temporary change.. Maybe you are ssh'ed into a server as root, and just want to change to vi-mode for that session, but not to change it for everyone else. Or you are on someone else's computer for a brief period.
Hamish Downer
+26  A: 

Put this in your ~/.inputrc:

set editing-mode vi

That gets you vi mode in everything that uses readline (e.g. mysql client).

chaos
This is really huge!
kizzx2
Is this similar to `set -o vi` ?
OscarRyz
Yeah, it does what `set -o vi` does in `bash` to whatever uses `readline`.
chaos
+2  A: 

One last link to another question - this one about vi mode plugins for IDEs.

Hamish Downer
+16  A: 

I can highly recommend ViEmu which is a plugin for Visual Studio giving you nearly 100% Vim capability while retaining things like Intellisense. It's great for C# coding. There is also a version of ViEmu for Word, Outlook and for SQL Server if you do a lot of those and want the power of Vim there as well.

Steve Rowe
+2  A: 

In the game NetHack you can use vi keyboard mode. Just set the setting to 0 (zero):

number_pad
Use the number keys to move instead of [yuhjklbn] (default 0 or off).
Joe Philllips
+4  A: 

Vim can be used as PAGER and for viewing man pages.

Many tools, e.g. Git, also let you specify a DIFF program (often via a configuration option or environment variable); Vim's diff mode works very well for that.

Brian Carper
+3  A: 

I've seen quite a few examples around the web of Autohotkey being combined with gvim in order to increase ubiquity. There are probably more.

Andy
+6  A: 

Set your $EDITOR to Vim.

At least in Linux, most environment aware applications will draw on this variable to choose the editor whenever they need you to edit something.

sykora
+2  A: 

For Mac users I just came across the Vi Input Manager plugin which "patches the Cocoa Text System to add a Vi-like command mode". This affects applications including "Safari, TeXShop, XCode".

Looks cool. (Though I am not a Mac user).

Hamish Downer
+1  A: 

Just for completeness, I will mention that you can use command line email clients such as mutt and pine. And with them you can use any command line editor for writing your emails.

Hamish Downer
+10  A: 

Trying to use Vim for everything is overkill. While the book does say

Tip 22

Use a Single Editor Well

At a high level, it also says “use the right tool for the job.” It’s better to know how to use one text editor really well than to be barely competent with a half-dozen; but it would be significantly worse to master only a single program.

andrew
+2  A: 

This site has an AutoHotkey script for Windows that will let you set up some basic Vim keystrokes in any application (I use hjkl for motion everywhere now).

+1  A: 

MonoDevelop has a vi mode too.

Also check Eclim. It started to integrate the functionality of Vim and Eclipse, but now it seems it is beyond that. I have not used it though, but its release notes shows that it supports Python, PHP and C++ and markup languages.

Caglar Toklu
+8  A: 

For Firefox use Vimperator. It transforms Firefox into a vim-like program.

Hit Ctrl-I while your keyboard focus is inside a text area to launch vim on that text area.

dysmsyd
+2  A: 

For your Vim gaming needs: Word War vi - a retro styled side scrolling shoot'em up arcade game for Linux.

A: 

I have half-followed the instructions at the Vim tips wiki but used my own little script for AutoHotKey:

; edit in Vim...
#v::
WinGetActiveTitle, VimTargetWindow
SendInput ^a^c
RunWait c:\Program Files (x86)\Vim\vim72\gvim.exe --servername ClipBrd +ClipBrd +only
If not ErrorLevel
{
    WinActivate %VimTargetWindow%
    Sleep 10
    SendInput ^a^v
}
return

However, it does clobber the clipboard, and is a bit hit and miss whether it gets back to the right application if you've been doing things in the meantime...

Greg
+1  A: 

To change zsh to vi mode:

bindkey -v

To change it permanently, add that line to your ~/.zshrc. Alternatively, if you set your EDITOR (environment variable) to vi or vim, zsh will assume you want vi mode in the shell command line as well.

Pistos
+1  A: 

There is a very good vim plugin for intellij idea (recently partly open sourced). It can easily be installed from the plugins menu.

And there is jvi for netbeans.

0x89
+2  A: 

For Google Chrome, there are now a few extensions. Text Aid and Edit with Emacs both allow editing with an external editor. (Edit with Emacs does not require you to use emacs).

And in the spirit of the Vimperator Firefox extension, there are now

allowing you to navigate pages with vi key-bindings. However currently (May 2010) they are very basic compared to the Vimperator. Vrome is the most feature rich one.

Hamish Downer
+1  A: 

Abiword has an optional VI mode:

http://recycledelectron.blogspot.com/2009/01/vi-and-emacs-key-bindings-in-abiword.html

How I wish that was available for OpenOffice.org:

http://qa.openoffice.org/issues/show_bug.cgi?id=89663

Please comment on that OOo bug!

+1  A: 

There is a PDF viewer called apvlv that uses vi-like bindings.

For example, < Ctrl-f > to forward page, < Ctrl-b > to previous page, 'k','j','h','l' to scrolling a page up, down, left or right, and so on.

And, Apvlv can understand that how many times you want to run the command.

The only thing you need to do is typing the number before the command. For example, typing '50' and < Ctrl-f > will go forward 50 pages, typing '30' and < Ctrl-b > will go previous 30 pages.

Hamish Downer
Just found out that evince (a PDF reader on Linux) lets you move around using `hjkl` aswell.
Hamish Downer