Remaping leader with :execute cannot run two commands at once
Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
I have following command:
map <Leader>ntd :execute ":tabe! ". g:path ."l_todo.txt"<CR><ESC> :execute ":vsplit! ".g:path ."u_todo.txt"<CR>
Both tabe!
and vsplit!
commands works fine as separate remapings. I want to join those commands into one remaping.
How to make the above command to work?
key-bindings
add a comment |Â
up vote
2
down vote
favorite
I have following command:
map <Leader>ntd :execute ":tabe! ". g:path ."l_todo.txt"<CR><ESC> :execute ":vsplit! ".g:path ."u_todo.txt"<CR>
Both tabe!
and vsplit!
commands works fine as separate remapings. I want to join those commands into one remaping.
How to make the above command to work?
key-bindings
2
You should try using only onceexecute
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`)
â statoxâ¦
8 hours ago
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I have following command:
map <Leader>ntd :execute ":tabe! ". g:path ."l_todo.txt"<CR><ESC> :execute ":vsplit! ".g:path ."u_todo.txt"<CR>
Both tabe!
and vsplit!
commands works fine as separate remapings. I want to join those commands into one remaping.
How to make the above command to work?
key-bindings
I have following command:
map <Leader>ntd :execute ":tabe! ". g:path ."l_todo.txt"<CR><ESC> :execute ":vsplit! ".g:path ."u_todo.txt"<CR>
Both tabe!
and vsplit!
commands works fine as separate remapings. I want to join those commands into one remaping.
How to make the above command to work?
key-bindings
key-bindings
edited 8 hours ago
statoxâ¦
24.4k660125
24.4k660125
asked 8 hours ago
lluke
434
434
2
You should try using only onceexecute
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`)
â statoxâ¦
8 hours ago
add a comment |Â
2
You should try using only onceexecute
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`)
â statoxâ¦
8 hours ago
2
2
You should try using only once
execute
call with a pipe |
to chain the commands like nnoremap <leader>a :execute "tabnew | vsplit"<CR>
. I didn't test it but I think your command should be map <Leader>ntd :execute "tabe! ". g:path ."l_todo.txt | vsplit! ".g:path ."u_todo.txt"<CR>
(Also use nore
and a mode in your map
command i.e. nnoremap
, this is a good practice and can save you a lot of debugging`)â statoxâ¦
8 hours ago
You should try using only once
execute
call with a pipe |
to chain the commands like nnoremap <leader>a :execute "tabnew | vsplit"<CR>
. I didn't test it but I think your command should be map <Leader>ntd :execute "tabe! ". g:path ."l_todo.txt | vsplit! ".g:path ."u_todo.txt"<CR>
(Also use nore
and a mode in your map
command i.e. nnoremap
, this is a good practice and can save you a lot of debugging`)â statoxâ¦
8 hours ago
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
4
down vote
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 toexecute()
- 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
)
1
With your refactoring, I believe changing g:path mid-session wont be reflected in the mapping. Id make first and second functions instead.
â D. Ben Knoble
4 hours ago
1
@D.BenKnoble You're perfectly right, I guess one could also use:h getcwd()
instead ofg:path
depending on what the variable is meant to contain.
â statoxâ¦
4 hours ago
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
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 toexecute()
- 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
)
1
With your refactoring, I believe changing g:path mid-session wont be reflected in the mapping. Id make first and second functions instead.
â D. Ben Knoble
4 hours ago
1
@D.BenKnoble You're perfectly right, I guess one could also use:h getcwd()
instead ofg:path
depending on what the variable is meant to contain.
â statoxâ¦
4 hours ago
add a comment |Â
up vote
4
down vote
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 toexecute()
- 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
)
1
With your refactoring, I believe changing g:path mid-session wont be reflected in the mapping. Id make first and second functions instead.
â D. Ben Knoble
4 hours ago
1
@D.BenKnoble You're perfectly right, I guess one could also use:h getcwd()
instead ofg:path
depending on what the variable is meant to contain.
â statoxâ¦
4 hours ago
add a comment |Â
up vote
4
down vote
up vote
4
down vote
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 toexecute()
- 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
)
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 toexecute()
- 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
)
edited 3 hours ago
answered 5 hours ago
statoxâ¦
24.4k660125
24.4k660125
1
With your refactoring, I believe changing g:path mid-session wont be reflected in the mapping. Id make first and second functions instead.
â D. Ben Knoble
4 hours ago
1
@D.BenKnoble You're perfectly right, I guess one could also use:h getcwd()
instead ofg:path
depending on what the variable is meant to contain.
â statoxâ¦
4 hours ago
add a comment |Â
1
With your refactoring, I believe changing g:path mid-session wont be reflected in the mapping. Id make first and second functions instead.
â D. Ben Knoble
4 hours ago
1
@D.BenKnoble You're perfectly right, I guess one could also use:h getcwd()
instead ofg:path
depending on what the variable is meant to contain.
â statoxâ¦
4 hours ago
1
1
With your refactoring, I believe changing g:path mid-session wont be reflected in the mapping. Id make first and second functions instead.
â D. Ben Knoble
4 hours ago
With your refactoring, I believe changing g:path mid-session wont be reflected in the mapping. Id make first and second functions instead.
â D. Ben Knoble
4 hours ago
1
1
@D.BenKnoble You're perfectly right, I guess one could also use
:h getcwd()
instead of g:path
depending on what the variable is meant to contain.â statoxâ¦
4 hours ago
@D.BenKnoble You're perfectly right, I guess one could also use
:h getcwd()
instead of g:path
depending on what the variable is meant to contain.â statoxâ¦
4 hours ago
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fvi.stackexchange.com%2fquestions%2f17477%2fremaping-leader-with-execute-cannot-run-two-commands-at-once%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
2
You should try using only once
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`)â statoxâ¦
8 hours ago