I have this in my .vimrc
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
I have this in my .vimrc
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
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
:help :exe
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>'
With the <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.