0

我得到以下热键映射:

nnoremap <leader>f Unite file -path=~/Workspace

这很好用,但是,我想让它的路径等于我所在的当前文件夹(它将与工作目录分开)。

有谁知道我怎么能做到这一点?:S

4

3 回答 3

4

您可以使用该expand()函数%:p:h在不需要文件名的地方使用(这些扩展用于文件名参数,而不是像您的命令出现的那样)

:echo expand('%:p:h')

但是你不能直接映射它。这是一个需要“即时”构建的命令,因此您可以使用它:execute来构建和执行评估表达式:

nnoremap <leader>f :exec "Unite file -path=" . expand('%:p:h')
于 2015-11-23T18:31:57.503 回答
3

如何使用:

:UniteWithBufferDir file 

或者

:UniteWithCurrentDir file

(取决于你想要什么)

于 2015-11-23T21:56:45.690 回答
2

Unite 允许使用 动态参数backtick,如 Unite 帮助文档中所述:

You don't have to use |:execute| for dynamic arguments.
You can use evaluation cmdline by ``.
Note: In the evaluation, The special characters(spaces,  "\" and ":")
are escaped automatically.
>
    :Unite -buffer-name=search%`bufnr('%')` line:forward:wrap<CR>

因此,在您的情况下,映射将是:

:nnoremap <leader>f :Unite file -path=`expand('%:p:h')`
于 2015-11-23T22:08:51.060 回答