开发者

Making Viper state global

开发者 https://www.devze.com 2023-01-05 00:22 出处:网络
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 st

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 q开发者_如何学编程uickly. Does anybody know?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消