views:

52

answers:

1

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 configure vim so it looks for files before directories?

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

+1  A: 

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
Al