The Pragmatic Programmer
[1] 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 [2] are [3] other [4] questions [5] 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
Put this in your ~/.inputrc
:
set editing-mode vi
That gets you vi
mode in everything that uses readline
(e.g. mysql
client).
set -o vi
? - OscarRyz
set -o vi
does in bash
to whatever uses readline
. - chaos
C-p
etc are trivial to bind in addition to vi keys. And all in insert mode what's the default for a new prompt in bash/zsh :) - progo
zsh
does not use readline
, but instead zle
, which does not read ~/.inputrc
. - orftz
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.
For Firefox, It's all text [1] and ViewSourceWith [2] 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 [3]. Scroll pages with hjkl, go back and forward with H and L, and many more keybindings [4] familiar to Vim users.
It is not at version 1.0 yet, but jV [5] makes text areas work like vi.
And finally there is an experimental way to directly embed the actual Vim in Firefox using embedded editor [6] - though it requires mozplugger and will only work on Linux.
For more details see this question about using vim with firefox [7].
[1] https://addons.mozilla.org/en-US/firefox/addon/4125I can highly recommend ViEmu [1] 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.
[1] http://www.viemu.com/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 [1].
[1] http://stackoverflow.com/questions/537522/standard-python-interpreter-has-a-vi-command-modeFor Firefox use Vimperator [1]. 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.
[1] http://vimperator.org/vimperatorFor Thunderbird, the external editor [1] extension allows you to use gVim to write your emails, or you could use Vimperator [2]'s sister extension - muttator [3].
[1] http://globs.org/articles.php?pg=2&lng=enSet 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.
dactyl [1]
is like vimperator but maybe even better (I just started using it a bit).
I'm no programmer but like using this way of browsing. I still wonder if it's worth my while getting more into vim, since I'll probably never write a program; a bit of basic command line use in the terminal is about it.
[1] http://dactyl.sourceforge.net/pentadactyl/Vim can be used as PAGER [1] and for viewing man pages [2].
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.
[1] http://vim.wikia.com/wiki/VimTip121For Google Chrome, there are now a few extensions. Text Aid [1] and Edit with Emacs [2] 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 [6].
[1] https://chrome.google.com/extensions/detail/ppoadiihggafnhokfkpphojggcdigllpYou 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 [1].
[1] http://stackoverflow.com/questions/397229/reaching-up-to-hit-the-escape-key-sucks-especially-in-vimThere 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 [1]
[1] http://eclim.org/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.
There is a PDF viewer called apvlv [1] that uses vi-like bindings.
[1] http://code.google.com/p/apvlv/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.
hjkl
aswell. - Hamish Downer
I've seen quite a few examples around the web of Autohotkey being combined with gvim [1] in order to increase ubiquity. There are probably more.
[1] http://jamesoff.net/site/2009/04/03/using-gvim-to-edit-mail-in-outlook/For Mac users I just came across the Vi Input Manager plugin [1] 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).
[1] http://www.corsofamily.net/jcorso/vi/For your Vim gaming needs: Word War vi [1] - a retro styled side scrolling shoot'em up arcade game for Linux.
[1] http://wordwarvi.sourceforge.netAbiword 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!
Here's an idea for a bit if hjkl ubiquity (based on this thread [1] at superuser.com) but sadly it doesn't work.
xev
tells me that my Windoze key sends keycode 133; I created .hjkl.modmap
:
keycode 66 = Mode_switch
keysym j = j J Left
keysym l = l L Right
keysym i = i I Up
keysym k = k K Down
And installed it with xmodmap
$ xmodmap .hjkl.modmap
Now Win-[hjkl] behave like the arrow keys. One less reason to take my hands off the home keys. But it clobbers the Win key. Maybe someone knows how to just remap Win-h, etc?
[1] http://superuser.com/questions/213051/remap-arrow-keys-to-winijkl-on-linuxOne last link to another question - this one about vi mode plugins for IDEs [1].
[1] http://stackoverflow.com/questions/294613/does-any-ide-have-a-vi-keybindings-optionsThis [1] 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] http://duartes.org/gustavo/blog/post/home-row-computingIn the game NetHack [1] 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).[1] http://www.nethack.org/
MonoDevelop has a vi mode [1] too.
Also check Eclim [2]. 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.
[1] http://mjhutchinson.com/journal/2008/10/14/vi%5Fmodes%5FmonodevelopThere 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 [1] for netbeans.
[1] http://jvi.sourceforge.net/Just for completeness, I will mention that you can use command line email clients such as mutt [1] and pine [2]. And with them you can use any command line editor for writing your emails.
[1] http://en.wikipedia.org/wiki/Mutt%5F%28e-mail%5Fclient)Check out the IDE pida [1]. This embeds vim right inside the IDE. Standard features like interface with common version control software and source code browsing with ctags / gtags are included. Plugins are available for a variety of languages. You can also use this with emacs instead of vim.
[1] http://pida.co.ukI have half-followed the instructions at the Vim tips wiki [1] 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...
[1] http://vim.wikia.com/wiki/Use%5Fgvim%5Fas%5Fan%5Fexternal%5Feditor%5Ffor%5FWindows%5Fapps