As the title stated, remap ':' to maintain last command, and erase all char if any key other than
<CR> was pressed.
possible use cases:
- I have typed a long command, and I may or may not modified it, then re-run it.
- I save a lot, so I want type
:, then visually verify
:wis there, then type
<CR>to proceed. -- I have remapped
things that are not what I pursue:
- I know about
<C-f>in cmdline mode to open the mini buffer to edit command.
- I know type
@@to repeat command.
- I know type
<Up>in cmdline mode.
a little more on motivation:
register/macro is great and is really handy for some task.
But here I want a more consistent and safer (visually verification/feedback) way to re-run last command, with fewer key stroke.
Is that possible? or not trivially implementable at all??
======== EDIT ========
Based on @Karl's comment, I think the problem could be implemented via a function definition and a
nnoremap. The function consist three parts:
echo last command
getreg(':'), then get
char == '^M', re-execute last command.
otherwise, open command line and act accordingly.
My first attempt is as below: -- (based on @grodzik's answer and @Karl's idea in the comment)
func! Show_last_command_and_exec() echo ':'.getreg(':') try let char = getchar() catch /^Vim:Interrupt$/ let char = "\<Esc>" endtry if char == "^M" exec getreg(':') " not work, don't know why, tried with previous comand be `:pwd` else " not work, don't know which function or command should be used. " below are failed attempt. " normal! : " call feedkeys(char) " exec ':'.char endif endfunc nnore : :call Show_last_command_and_exec()<CR>
But unfortunately, except the trivial first echo part, neither work yet. I post my attempt (though failed currently) here, hope someone interested may implement a better one that work nicely.
P.S. as @grodzik said in his answer, the "^M" should be replaced with real