Mapping snippets for Vim
I'm struggling with setting up some mappings for Vim. I want to have a mapping to insert a line of text.
I've achieved this:
nnoremap åfox oThe quick brown fox jumps over the lazy dog<Esc>]<Space>j
It works fine, except for the last part.
]<Space>
is mapped to create a new line without entering insert mode, and then the j goes one line down. This mapping comes from the vim unimpaired plugin.
The command ]<Space>
works fine in the normal vim editor, when I do all step by step.
When I do it as a macro, I get problems when inserting the bracket after exiting insert mode, so I have to do the same command again.
Here is how the macro is recorded. Note that I press the exact same combination twice, (ALT + 9), which is ]
on my Swedish keyboard.
Are there any safer way to achieve this?
vim vim-plugins
add a comment |
I'm struggling with setting up some mappings for Vim. I want to have a mapping to insert a line of text.
I've achieved this:
nnoremap åfox oThe quick brown fox jumps over the lazy dog<Esc>]<Space>j
It works fine, except for the last part.
]<Space>
is mapped to create a new line without entering insert mode, and then the j goes one line down. This mapping comes from the vim unimpaired plugin.
The command ]<Space>
works fine in the normal vim editor, when I do all step by step.
When I do it as a macro, I get problems when inserting the bracket after exiting insert mode, so I have to do the same command again.
Here is how the macro is recorded. Note that I press the exact same combination twice, (ALT + 9), which is ]
on my Swedish keyboard.
Are there any safer way to achieve this?
vim vim-plugins
add a comment |
I'm struggling with setting up some mappings for Vim. I want to have a mapping to insert a line of text.
I've achieved this:
nnoremap åfox oThe quick brown fox jumps over the lazy dog<Esc>]<Space>j
It works fine, except for the last part.
]<Space>
is mapped to create a new line without entering insert mode, and then the j goes one line down. This mapping comes from the vim unimpaired plugin.
The command ]<Space>
works fine in the normal vim editor, when I do all step by step.
When I do it as a macro, I get problems when inserting the bracket after exiting insert mode, so I have to do the same command again.
Here is how the macro is recorded. Note that I press the exact same combination twice, (ALT + 9), which is ]
on my Swedish keyboard.
Are there any safer way to achieve this?
vim vim-plugins
I'm struggling with setting up some mappings for Vim. I want to have a mapping to insert a line of text.
I've achieved this:
nnoremap åfox oThe quick brown fox jumps over the lazy dog<Esc>]<Space>j
It works fine, except for the last part.
]<Space>
is mapped to create a new line without entering insert mode, and then the j goes one line down. This mapping comes from the vim unimpaired plugin.
The command ]<Space>
works fine in the normal vim editor, when I do all step by step.
When I do it as a macro, I get problems when inserting the bracket after exiting insert mode, so I have to do the same command again.
Here is how the macro is recorded. Note that I press the exact same combination twice, (ALT + 9), which is ]
on my Swedish keyboard.
Are there any safer way to achieve this?
vim vim-plugins
vim vim-plugins
edited Jan 17 at 13:36
TDK
34513
34513
asked Jan 17 at 11:42
MaxMax
478
478
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Though the recommendation is to use :noremap
, because it makes the mapping immune to remapping and recursion, here this is hurting you.
In order to execute unimpaired's ]<Space>
mapping, you have to use :nmap
here (at least for the trailing part, but breaking this mapping up would just complicate things a lot, and there's little risk as the rest of the mapping just uses alphabetic letters and the standard <Esc>
and j
commands).
It's up to you whether you use unimpaired's ]Space
default mapping or rather the internal <Plug>unimpairedBlankDown
target; the latter would allow to change the plugin mapping without having to adapt this mapping, too.
Didn't know that, I ended up solving it naively with the following snippetnnoremap åfox OThe quick brown fox jumps over the lazy dog.<CR>The lazy dog was jumped over by the quick brown fox.<Esc>kk
. Seems clearer.
– Max
Jan 21 at 11:20
I agree. In this particular case, the functionality provided by the plugin is so insignificant (and its main benefit is in the shorter and easier typing, which doesn't apply to a mapping) that using built-in commands is indeed better.
– Ingo Karkat
Jan 21 at 11:27
As my question addresses the general case (and core problem), please accept the answer by clicking on the outlined checkmark. This way, the question is marked as closed, and you increase your chances of getting answers to future questions, as this shows that you care about the answers.
– Ingo Karkat
Jan 21 at 11:28
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
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: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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
});
}
});
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%2fsuperuser.com%2fquestions%2f1395339%2fmapping-snippets-for-vim%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Though the recommendation is to use :noremap
, because it makes the mapping immune to remapping and recursion, here this is hurting you.
In order to execute unimpaired's ]<Space>
mapping, you have to use :nmap
here (at least for the trailing part, but breaking this mapping up would just complicate things a lot, and there's little risk as the rest of the mapping just uses alphabetic letters and the standard <Esc>
and j
commands).
It's up to you whether you use unimpaired's ]Space
default mapping or rather the internal <Plug>unimpairedBlankDown
target; the latter would allow to change the plugin mapping without having to adapt this mapping, too.
Didn't know that, I ended up solving it naively with the following snippetnnoremap åfox OThe quick brown fox jumps over the lazy dog.<CR>The lazy dog was jumped over by the quick brown fox.<Esc>kk
. Seems clearer.
– Max
Jan 21 at 11:20
I agree. In this particular case, the functionality provided by the plugin is so insignificant (and its main benefit is in the shorter and easier typing, which doesn't apply to a mapping) that using built-in commands is indeed better.
– Ingo Karkat
Jan 21 at 11:27
As my question addresses the general case (and core problem), please accept the answer by clicking on the outlined checkmark. This way, the question is marked as closed, and you increase your chances of getting answers to future questions, as this shows that you care about the answers.
– Ingo Karkat
Jan 21 at 11:28
add a comment |
Though the recommendation is to use :noremap
, because it makes the mapping immune to remapping and recursion, here this is hurting you.
In order to execute unimpaired's ]<Space>
mapping, you have to use :nmap
here (at least for the trailing part, but breaking this mapping up would just complicate things a lot, and there's little risk as the rest of the mapping just uses alphabetic letters and the standard <Esc>
and j
commands).
It's up to you whether you use unimpaired's ]Space
default mapping or rather the internal <Plug>unimpairedBlankDown
target; the latter would allow to change the plugin mapping without having to adapt this mapping, too.
Didn't know that, I ended up solving it naively with the following snippetnnoremap åfox OThe quick brown fox jumps over the lazy dog.<CR>The lazy dog was jumped over by the quick brown fox.<Esc>kk
. Seems clearer.
– Max
Jan 21 at 11:20
I agree. In this particular case, the functionality provided by the plugin is so insignificant (and its main benefit is in the shorter and easier typing, which doesn't apply to a mapping) that using built-in commands is indeed better.
– Ingo Karkat
Jan 21 at 11:27
As my question addresses the general case (and core problem), please accept the answer by clicking on the outlined checkmark. This way, the question is marked as closed, and you increase your chances of getting answers to future questions, as this shows that you care about the answers.
– Ingo Karkat
Jan 21 at 11:28
add a comment |
Though the recommendation is to use :noremap
, because it makes the mapping immune to remapping and recursion, here this is hurting you.
In order to execute unimpaired's ]<Space>
mapping, you have to use :nmap
here (at least for the trailing part, but breaking this mapping up would just complicate things a lot, and there's little risk as the rest of the mapping just uses alphabetic letters and the standard <Esc>
and j
commands).
It's up to you whether you use unimpaired's ]Space
default mapping or rather the internal <Plug>unimpairedBlankDown
target; the latter would allow to change the plugin mapping without having to adapt this mapping, too.
Though the recommendation is to use :noremap
, because it makes the mapping immune to remapping and recursion, here this is hurting you.
In order to execute unimpaired's ]<Space>
mapping, you have to use :nmap
here (at least for the trailing part, but breaking this mapping up would just complicate things a lot, and there's little risk as the rest of the mapping just uses alphabetic letters and the standard <Esc>
and j
commands).
It's up to you whether you use unimpaired's ]Space
default mapping or rather the internal <Plug>unimpairedBlankDown
target; the latter would allow to change the plugin mapping without having to adapt this mapping, too.
answered Jan 18 at 14:37
Ingo KarkatIngo Karkat
17.7k22545
17.7k22545
Didn't know that, I ended up solving it naively with the following snippetnnoremap åfox OThe quick brown fox jumps over the lazy dog.<CR>The lazy dog was jumped over by the quick brown fox.<Esc>kk
. Seems clearer.
– Max
Jan 21 at 11:20
I agree. In this particular case, the functionality provided by the plugin is so insignificant (and its main benefit is in the shorter and easier typing, which doesn't apply to a mapping) that using built-in commands is indeed better.
– Ingo Karkat
Jan 21 at 11:27
As my question addresses the general case (and core problem), please accept the answer by clicking on the outlined checkmark. This way, the question is marked as closed, and you increase your chances of getting answers to future questions, as this shows that you care about the answers.
– Ingo Karkat
Jan 21 at 11:28
add a comment |
Didn't know that, I ended up solving it naively with the following snippetnnoremap åfox OThe quick brown fox jumps over the lazy dog.<CR>The lazy dog was jumped over by the quick brown fox.<Esc>kk
. Seems clearer.
– Max
Jan 21 at 11:20
I agree. In this particular case, the functionality provided by the plugin is so insignificant (and its main benefit is in the shorter and easier typing, which doesn't apply to a mapping) that using built-in commands is indeed better.
– Ingo Karkat
Jan 21 at 11:27
As my question addresses the general case (and core problem), please accept the answer by clicking on the outlined checkmark. This way, the question is marked as closed, and you increase your chances of getting answers to future questions, as this shows that you care about the answers.
– Ingo Karkat
Jan 21 at 11:28
Didn't know that, I ended up solving it naively with the following snippet
nnoremap åfox OThe quick brown fox jumps over the lazy dog.<CR>The lazy dog was jumped over by the quick brown fox.<Esc>kk
. Seems clearer.– Max
Jan 21 at 11:20
Didn't know that, I ended up solving it naively with the following snippet
nnoremap åfox OThe quick brown fox jumps over the lazy dog.<CR>The lazy dog was jumped over by the quick brown fox.<Esc>kk
. Seems clearer.– Max
Jan 21 at 11:20
I agree. In this particular case, the functionality provided by the plugin is so insignificant (and its main benefit is in the shorter and easier typing, which doesn't apply to a mapping) that using built-in commands is indeed better.
– Ingo Karkat
Jan 21 at 11:27
I agree. In this particular case, the functionality provided by the plugin is so insignificant (and its main benefit is in the shorter and easier typing, which doesn't apply to a mapping) that using built-in commands is indeed better.
– Ingo Karkat
Jan 21 at 11:27
As my question addresses the general case (and core problem), please accept the answer by clicking on the outlined checkmark. This way, the question is marked as closed, and you increase your chances of getting answers to future questions, as this shows that you care about the answers.
– Ingo Karkat
Jan 21 at 11:28
As my question addresses the general case (and core problem), please accept the answer by clicking on the outlined checkmark. This way, the question is marked as closed, and you increase your chances of getting answers to future questions, as this shows that you care about the answers.
– Ingo Karkat
Jan 21 at 11:28
add a comment |
Thanks for contributing an answer to Super User!
- 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%2fsuperuser.com%2fquestions%2f1395339%2fmapping-snippets-for-vim%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