• Stars
    star
    162
  • Rank 232,284 (Top 5 %)
  • Language
    Emacs Lisp
  • License
    GNU General Publi...
  • Created over 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

toggles between the vterm buffer and whatever buffer you are editing.

MELPA

vterm-toggle Toggle vterm buffer

emacs-libvterm is fully-fledged terminal emulator inside GNU Emacs based on libvterm.

This package provides the command vterm-toggle which toggles between the vterm buffer and whatever buffer you are editing.

This is done in an "intelligent" way. Features are:

  1. Starts a vterm if none is existent.
  2. Minimum distortion of your window configuration.
  3. When done in the vterm-buffer you are returned to the same window configuration you had before you toggled to the shell.
  4. If you desire, you automagically get a cd command in the shell to the directory where your current buffers file exists, just call vterm-toggle-cd instead of vterm-toggle.
(global-set-key [f2] 'vterm-toggle)
(global-set-key [C-f2] 'vterm-toggle-cd)

;; you can cd to the directory where your previous buffer file exists
;; after you have toggle to the vterm buffer with `vterm-toggle'.
(define-key vterm-mode-map [(control return)]   #'vterm-toggle-insert-cd)

;Switch to next vterm buffer
(define-key vterm-mode-map (kbd "s-n")   'vterm-toggle-forward)
;Switch to previous vterm buffer
(define-key vterm-mode-map (kbd "s-p")   'vterm-toggle-backward)

Customize

vterm-toggle-cd-auto-create-buffer

With

(setq vterm-toggle-cd-auto-create-buffer nil)

vterm-toggle-cd would activate a recent vterm buffer even if no prompt can be found (with vterm-toggle-use-dedicated-buffer still nil). So when the current buffer is not a vterm buffer, it would always activate a recent vterm buffer if there is one but would only insert cd if the prompt is available. And you can bind

(define-key vterm-mode-map [(control return)]   #'vterm-toggle-insert-cd)

vterm-toggle-reset-window-configration-after-exit

t Reset window configuration after vterm buffer is killed. 'kill-window-only Kill Window only.

vterm-toggle-hide-method

  1. delete-window Delete vterm window
  2. nil Toggle without closing the vterm window, just jump back-and-forth between vterm and a code buffer.
  3. reset-window-configration Reset window configration

show vterm buffer in current window

(setq vterm-toggle-fullscreen-p nil)
(add-to-list 'display-buffer-alist
             '((lambda (buffer-or-name _)
                   (let ((buffer (get-buffer buffer-or-name)))
                     (with-current-buffer buffer
                       (or (equal major-mode 'vterm-mode)
                           (string-prefix-p vterm-buffer-name (buffer-name buffer))))))
         (display-buffer-reuse-window display-buffer-same-window)))


show vterm buffer in bottom side

(setq vterm-toggle-fullscreen-p nil)
(add-to-list 'display-buffer-alist
             '((lambda (buffer-or-name _)
                   (let ((buffer (get-buffer buffer-or-name)))
                     (with-current-buffer buffer
                       (or (equal major-mode 'vterm-mode)
                           (string-prefix-p vterm-buffer-name (buffer-name buffer))))))
                (display-buffer-reuse-window display-buffer-at-bottom)
                ;;(display-buffer-reuse-window display-buffer-in-direction)
                ;;display-buffer-in-direction/direction/dedicated is added in emacs27
                ;;(direction . bottom)
                ;;(dedicated . t) ;dedicated is supported in emacs27
                (reusable-frames . visible)
                (window-height . 0.3)))

show vterm buffer in side window

If you want show vterm buffer at bottom side window:

(setq vterm-toggle-fullscreen-p nil)
(add-to-list 'display-buffer-alist
             '((lambda (buffer-or-name _)
                   (let ((buffer (get-buffer buffer-or-name)))
                     (with-current-buffer buffer
                       (or (equal major-mode 'vterm-mode)
                           (string-prefix-p vterm-buffer-name (buffer-name buffer))))))
               (display-buffer-reuse-window display-buffer-in-side-window)
               (side . bottom)
               ;;(dedicated . t) ;dedicated is supported in emacs27
               (reusable-frames . visible)
               (window-height . 0.3)))

work with centaur-tabs (select next/prev vterm buffer)

https://github.com/ema2159/centaur-tabs/

You can customize centaur-tabs and make all vterm buffer in a tab group, and use centaur-tabs-forward and centaur-tabs-backward switch from one vterm buffer to another.

(global-set-key  (kbd "s-n") 'centaur-tabs-forward)
(global-set-key  (kbd "s-p") 'centaur-tabs-backward)
(setq centaur-tabs-buffer-groups-function 'vmacs-awesome-tab-buffer-groups)
(defun vmacs-awesome-tab-buffer-groups ()
  "`vmacs-awesome-tab-buffer-groups' control buffers' group rules. "
  (list
   (cond
    ((derived-mode-p 'eshell-mode 'term-mode 'shell-mode 'vterm-mode)
     "Term")
    ((string-match-p (rx (or
                          "\*Helm"
                          "\*helm"
                          "\*tramp"
                          "\*Completions\*"
                          "\*sdcv\*"
                          "\*Messages\*"
                          "\*Ido Completions\*"
                          ))
                     (buffer-name))
     "Emacs")
    (t "Common"))))

(setq vterm-toggle--vterm-buffer-p-function 'vmacs-term-mode-p)
(defun vmacs-term-mode-p(&optional args)
  (derived-mode-p 'eshell-mode 'term-mode 'shell-mode 'vterm-mode))

vterm-toggle-use-dedicated-buffer

When vterm-toggle-use-dedicated-buffer is not nil, you can toggle to a dedicated vterm buffer.

you can toggle to different dedicated buffer for different purpose. For example, I want to replace default compile with my vterm-compile

(defvar vterm-compile-dedicated-buffer nil)
(defun vterm-compile ()
  (interactive)
  (let ((vterm-toggle-use-dedicated-buffer t)
        (vterm-toggle--vterm-dedicated-buffer vterm-compile-dedicated-buffer))
    (with-current-buffer (vterm-toggle-cd)
      (setq vterm-compile-dedicated-buffer (current-buffer))
      (rename-buffer "term compile")
      (compilation-shell-minor-mode 1)
      (vterm-send-string compile-command t)
      (vterm-send-return))
    )
  )

More Repositories

1

fund

ไปŽๅคฉๅคฉๅŸบ้‡‘็ฝ‘ๆŠ“ๅ–ๆ•ฐๆฎ๏ผŒ่ฎก็ฎ—ๅฎšๆŠ•ๆŽ’่กŒ
Go
51
star
2

vmacs

my .emacs.d
Emacs Lisp
50
star
3

helm-etags-plus

etags interface for Helm on Emacs
Emacs Lisp
48
star
4

my_autohotkey_scripts

my autohotkey scripts . http://jixiuf.github.com/my_autohotkey_scripts/
AutoHotkey
32
star
5

golden-ratio-scroll-screen

scrolling screen in Emacs
Emacs Lisp
30
star
6

helloerlang

my repos for erlang test code .
Erlang
26
star
7

ctags-update

(auto) update TAGS in parent directory using exuberant-ctags
Emacs Lisp
16
star
8

jixiuf.github.io

my org files publish by GNU/Emacs org-mode .
Emacs Lisp
14
star
9

dired-filetype-face

set different face for different file types in dired buffer for emacs
Emacs Lisp
14
star
10

ivy-dired-history

Emacs Lisp
14
star
11

sqlparser

a plugin for emacs to edit sql script or execute sql sentence in sql-mode.it can completing tablename and colum names.
Emacs Lisp
9
star
12

helm-dired-history

show dired histories you have visited on emacs.
Emacs Lisp
8
star
13

dotfiles

Lua
7
star
14

quick-jump

like bookmark in Emacs ,jump from one position to another quickly
Emacs Lisp
4
star
15

vitess-build-patch

Shell
3
star
16

joseph-single-dired

only open a single dired buffer in emacs
Emacs Lisp
3
star
17

erlang-dired-mode

erlang dired mode with Emakefile
Emacs Lisp
2
star
18

drp

drp
Java
2
star
19

libtsm

C
2
star
20

my_redis_erlang

no finished yet ,maybe wouldn't be finished
Erlang
1
star
21

hello_c

c code
C
1
star
22

joseph-autopair

autopair for Emacs . auto insert } ]) when typing [{(
Emacs Lisp
1
star
23

logstashdocker

Makefile
1
star
24

emacs-tsmterm

C
1
star
25

hammerspoon_supergenpass

Lua
1
star
26

helm-bm

Visible Bookmark bm.el helm interface
Emacs Lisp
1
star
27

joseph-file-util

some util function handle file and directory for Eamcs
Emacs Lisp
1
star
28

awesomerc

awesome is a window manager under linux ,and this is my config for it
Lua
1
star