开发者

Vim: gf opens directories, not files

I am trying to configure vim's 'path' and 'suffixesadd' so when I use gf over FILE_NAME, and pwd is /some/dir/, it opens /some/dir/FILE_NAME/File_Name.xml

In vimrc I put:

set suffixesadd=.xml
set path=.,dir/**

But, instead of opening File_Name.xml it opens the directory FILE_NAME

What should I do to confi开发者_如何学Gogure vim so it looks for files before directories?

PS: Im using gvim in Windows and have NERD plugin active


I don't think this is possible with gf as standard, but you could always do:

" Mapping to make it easier to use - <C-R><C-W> inserts the Word under
" the cursor
nmap gx :call CustomGFOpen("<C-R><C-W>")<CR>
" The function that does the work
function! CustomGFOpen(cursor_word)
    " The directory name (e.g. FILE_NAME) is passed as the parameter
    let dirname = a:cursor_word
    " This is a regular expression substitution to convert 
    " FILE_NAME to File_Name
    let filename = substitute(a:cursor_word, '\(^\|_\)\@<=\([A-Z]\)\([A-Z]\+\)', '\=submatch(2) . tolower(submatch(3))', 'g')
    " The extension
    let extension = '.xml'
    " Join the whole lot together to get FILE_NAME/File_Name.xml
    let relative_path = dirname . '/' . filename . extension
    " Open that file
    exe 'e' relative_path
endfunction
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜