I have this in my
let $ROOTPATH=FindRootDirectory() nnoremap <leader>ct :!clear<CR>:!$ROOTPATH/app/Console/cake test %:p<CR>
Is there a way I can write this in one line?
Using vim-rooter pluguin
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.Sign up to join this community
nnoremap <leader>ct :exe "!clear; ".FindRootDirectory()."/app/Console/cake test %:p"<CR>
The key is the
:exe command, which executes its argument strings. In this case there is one argument string, which is the concatenation (
. operator) of "!clear; ", the output of the FindRootDirectory() function, and "/app/Console/cake test %:p". The
<CR> terminates the mapping. I transformed the two shell commands into one, but you can use two commands if you prefer. See
An alternative to @garyjohn's answer is to use a map expression, i.e.
nnoremap <expr><leader>ct ':!clear<cr>:!' . \ FindRootDirectory() . '/app/Console/cake test ' . expand('%:p') . '<cr>'
<expr> keyword for the mapping, the right-hand side is evaluated and it's result will be used as the mapping. In this case, the result is the concatanated string. See
:h map-expression for more details.