If I save the result of :call mode()
in a variable, how can I restore that mode later?
-
1I doubt there is an API in particular for the exotic modes like operator pending. Maybe could give us more insight about what you try to achieve and get a more appropriate suggestion?– Vivian De SmedtMar 26 at 15:58
-
@VivianDeSmedt I want to destroy a buffer, then create a new buffer exactly the same as it, in the same state– theonlygustiMar 26 at 17:23
1 Answer
You can't set an arbitrary mode programmatically, or at least not with a dedicated function like :call setmode('n')
, which doesn't exist.
What you can do, however, is…
- start insert mode with
:help :startinsert
, - start replace mode with
:help :startreplace
, - like the two methods above, but switch to another mode from insert or replace mode,
- execute a normal mode command with
:help :normal
, which should leave you in normal mode, - same as above but execute a normal mode command that switches to another mode, like
v
for visual mode, - and other similar kinds of tricks…
See :help mode-switching
.