DEV Community

Waylon Walker
Waylon Walker

Posted on β€’ Originally published at waylonwalker.com

3 1

Vim remaps use cmd in place of :

Anyone just starting out their vim customization journey is bound to run into this error.

E5520: <Cmd> mapping must end with <CR>
Enter fullscreen mode Exit fullscreen mode

I did not get it

I'll admit, in hindsight it's very clear what this is trying to tell me, but for whatever reason I still did not understand it and I just used a : everywhere.

From the docs

If you run :h <cmd> you will see a lot of reasons why you should do it, from performance, to hygene, to ergonomics. You will also see another clear statement about how to use <cmd>.

                                                          E5520
  <Cmd> commands must terminate, that is, they must be followed by <CR> in the
  {rhs} of the mapping definition.  Command-line mode is never entered.
Enter fullscreen mode Exit fullscreen mode

When to map with a :

You still need to map your remaps with a : if you do not close it with a
<cr>. This might be something like prefilling a command with a search term.

nnoremap <leader><leader>f :s/search/
Enter fullscreen mode Exit fullscreen mode

Otherwise use

If you can close the <cmd> with a <cr> the command do so. Your map will automatically be silent, more ergonomic, performant, and all that good stuff.

nnoremap <leader><leader>f <cmd>s/search/Search/g<cr>
Enter fullscreen mode Exit fullscreen mode

AWS GenAI LIVE image

Real challenges. Real solutions. Real talk.

From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.

Learn more

Top comments (0)

Sentry image

See why 4M developers consider Sentry, β€œnot bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay