I want to return to insert mode after writing (see: else)
function! SaveOrSaveAsInInsert()
if @% == ""
:browse saveas
else
:w
"//TODO: Return to insert mode
endif
endfunction
Tried with :w<CR>a but does not work.
Thanks!
Edit
@Randy Morris, commented using startinsert which works. On the other hand :h inserting-ex says:
NOTE: These commands cannot be used
with |:global| or |:vglobal|.
“:append” and “:insert” don’t work
properly in between “:if” and
“:endif”, “:for” and “:endfor”,
“:while” and “:endwhile”.
So my question is am I stuck with startinsert i equivalent, or is there a way to get around with an a behavior? Or should I stick with imap <C-s> <Esc>w<CR>a and no filename testing?
inoremap <expr> <c-s> "\<esc>:" . (@% == "" ? "browse saveas" : "w") . "\<cr>gi"I use
gito get back to insert mode. And use an expression mapping to determine if the file has been saved or not.