;; -*- lexical-binding: t; -*- (use-package vterm :commands vterm :init (defun project-vterm () (interactive) (if (projectile-project-root) (call-interactively #'projectile-run-vterm) (call-interactively #'vterm))) :config (evil-collection-vterm-setup) (general-def 'insert vterm-mode-map "C-" #'vterm-send-escape) ;; Add a hook when vterm changes the directory (defvar vterm-directory-change-hook nil "Hooks to be run after vterm changes the directory") (defun vterm--set-directory (path) "Set `default-directory' to PATH." (let ((dir (vterm--get-directory path))) (when (and dir (eq major-mode 'vterm-mode)) (setq default-directory dir) (run-hooks 'vterm-directory-change-hook)))) (add-hook 'vterm-mode-hook #'hack-dir-local-variables-non-file-buffer) (add-hook 'vterm-directory-change-hook #'hack-dir-local-variables-non-file-buffer) (with-eval-after-load 'consult (defun vterm-consult-yank-from-kill-ring-action (orig-fun &rest args) (if (equal major-mode 'vterm-mode) (let ((inhibit-read-only t) (yank-undo-function (lambda (_start _end) (vterm-undo)))) (cl-letf (((symbol-function 'insert-for-yank) (lambda (str) (vterm-send-string str t)))) (apply orig-fun args))) (apply orig-fun args))) (defun vterm-disable-consult-preview (orig-fun &rest args) "Disable Consult previews in vterm buffers. Meant to advise consult--insertion-preview." (unless (equal major-mode 'vterm-mode) (apply orig-fun args))) (advice-add 'consult-yank-from-kill-ring :around #'vterm-consult-yank-from-kill-ring-action) (advice-add 'consult--insertion-preview :around #'vterm-disable-consult-preview)) :general (leader-map "v" #'project-vterm) :custom (vterm-max-scrollback 10000) (vterm-environment '("TYPEWRITTEN_CURSOR=terminal")) (vterm-ignore-blink-cursor t) (vterm-clear-scrollback-when-clearing t) (vterm-eval-cmds '(("find-file" find-file) ("ff" find-file) ("message" message) ("vterm-clear-scrollback" vterm-clear-scrollback) ("man" man) ("ediff" ediff)))) (provide 'init-vterm)