让 Viper 状态全球化

发布于 2024-09-06 22:38:05 字数 371 浏览 4 评论 0原文

EmacsWiki

有一种方法可以使 Viper 状态和 Viper 插入状态全局化,就像在 Vim(也可能是 vi)中一样。在 Vim(可能还​​有 vi)中,您以普通模式开始。您可以切换缓冲区,Vim 会保持正常模式。按“i”使 Vim 进入插入模式。然后,如果您通过单击另一个窗口来切换缓冲区,Vim 将保持插入模式。你不必记住哪个缓冲区处于什么模式,你只需要记住 Vim 处于哪种模式即可。

但遗憾的是,他们并没有说这个方法是什么,我也无法很快找到。有人知道吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一身骄傲 2024-09-13 22:38:05

我不知道有哪个设置或包可以满足您的要求。它不是由 viper 本身提供的。

也就是说,您可以写一些建议哪个可以完成这项工作。关键是您需要建议切换缓冲区/窗口的所有方式。例如,如果您通过 other-window 命令 (Cx o) 切换窗口,您将需要这样:

(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)))

但是,使用鼠标切换窗口不会通过该功能,并且要使其工作,您需要以完全相同的方式建议 select-window

(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)))

如果您发现使用另一种机制来切换不使用上述机制的窗口/缓冲区,那么它只需要一点点挖掘(Mxdescribe-key)即可找出您应该建议的新事物。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文