As far as I know, Vim has no history extension.
Naturally, we need to use the tools that Vim gives us on the command line. And we have options!
<Up> arrow filtering- Command Line Editing Commands
CTRL-W to delete the word back<Left> and <Right> to move, CTRL-B and CTRL-E to go to the beginning / end of the line
- Use the
q: command line window (or CTRL-F when already on the command line) for maximum editing power - Find idiomatic alternative Vim solutions for a specific problem
- Automatically expanded tokens, such as
% and # , are a good example.
However , if you really want a Bash-style history extension, you can pretty easily hack something along with the <expr> command line abbreviations (at least for simpler cases).
Elements of the story extension that I use most often (frankly not very often):
!! , the most recent command line!-2 , the second most recent command line!* , all arguments, but the first of the previous command line!$ , last argument of the previous command line
Here you can implement them as paragraph abbreviations:
cnoreabbr <expr> !! getcmdtype() == ':' ? @: : '!*' cnoreabbr <expr> !-2 getcmdtype() == ':' ? histget(':', -2) : '!-2' cnoreabbr <expr> !* getcmdtype() == ':' ? join(split(@:,'\s\+')[1:], ' ') : '!*' cnoreabbr <expr> !$ getcmdtype() == ':' ? split(@:,'\s\+')[-1] : '!$'
And this is how your example will work in Vim:
:echo "Hello Stackoverflow" Hello Stackoverflow :echo "I'm posting on !$<Enter> I'm posting on Stackoverflow
Of course, use functions for more complex expressions if you really decide to go this route.
glts
source share