You don't need to use two different execute()
calls, you can simply call both commands in execute()
like this:
nnoremap <Leader>ntd :execute "tabe! ". g:path . "l_todo.txt \| vsplit! " . g:path . "u_todo.txt"<CR>
Note the escaped piped character (\|
) it is escaped so that vim understands that it is part of the command fed to execute
.
Otherwise, when you source your vimrc, Vim would try to execute first nnoremap <Leader>ntd :execute ":tabe! ". g:path . "l_todo.txt
followed by vsplit! " . g:path . "u_todo.txt"<CR>
which is not what you want.
You could also improve the readability of your code like this:
let firstCommand="tabe! ". getcwd() . "/l_todo.txt"
let secondCommand="vsplit! " . getcwd() . "/u_todo.txt"
nnoremap <Leader>ntd :execute firstCommand . "\|" . secondCommand<CR>
Here we separate the different part of the string give to execute()
to see the two actions executed.
We also use :h getcwd()
to get the current working directory so that we don't need a global variable to get the path.
Several other points about your code:
- You don't need the
:
in the commands you feed to execute()
- Always use the non recurcive version of
map
(i.e. noremap
) unless you know what you're doing
- Always specify a mode to
map
(see :h map-modes
)
execute
call with a pipe|
to chain the commands likennoremap <leader>a :execute "tabnew \| vsplit"<CR>
. I didn't test it but I think your command should bemap <Leader>ntd :execute "tabe! ". g:path ."l_todo.txt \| vsplit! ".g:path ."u_todo.txt"<CR>
(Also usenore
and a mode in yourmap
command i.e.nnoremap
, this is a good practice and can save you a lot of debugging`)