Vim 在当前文件夹中打开 unite
Vim Open unite in current folder
我得到了以下热键映射:
nnoremap <leader>f Unite file -path=~/Workspace
这很好用,但是,我想让路径等于我所在的当前文件夹(它将与工作目录分开)。
有人知道我怎样才能做到这一点吗? :S
您可以使用 expand()
函数在不需要文件名的地方使用 %:p:h
(这些扩展是针对文件名参数,而不是其他类似的情况你的命令)
:echo expand('%:p:h')
但是你不能直接映射它。这是一个需要构建的命令 "on-the-fly",所以你可以使用 :execute
来构建和执行一个计算表达式:
nnoremap <leader>f :exec "Unite file -path=" . expand('%:p:h')
如何使用:
:UniteWithBufferDir file
或
:UniteWithCurrentDir file
(看你想要什么)
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')`
我得到了以下热键映射:
nnoremap <leader>f Unite file -path=~/Workspace
这很好用,但是,我想让路径等于我所在的当前文件夹(它将与工作目录分开)。
有人知道我怎样才能做到这一点吗? :S
您可以使用 expand()
函数在不需要文件名的地方使用 %:p:h
(这些扩展是针对文件名参数,而不是其他类似的情况你的命令)
:echo expand('%:p:h')
但是你不能直接映射它。这是一个需要构建的命令 "on-the-fly",所以你可以使用 :execute
来构建和执行一个计算表达式:
nnoremap <leader>f :exec "Unite file -path=" . expand('%:p:h')
如何使用:
:UniteWithBufferDir file
或
:UniteWithCurrentDir file
(看你想要什么)
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')`