代码之家  ›  专栏  ›  技术社区  ›  Yuri Ghensev

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

  •  0
  • Yuri Ghensev  · 技术社区  · 14 年前

    'path' 'suffixesadd' 所以当我使用 gf 结束 FILE_NAME /some/dir/ ,它打开 /some/dir/FILE_NAME/File_Name.xml

    在vimrc中我说:

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

    但是,不是打开 File_Name.xml 它打开目录 文件名

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

    PS:Im在Windows中使用gvim并激活了NERD插件

    1 回复  |  直到 11 年前
        1
  •  1
  •   DrAl    14 年前

    我不认为这是可能的 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