Vim Tips Wiki

Edit file found by whereis

1,623pages on
this wiki
Add New Page
Add New Page Talk0
Tip 301 Printable Monobook Previous Next

created August 7, 2002 · complexity intermediate · author Little Dragon · version 5.7

You can write a little shell function that will let you easily edit any file that is in the path, or which's location can be retrieved with the whereis tool. This is something similar to what I have in /etc/profile:

function vvim() { vim `whereis $1|cut -d: -f2` }
function ggvim() { gvim `whereis $1|cut -d: -f2` }

Then just type, for example, "vvim ls", and you'll start vim with /bin/ls and /usr/share/man/ls.1.gz loaded. (it's not very useful to edit /bin/ls, but you get the ideea).

A more useful example: vvim profile


I liked the idea, great for editing scripts, but it didn't work for the shells I use. Here's how I got it to work for the 2 shells I use:

For 'bash':

vvim () { command vim `whereis "$@" | cut -d: -f2` ; }

For 'tcsh' in .tcshrc:

alias vvim 'vim `whereis \!* | cut -d: -f2` '

Also on Fandom

Random Wiki