[窗口问题]怎么切换两个窗口位置

比如有两个窗口


我该怎么让这两个窗口一次性交换位置

1 个赞

有个ace-window包,可以使用M-x ace-swap-window交换

4 个赞

window-swap-states

如果安装 ivy 或者其他类似工具的话可以 M-x swap 看看相关的函数。 2020-04-28 16-44-20屏幕截图

evil-mode下更简单, C-w H/J/K/L 都可以,分别对应和左边的、下边的、上边的、右边的窗口交换

2 个赞

试了一下,蛮帅的。

(可能是builtin的包?忘了)可以试试buf-move

可以写个函数进行上下左右调换,如果你不想使用ace-window这种第三方包,可以使用windmove来写,就像这样:

(defun window-move (way)
  "移动窗口.(Move window.)
WAY是方向,可选值为p,n,f,b,分别对应上下左右
(WAY is the direction, the optional values are p, n, f, b, which correspond to the up, down, left and right)"
  (interactive "s方向(p-n-f-b): ")
  (let ((old-window-buffer (window-buffer))
        (old-window (get-buffer-window)))
    (pcase way
      ("p" (windmove-up))
      ("n" (windmove-down))
      ("f" (windmove-right))
      ("b" (windmove-left)))
    (setq new-window-buffer (get-buffer-window))
    (if (not (eql old-window-buffer new-window-buffer))
        (progn
          (set-window-buffer old-window (window-buffer))
          (set-window-buffer (get-buffer-window) old-window-buffer)))))

不过这个函数放到use-package的bind-key上有问题,所以如果你要用use-package绑定快捷键的话还是拆分成四个单独的函数吧:

(defun window-move-right()
  (interactive)
  (let ((old-window-buffer (window-buffer))
        (old-window (get-buffer-window)))
    (if (windmove-right)
        (progn
          (set-window-buffer old-window (window-buffer))
          (set-window-buffer (get-buffer-window) old-window-buffer)))))

windmove-swap-state-*

2 个赞

总是能在你的配置里找到一些好玩的东西 :rofl:

简单抄袭了一下你的 init-window.el,发现有几个在其它文件配置的地方,有需要的人可以自取:

  (defcustom centaur-icon (display-graphic-p)
    "Display icons or not."
    :group 'centaur
    :type 'boolean)
  (defun icons-displayable-p ()
    "Return non-nil if `all-the-icons' is displayable."
    (and centaur-icon
         (display-graphic-p)
         (require 'all-the-icons nil t)))

(use-package pretty-hydra
  :init
  (cl-defun pretty-hydra-title (title &optional icon-type icon-name
                                      &key face height v-adjust)
    "Add an icon in the hydra title."
    (let ((face (or face `(:foreground ,(face-background 'highlight))))
          (height (or height 1.0))
          (v-adjust (or v-adjust 0.0)))
      (concat
       (when (and (icons-displayable-p) icon-type icon-name)
         (let ((f (intern (format "all-the-icons-%s" icon-type))))
           (when (fboundp f)
             (concat
              (apply f (list icon-name :face face :height height :v-adjust v-adjust))
              " "))))
       (propertize title 'face face)))))

觉得好玩就用 :smile:

又发现一个好玩的 https://github.com/Ladicle/hydra-posframe ,一切皆可 posframe

然而并不好用,焦点和位置经常出问题 :sweat_smile: :sweat_smile: