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?


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 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 '19 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 '19 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 '19 at 11:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.