0

If I save the result of :call mode() in a variable, how can I restore that mode later?

2
  • 1
    I 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? Commented Mar 26, 2023 at 15:58
  • @VivianDeSmedt I want to destroy a buffer, then create a new buffer exactly the same as it, in the same state
    – minseong
    Commented Mar 26, 2023 at 17:23

1 Answer 1

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.