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
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
- Always use the non recurcive version of
noremap) unless you know what you're doing
- Always specify a mode to