Reputation: 89053
I'm doing some debugging, which involves checking logfiles name "blah N.log" where N is an integer. Periodically, a new log file gets added, and I'd like to just skip to the next log file, rather than explicitly do :e blah\ N.log
. I can't just do % vim *.log
and then :n
, b/c not all the log files exist yet.
I've got an expression that yields the next logfile name:
:echo substitute(expand('%'), ' \zs\d\+', \=submatch(0) + 1', '')
But I can't figure out how to pass the result of that expression to an :e
command. Any tips?
Upvotes: 1
Views: 308
Reputation: 89053
Yet another way: :e <CTRL-R>=
brings up the expression prompt. Enter the appropriate expression (including using up for expression history), and then hit <Enter>
to substitute the value in the original prompt.
This makes the keystrokes:
:e <CTRL-R>=<Up><Enter><Enter>
Which is not as few as just :<Up><Enter>
to redo my :exec
command, but a useful trick, nonetheless.
Upvotes: 1
Reputation: 3380
Or you can wrap it in a function. I would do the following:
function! GetNextLogfile()
"" store expression in a
"" let a=...
return a
endfunction
then
:execute "edit " GetNextLogfile()
You might want a mapping or abbreviation.
Upvotes: 2
Reputation: 89053
Here's a way to do it - though I hope there's a more elegant way.
:execute ':e ' . substitute(substitute(expand('%'), ' \zs\d\+', \=submatch(0) + 1', ''), ' ', '\\ ', '')
I have to add a second substitute()
command to escape the space in the filename.
Upvotes: 2