Vim logo vim online Vim Book Ad

 Tip #299: Open file under cursor.

 tip karma   Rating -6/12, Viewed by 888 

created:   August 6, 2002 4:23      complexity:   intermediate
author:   Little Dragon      as of Vim:   5.7

A little thing that I did and found quite useful:

function! OpenFileUnderCursor()
let FileName = expand("<cfile>")
let OldPath = getcwd()
silent cd %:p:h
execute "silent sp +e " . FileName
execute "silent cd " . OldPath
endfunction

map! silent <M-e> :call OpenFileUnderCursor()<CR>

Then use Alt+E on a filename to open it (relative to the directory the current file resides in).

 rate this tip  Life Changing Helpful Unfulfilling 

<<Changing case with regular expressions | Making a tags file for IDL (Interactive Data Language) >>

Additional Notes

[email protected], August 6, 2002 4:47
Did you ever try gf? ;-)
[email protected], August 6, 2002 5:53
Not to mention ctrl-w f (for another window).
[email protected], August 6, 2002 7:33
Hrm... Never tried gf or C-w f before :)
Cool :)
[email protected], September 2, 2002 23:42
Hmm, ok, but is there a way to open the file in a NEW vim?
If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to [email protected] after searching the archive. Help Bram help Uganda.
SourceForge Logo