1

EmacsWiki says:

There is a way to make Viper state and Viper insert state global, like in Vim (and probably vi). In Vim (and probably vi), you start in Normal Mode. You can switch buffer, and Vim stays in Normal Mode. Pressing “i” puts Vim in Insert Mode. Then if you switch buffers by clicking on another window, Vim stays in Insert Mode. You don’t have to remember which buffer is in what mode, you only need to remember in which mode Vim is.

But unfortunately, they don't say what this method is, and I couldn't find it quickly. Does anybody know?

Andreas ZUERCHER
  • 862
  • 1
  • 7
  • 20
Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487
  • 1
    Looking at the viper code, I don't see how it can be done - there are tons of viper state variables that are defined to be buffer local. And, unfortunately, there isn't a 'set-buffer-hook' you can use to trigger the behavior you want upon switching buffers. – Trey Jackson Jun 23 '10 at 20:36
  • Thanks! Yes, that's unfortunate. – Alexey Romanov Jun 23 '10 at 20:42

1 Answers1

3

I don't know a single setting or package to do what you want. It's not provided by viper itself.

That said, you can write some advice which does the job. The key being that you need to advise all the ways you switch buffers/windows. For example, if you switch windows through the other-window command (C-x o), you'll want this:

(defadvice other-window (around other-window-maintain-viper-state activate 
                         activate)
  "when switching windows, pull the viper-current-state along"
  (let ((old-window-state viper-current-state))
    ad-do-it
    (viper-change-state old-window-state)))

But, switching windows using the mouse doesn't go through that function, and to get that to work you need to advise select-window in exactly the same way:

(defadvice select-window (around select-window-maintain-viper-state activate 
                          activate)
  "when switching windows, pull the viper-current-state along"
  (let ((old-window-state viper-current-state))
    ad-do-it
    (viper-change-state old-window-state)))

If you find you use another mechanism to switch windows/buffers that doesn't use the above, it just takes a tiny bit of digging (M-x describe-key ) to find out what new thing you should be advising.

Trey Jackson
  • 73,529
  • 11
  • 197
  • 229