Reputation: 119
My context:
I frequently take notes in VIM. I'd like a VIM function to type a standard-header into the command line (specifically, a timestamp such as :sav 20180418_
) without executing; control would return with VIM still in command-mode (so that user could append remainder of the filename and execute).
My fundamental difficulty: I cannot seem to get a Vim function/macro to enter command-mode, supply text to the command line, then exit while staying in command-mode and not executing the text supplied.
Is this possible?
Thank you.
Upvotes: 2
Views: 274
Reputation: 7627
You can use expand()
function. For example if you are currently editing file 20180418_.txt
you can type:
:sav <c-r>=expand("%:r")<cr>
where <c-r>=
should be typed as Ctrl+R followed by =. Enter key is <cr>
. This will expand the text in the command line into:
:sav 20180418_
Upvotes: 3