Vim Open unite in current folder

138 views Asked by At

I got the following hotkey mapping:

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

This works great, however, I want to make it so that path equals the current folder I'm in (which will be seperate from working directory).

Anyone know how I can make this happen? :S

3

There are 3 answers

1
VanLaser On BEST ANSWER

How about using:

:UniteWithBufferDir file 

or

:UniteWithCurrentDir file

(depending on what you want)

4
DJ. On

Unite allows dynamic argument by using backtick, as documented in the Unite help doc:

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>

So in your case, the mapping will be:

:nnoremap <leader>f :Unite file -path=`expand('%:p:h')`
1
sidyll On

You can use the expand() function to use %:p:h in places where a file name is not expected (these expansions are for file-name arguments, not others like what it appears to happen with your command)

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

But you can't map that directly. It is a command that needs to be built "on-the-fly", so you can use :execute to build and execute an evaluated expression:

nnoremap <leader>f :exec "Unite file -path=" . expand('%:p:h')