我想在写入后返回插入模式(参见:else
)
function! SaveOrSaveAsInInsert()
if @% == ""
:browse saveas
else
:w
"//TODO: Return to insert mode
endif
endfunction
尝试过
:w<CR>a
但不起作用。谢谢!
编辑
@Randy Morris,评论使用
startinsert
哪个有效。另一方面:h inserting-ex
说: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".
所以我的问题是我是否坚持
startinsert
i
等效,或者有没有办法绕过 a
行为?或者我应该坚持使用 imap <C-s> <Esc>w<CR>a
没有文件名测试?
最佳答案
inoremap <expr> <c-s> "\<esc>:" . (@% == "" ? "browse saveas" : "w") . "\<cr>gi"
我用 gi
回到插入模式。并使用表达式映射来确定文件是否已保存。
关于vim:在 :write 后转到插入模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6430594/