Reputation: 1108
My question is about usage of vim-projectroot with fzf.vim
I have a key mapping which opens :Files
at project root like this
nnoremap <leader>t :ProjectRootExe Files<CR>
But problem is it's interfering with set autochdir
. Unless I force a new session with :e/:sp/:vsp
current directory remains same as previous directory.
So I thought of passing directory as the second argument to :Files path
like this
function Guess()
return projectroot#guess()
endfunction
nnoremap <leader>t :Files Guess()<CR>
But for obvious reasons which I can't figure out I am unable to get the usage working. How can I specify in a vim mapping that it should combine the command with output of a function?
What I want is :Files output_of_Guess()
to be invoked.
Upvotes: 1
Views: 1374
Reputation: 172580
Vim's evaluation rules are different than most programming languages. You need to use :execute
in order to evaluate a variable (or expression); otherwise, it's taken literally; i.e. Vim uses the function name itself as the argument.
nnoremap <leader>t :execute 'Files ' . Guess()<CR>
An alternative for mappings is using :help :map-expr
; that's basically :execute
built into the variant of :map
:
nnoremap <expr> <leader>t ':Files ' . Guess() . "\<lt>CR>"
Upvotes: 2