3

I want to have a macro in my .vimrc which when activated will enter a command and execute it.

I want something like

let @r = ':e!' 

but instead of it just being entered in the command line I want it executed.

4

Your goal is to insert a literal ^M character. You have two options: You can use digraphs (:h digraphs), or the <C-v> shortcut (:h i_CTRL-v).

Digraphs

Digraphs are a way to enter hard-to-reach characters, like accented letters or special keys. If you look at the listing in :digraphs, you will see that CR is the shortcut you want.

To enter a digraph, press Ctrlk followed by the digraph letters. In this case, it would be Ctrlk - CR (note the uppercase, it's significant).

Ctrl-v

Typing Ctrlv will "insert next non-digit literally". You can either press Ctrlv - Ctrlm, or Ctrlv - Enter – both will result in ^M.

| improve this answer | |
2

Before ending ' sign, press combination CtrlV followed by Enter. This will insert Enter code represented by ^M sign, which will as you would have pressed Enter yourself.

You should get something like this:

let @r = ':e!^M' 
| improve this answer | |
  • if you are using gvim for Windows, you probably need to use c-w rather than c-v – Jim U Apr 27 '17 at 14:14
-1

<cr> (Carriage Return) inside a mapping or a command will expand to an Enter keystroke.

So your mapping then would be

let @r = ':e!<cr>'
| improve this answer | |
  • 1
    I would say that this won't work. It will, if you prefix < with a backslash \ and enclose whole expression in double quotes instead of single ones ' => " – grodzik Apr 28 '17 at 9:08

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.