Repeat the menu command

I have created many menu commands in VIM.

. repeats the last command in normal mode.
@: repeats the last command from the command line

Is there a way to repeat the last command called from the vim menu ?

Update:

Example menu command:

 an 98.80.00 &MyMenu.Test\ :call <SID>Test("%")<CR> 

If I use this menu command that I created, how can I repeat it again (repeat the last used menu command)?
In the above case, it would be :call <SID>Test("%")<CR>
I can not find these commands in the command line history.
@: and :<UP> does not work

Does anyone know where Vim functions as function calls / menu commands?

Update2

Kent suggested constructing a function around the specified command:

 an 98.80.00 &MyMenu.Test\ :call SubExe('call <SID>Test("%")')<CR> function! SubExe(argument) let g:lastcommand = a:argument exe g:lastcommand endfun 

It seems to work, the downside is that I have to change all current commands;)

+4
source share
2 answers

If there is no built-in support, you must create it yourself if this is so important to you. Main idea:

You create a function, for example ExecMenuCmd(cmd) argument - this is a command, for example wq , in a function, you save the command in a variable and then execute it.

Then you can create a mapping to β€œrepeat” the last cmd menu by reading the variable and executing it.

When you create menu items, you do something like:

 :menu File.SaveAndExit :call ExecMenuCmd('wq') 

If you like, you can support the stack for storing commands launched by menus, to implement additional functions.

+3
source

You can do the mapping in your .vimrc to enter command mode, and then run the last command. Sort of:

 noremap <F8> :<Up><Cr> 

This will repeat the last thing you ran from command mode whenever you press F8 in normal mode. You can change the F8 to whatever you want.

0
source

Source: https://habr.com/ru/post/1343988/


All Articles