使用 SPC o p 可以打开 treemacs 的同时,切换焦点过去,然后可以通过 C-w 之类切换到编辑器里面,但是因为那边是个 sidebar 切换不过去了,请问应该是怎么操作?
ESC SPC w h 移动到左边窗口 SPC w l 移动到右边窗口
1 个赞
treemacs 那个窗口不能通过这个方式切换过去。那个设置了 ``` no-other-window
(defun +treemacs/toggle ()
"Initialize or toggle treemacs.
Ensures that only the current project is present and all other projects have
been removed.
Use `treemacs' command for old functionality."
(interactive)
(require 'treemacs)
(pcase (treemacs-current-visibility)
(`visible (delete-window (treemacs-get-local-window)))
(_ (if (doom-project-p)
(treemacs-add-and-display-current-project)
(treemacs)))))
看了一下,似乎可以参考下这个,切换一下就行。
效果是如果已经打开了 treemacs,那在 treemacs 和编辑窗口之间切换。如果没有打开,那就打开 treemacs 并切换过去。
treemacs 的 toggle doom emacs 自带快捷键了 <SPC> o p
(defun wd/switch-with-treemacs()
(interactive)
(require 'treemacs)
(if (not (eq (treemacs-current-visibility) `visible))
(+treemacs/toggle)
(if (eq (treemacs-get-local-window) (get-buffer-window))
(other-window -1)
(select-window (treemacs-get-local-window))
)
)
)
(global-set-key "\C-\M-j" 'wd/switch-with-treemacs)
我的办法很粗暴。。。和楼上类似。直接定义一个键,是从编辑窗口切换到treemacs的。
(global-set-key (kbd "M-0") 'treemacs-select-window)
从编辑窗口切到treemacs用这个,反之用自带的C-w
即可。
另外如果开启了winum,那么treemacs也可以用他定义的切窗口快捷键切过去。
1 个赞
可以试试看我那个代码。按 C-M-j 会在编辑器和 treemacs 之间来回跳,不用切换按键。