Reman
Reman

Reputation: 8109

Repeat a Command invoked from Menu

I created many menu commands in VIM.

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

Is there a way to repeat the last command invoked from vim's menu?

Update:

example menu command:

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

If I use this Menu Command created by myself, how can I repeat it again (repeat last used menu command)?
In above case it would be :call <SID>Test("%")<CR>
I can't find these commands in command line history.
@: and :<UP> doesn't work

Does anyone know where Vim saves function calls/menu commands actions?

Update2

Kent proposed to build a function around the above 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 disadvantage is that I have to change all current commands ;)

Upvotes: 4

Views: 354

Answers (2)

Kent
Kent

Reputation: 195039

If there is no built-in support, you have to build one on your own, if it is so important to you. Basic idea is:

You create a function, like ExecMenuCmd(cmd) the argument is the command, like wq, in the function, you save the command into a variable, then execute it.

Then you can create mapping to "repeat" last menu cmd by reading the variable and execute.

When you create menu items, you do something like:

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

If you like, you could maintain a stack to store the commands triggered by menu, to implement more features.

Upvotes: 3

gnit
gnit

Reputation: 1

You could make a mapping in your .vimrc for entering the command mode, and then running the last command. Something like:

noremap <F8> :<Up><Cr>

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

Upvotes: 0

Related Questions