Is there a way to effectively combine :w
and :e
commands so that the current file is saved and a new one is opened for editing in one go? And to do so in a way that allows tab completion of path and filename on the command line?
You can use command
to add new commands. These have to start with a capital letter.
Something like this should do what you want:
command! -nargs=1 -complete=file WE write | edit <args>
You can then do:
:WE new-file
-nargs=1
- accept one argument-complete=file
- do file completionWE
- the command namewrite | edit <args>
- first call:w
, and then:e
with the argument we gave it.
Note that there's also the autowrite
option:
Write the contents of the file, if it has been modified, on each
:next
,:rewind
,:last
,:first
,:previous
,:stop
,:suspend
,:tag
,:!
,:make
,CTRL-]
andCTRL-^
command; and when a:buffer
,CTRL-O
,CTRL-I
,'{A-Z0-9}
, or`{A-Z0-9}
command takes one to another file.
and the autowriteall
option:
Like
'autowrite'
, but also used for commands:edit
,:enew
,:quit
,:qall
,:exit
,:xit
,:recover
and closing the Vim window. Setting this option also implies that Vim behaves like'autowrite'
has been set.