Vim:gf打开目录,而不是文件

时间:2010-10-21 12:24:54

标签: windows vim file-io

我正在尝试配置vim 'path''suffixesadd',因此当我gf使用FILE_NAME而pwd为/some/dir/时,它会打开{{1} }}

在vimrc中我放了:

/some/dir/FILE_NAME/File_Name.xml

但是,它不会打开set suffixesadd=.xml set path=.,dir/** ,而是打开目录File_Name.xml

如何配置vim以便在目录之前查找文件?

PS:我在Windows中使用gvim并且NERD插件处于活动状态

1 个答案:

答案 0 :(得分:1)

我不认为gf作为标准是可行的,但您可以随时执行:

" 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