tags:

views:

45

answers:

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?

+2  A: 

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