How to edit an existing key mapping in vim?

1.6k Views Asked by At

How do I edit an existing mapping in vim? I set the mapping in my .vim file using one of the standard mapping commands:

map ^A o]]></code>^M<GRD minus="" summary="">^M^M<p></p>^M^M</GRD>^M^M<code><![CDATA[0kkkkkk5ehi

I want to edit this long command to use "matlab" instead of code, e.g.:

map ^A o]]></matlab>^M<GRD minus="" summary="">^M^M<p></p>^M^M</GRD>^M^M<matlab><![CDATA[0kkkkkk5ehi

However, I don't want to edit the .vim file -- I will use the original mapping again. I just want to change the mapping for my current session. I tried :map ^A, but this only displays the current mapping, and I cannot copy the displayed text.

P.S. Note that the ^M and ^A characters are inserted with Ctrl-Q Ctrl-M, etc.

2

There are 2 best solutions below

3
On BEST ANSWER

Tweaking a mapping for a current session only is unusual; probably that's why it's supported poorly. I would guess that you're not actually concerned about a session, but rather a Matlab filetype. For that, there's excellent support. If the 'filetype' is detected as matlab, you can put a buffer-local mapping variant in ~/.vim/after/ftplugin/matlab.vim:

map <buffer> ^A ...

Direct editing

If you'd rather stick with your original plan, I would do it like that:

  1. Open configuration: :split ~/.vimrc
  2. Edit the mapping in-place
  3. Yank the line: yy
  4. Execute to activate for the current session: :@"
  5. Abort the edit without saving: :bdelete!

Alternative

For a more general solution, you could also capture the output of the original :map ^A command via :redir, then :put that into a :newscratch buffer, and finally :source that. It's more manual steps and typing, but could be automated by a custom command. Worthwhile if you need this often.

1
On

To set your map for the current session only, do

:map ^A o]]></matlab>^M<GRD minus="" summary="">^M^M<p></p>^M^M</GRD>^M^M<matlab><![CDATA[0kkkkkk5ehi