How to remap repeating commands i.e. ?How can I start vim and then execute a particular command that includes a , from the command line?Key mapping that will invoke the wildmenuSticky shift - or getting <shift> with letter combinationsHow to find out what a key is mapped to?How to remember the most basic commandsColon remap not working for registers(?)How to remap <C-W>hjkl to navigate tmux panes and vim splitsFactoring out commands in vimrc?Getting Shift-Tab to work in VIM Insert modeHow to get the number used before a command as an argument?
Was Mohammed the most popular first name for boys born in Berlin in 2018?
Whose birthyears are canonically established in the MCU?
When was it publicly revealed that a KH-11 spy satellite took pictures of the first Shuttle flight?
How can I test a shell script in a "safe environment" to avoid harm to my computer?
Opposite party turned away from voting when ballot is all opposing party
Why doesn't a particle exert force on itself?
Is the tensor product (of vector spaces) commutative?
Employee is self-centered and affects the team negatively
What will Doctor Strange protect now?
Two (probably) equal real numbers which are not proved to be equal?
Is your maximum jump distance halved by grappling?
As a small race with a heavy weapon, does enlage remove the disadvantage?
Capturing the entire webpage with WebExecute's CaptureImage
Cyclic queue using an array in C#
Exactly which act of bravery are Luke and Han awarded a medal for?
How can one see if an address is multisig?
Sed operations are not working or might i am doing it wrong?
How do I minimise waste on a flight?
Align a table column at a specific symbol
Is there an application which does HTTP PUT?
Why doesn't Dany protect her dragons better?
How can it be that ssh somename works, while nslookup somename does not?
Would the rotation of the starfield from a ring station be too disorienting?
Can I bring back Planetary Romance as a genre?
How to remap repeating commands i.e. ?
How can I start vim and then execute a particular command that includes a , from the command line?Key mapping that will invoke the wildmenuSticky shift - or getting <shift> with letter combinationsHow to find out what a key is mapped to?How to remember the most basic commandsColon remap not working for registers(?)How to remap <C-W>hjkl to navigate tmux panes and vim splitsFactoring out commands in vimrc?Getting Shift-Tab to work in VIM Insert modeHow to get the number used before a command as an argument?
By default, vim lets you type 5G (5 then shift + g) to go to line 5. Instead, I don't want to have to press the shift key. Pressing <S-g>
does something different than just 5<S-g>
. How can I remap a command that takes a number for repeated executions?
Something like: nnoremap <number>g <number>G
key-bindings normal-mode
New contributor
add a comment |
By default, vim lets you type 5G (5 then shift + g) to go to line 5. Instead, I don't want to have to press the shift key. Pressing <S-g>
does something different than just 5<S-g>
. How can I remap a command that takes a number for repeated executions?
Something like: nnoremap <number>g <number>G
key-bindings normal-mode
New contributor
add a comment |
By default, vim lets you type 5G (5 then shift + g) to go to line 5. Instead, I don't want to have to press the shift key. Pressing <S-g>
does something different than just 5<S-g>
. How can I remap a command that takes a number for repeated executions?
Something like: nnoremap <number>g <number>G
key-bindings normal-mode
New contributor
By default, vim lets you type 5G (5 then shift + g) to go to line 5. Instead, I don't want to have to press the shift key. Pressing <S-g>
does something different than just 5<S-g>
. How can I remap a command that takes a number for repeated executions?
Something like: nnoremap <number>g <number>G
key-bindings normal-mode
key-bindings normal-mode
New contributor
New contributor
New contributor
asked May 4 at 19:11
DJTripleThreatDJTripleThreat
1134
1134
New contributor
New contributor
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
nnoremap g G
But this will not work well, as there are a lot of key mapping beginning with g
. So Vim has to wait a timeout (default 1000 msec) to be sure that no other key is pressed after the g
. The g
could be the start of 'gg' or 'g$' or ...
So after you pressed 5g
nothing will happen for one second. Than the cursor jumps to line 5.
If you want to know about the other key mappings starting with 'g' just enter ':help g' and then hit <tab>
. Lots of stuff.
Thanks for this. I realized soon after remapping g was a bad idea haha! Ill check out the help text for that command.
– DJTripleThreat
May 4 at 23:14
add a comment |
Even though OP accepted the existing answer this feels incomplete to me.
First, the answer has a well-considered warning about remapping g
but there
is no mention of <count>gg
as a near-synonym for <count>G
. (They differ only when the count is omitted. By default gg
goes to the first line and G
to the last.). Perhaps entering 5gg is less annoying to OP than 5 Shift+G and we have a nice, easy workaround...
The other thing that feels unaddressed is the subject of the question which is notably more generic than what has actually been discussed. It happens to be a good question, about applying a repeat count to a mapped command, but folks who come here from google will have to keep looking if it's not answered. So...
From Normal mode, if one precedes a command with a count and that command enters a vimscript/ex context we can retrieve the count from that context with the built-in variable v:count
.
I'll use it in an example applicable to the more specific question we've been addressing...
nnoremap XX :<C-U>exe 'norm! ' . v:count . 'G'<CR>
In place of XX
choose any key or keys you like better than Shift+G and this will
give you a replacement for <count>G
.
FYI about the use of <C-U>
(see :h c_CTRL-U
): this is required to clear the command line before the mapped command is applied. Normally when we enter a number followed by :
the command line is pre-populated with a line range. In this case we don't want that.
1
Nice to know<count>gg
. You might need to explain<c-u>
, some user might consider it as a mistake, they don't know :h N: . You command also need a trailing<cr>
.
– dedowsdi
2 days ago
@dedowsdi Thanks for the heads up about the<cr>
that I left off. And you're right about explaining<c-u>
...I was being lazy and planned to fill it out later. :)
– B Layer
2 days ago
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "599"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
DJTripleThreat is a new contributor. Be nice, and check out our Code of Conduct.
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fvi.stackexchange.com%2fquestions%2f19841%2fhow-to-remap-repeating-commands-i-e-numbercommand%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
nnoremap g G
But this will not work well, as there are a lot of key mapping beginning with g
. So Vim has to wait a timeout (default 1000 msec) to be sure that no other key is pressed after the g
. The g
could be the start of 'gg' or 'g$' or ...
So after you pressed 5g
nothing will happen for one second. Than the cursor jumps to line 5.
If you want to know about the other key mappings starting with 'g' just enter ':help g' and then hit <tab>
. Lots of stuff.
Thanks for this. I realized soon after remapping g was a bad idea haha! Ill check out the help text for that command.
– DJTripleThreat
May 4 at 23:14
add a comment |
nnoremap g G
But this will not work well, as there are a lot of key mapping beginning with g
. So Vim has to wait a timeout (default 1000 msec) to be sure that no other key is pressed after the g
. The g
could be the start of 'gg' or 'g$' or ...
So after you pressed 5g
nothing will happen for one second. Than the cursor jumps to line 5.
If you want to know about the other key mappings starting with 'g' just enter ':help g' and then hit <tab>
. Lots of stuff.
Thanks for this. I realized soon after remapping g was a bad idea haha! Ill check out the help text for that command.
– DJTripleThreat
May 4 at 23:14
add a comment |
nnoremap g G
But this will not work well, as there are a lot of key mapping beginning with g
. So Vim has to wait a timeout (default 1000 msec) to be sure that no other key is pressed after the g
. The g
could be the start of 'gg' or 'g$' or ...
So after you pressed 5g
nothing will happen for one second. Than the cursor jumps to line 5.
If you want to know about the other key mappings starting with 'g' just enter ':help g' and then hit <tab>
. Lots of stuff.
nnoremap g G
But this will not work well, as there are a lot of key mapping beginning with g
. So Vim has to wait a timeout (default 1000 msec) to be sure that no other key is pressed after the g
. The g
could be the start of 'gg' or 'g$' or ...
So after you pressed 5g
nothing will happen for one second. Than the cursor jumps to line 5.
If you want to know about the other key mappings starting with 'g' just enter ':help g' and then hit <tab>
. Lots of stuff.
answered May 4 at 19:57
RalfRalf
3,9651319
3,9651319
Thanks for this. I realized soon after remapping g was a bad idea haha! Ill check out the help text for that command.
– DJTripleThreat
May 4 at 23:14
add a comment |
Thanks for this. I realized soon after remapping g was a bad idea haha! Ill check out the help text for that command.
– DJTripleThreat
May 4 at 23:14
Thanks for this. I realized soon after remapping g was a bad idea haha! Ill check out the help text for that command.
– DJTripleThreat
May 4 at 23:14
Thanks for this. I realized soon after remapping g was a bad idea haha! Ill check out the help text for that command.
– DJTripleThreat
May 4 at 23:14
add a comment |
Even though OP accepted the existing answer this feels incomplete to me.
First, the answer has a well-considered warning about remapping g
but there
is no mention of <count>gg
as a near-synonym for <count>G
. (They differ only when the count is omitted. By default gg
goes to the first line and G
to the last.). Perhaps entering 5gg is less annoying to OP than 5 Shift+G and we have a nice, easy workaround...
The other thing that feels unaddressed is the subject of the question which is notably more generic than what has actually been discussed. It happens to be a good question, about applying a repeat count to a mapped command, but folks who come here from google will have to keep looking if it's not answered. So...
From Normal mode, if one precedes a command with a count and that command enters a vimscript/ex context we can retrieve the count from that context with the built-in variable v:count
.
I'll use it in an example applicable to the more specific question we've been addressing...
nnoremap XX :<C-U>exe 'norm! ' . v:count . 'G'<CR>
In place of XX
choose any key or keys you like better than Shift+G and this will
give you a replacement for <count>G
.
FYI about the use of <C-U>
(see :h c_CTRL-U
): this is required to clear the command line before the mapped command is applied. Normally when we enter a number followed by :
the command line is pre-populated with a line range. In this case we don't want that.
1
Nice to know<count>gg
. You might need to explain<c-u>
, some user might consider it as a mistake, they don't know :h N: . You command also need a trailing<cr>
.
– dedowsdi
2 days ago
@dedowsdi Thanks for the heads up about the<cr>
that I left off. And you're right about explaining<c-u>
...I was being lazy and planned to fill it out later. :)
– B Layer
2 days ago
add a comment |
Even though OP accepted the existing answer this feels incomplete to me.
First, the answer has a well-considered warning about remapping g
but there
is no mention of <count>gg
as a near-synonym for <count>G
. (They differ only when the count is omitted. By default gg
goes to the first line and G
to the last.). Perhaps entering 5gg is less annoying to OP than 5 Shift+G and we have a nice, easy workaround...
The other thing that feels unaddressed is the subject of the question which is notably more generic than what has actually been discussed. It happens to be a good question, about applying a repeat count to a mapped command, but folks who come here from google will have to keep looking if it's not answered. So...
From Normal mode, if one precedes a command with a count and that command enters a vimscript/ex context we can retrieve the count from that context with the built-in variable v:count
.
I'll use it in an example applicable to the more specific question we've been addressing...
nnoremap XX :<C-U>exe 'norm! ' . v:count . 'G'<CR>
In place of XX
choose any key or keys you like better than Shift+G and this will
give you a replacement for <count>G
.
FYI about the use of <C-U>
(see :h c_CTRL-U
): this is required to clear the command line before the mapped command is applied. Normally when we enter a number followed by :
the command line is pre-populated with a line range. In this case we don't want that.
1
Nice to know<count>gg
. You might need to explain<c-u>
, some user might consider it as a mistake, they don't know :h N: . You command also need a trailing<cr>
.
– dedowsdi
2 days ago
@dedowsdi Thanks for the heads up about the<cr>
that I left off. And you're right about explaining<c-u>
...I was being lazy and planned to fill it out later. :)
– B Layer
2 days ago
add a comment |
Even though OP accepted the existing answer this feels incomplete to me.
First, the answer has a well-considered warning about remapping g
but there
is no mention of <count>gg
as a near-synonym for <count>G
. (They differ only when the count is omitted. By default gg
goes to the first line and G
to the last.). Perhaps entering 5gg is less annoying to OP than 5 Shift+G and we have a nice, easy workaround...
The other thing that feels unaddressed is the subject of the question which is notably more generic than what has actually been discussed. It happens to be a good question, about applying a repeat count to a mapped command, but folks who come here from google will have to keep looking if it's not answered. So...
From Normal mode, if one precedes a command with a count and that command enters a vimscript/ex context we can retrieve the count from that context with the built-in variable v:count
.
I'll use it in an example applicable to the more specific question we've been addressing...
nnoremap XX :<C-U>exe 'norm! ' . v:count . 'G'<CR>
In place of XX
choose any key or keys you like better than Shift+G and this will
give you a replacement for <count>G
.
FYI about the use of <C-U>
(see :h c_CTRL-U
): this is required to clear the command line before the mapped command is applied. Normally when we enter a number followed by :
the command line is pre-populated with a line range. In this case we don't want that.
Even though OP accepted the existing answer this feels incomplete to me.
First, the answer has a well-considered warning about remapping g
but there
is no mention of <count>gg
as a near-synonym for <count>G
. (They differ only when the count is omitted. By default gg
goes to the first line and G
to the last.). Perhaps entering 5gg is less annoying to OP than 5 Shift+G and we have a nice, easy workaround...
The other thing that feels unaddressed is the subject of the question which is notably more generic than what has actually been discussed. It happens to be a good question, about applying a repeat count to a mapped command, but folks who come here from google will have to keep looking if it's not answered. So...
From Normal mode, if one precedes a command with a count and that command enters a vimscript/ex context we can retrieve the count from that context with the built-in variable v:count
.
I'll use it in an example applicable to the more specific question we've been addressing...
nnoremap XX :<C-U>exe 'norm! ' . v:count . 'G'<CR>
In place of XX
choose any key or keys you like better than Shift+G and this will
give you a replacement for <count>G
.
FYI about the use of <C-U>
(see :h c_CTRL-U
): this is required to clear the command line before the mapped command is applied. Normally when we enter a number followed by :
the command line is pre-populated with a line range. In this case we don't want that.
edited 2 days ago
answered 2 days ago
B LayerB Layer
6,1221620
6,1221620
1
Nice to know<count>gg
. You might need to explain<c-u>
, some user might consider it as a mistake, they don't know :h N: . You command also need a trailing<cr>
.
– dedowsdi
2 days ago
@dedowsdi Thanks for the heads up about the<cr>
that I left off. And you're right about explaining<c-u>
...I was being lazy and planned to fill it out later. :)
– B Layer
2 days ago
add a comment |
1
Nice to know<count>gg
. You might need to explain<c-u>
, some user might consider it as a mistake, they don't know :h N: . You command also need a trailing<cr>
.
– dedowsdi
2 days ago
@dedowsdi Thanks for the heads up about the<cr>
that I left off. And you're right about explaining<c-u>
...I was being lazy and planned to fill it out later. :)
– B Layer
2 days ago
1
1
Nice to know
<count>gg
. You might need to explain <c-u>
, some user might consider it as a mistake, they don't know :h N: . You command also need a trailing <cr>
.– dedowsdi
2 days ago
Nice to know
<count>gg
. You might need to explain <c-u>
, some user might consider it as a mistake, they don't know :h N: . You command also need a trailing <cr>
.– dedowsdi
2 days ago
@dedowsdi Thanks for the heads up about the
<cr>
that I left off. And you're right about explaining <c-u>
...I was being lazy and planned to fill it out later. :)– B Layer
2 days ago
@dedowsdi Thanks for the heads up about the
<cr>
that I left off. And you're right about explaining <c-u>
...I was being lazy and planned to fill it out later. :)– B Layer
2 days ago
add a comment |
DJTripleThreat is a new contributor. Be nice, and check out our Code of Conduct.
DJTripleThreat is a new contributor. Be nice, and check out our Code of Conduct.
DJTripleThreat is a new contributor. Be nice, and check out our Code of Conduct.
DJTripleThreat is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Vi and Vim Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fvi.stackexchange.com%2fquestions%2f19841%2fhow-to-remap-repeating-commands-i-e-numbercommand%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown