Skip to content

Instantly share code, notes, and snippets.

Last active Feb 24, 2022
What would you like to do?
vterm completion for files, directories, command history and programs names
(use-package vterm
(defun get-full-list ()
(let ((program-list (split-string (shell-command-to-string "compgen -c") "\n" t ))
(file-directory-list (split-string (shell-command-to-string "compgen -f") "\n" t ))
(history-list (with-temp-buffer
(insert-file-contents "~/.bash_history")
(split-string (buffer-string) "\n" t))))
(delete-dups (append program-list file-directory-list history-list))))
(defun vterm-completion-choose-item ()
(completing-read "Choose: " (get-full-list) nil nil (thing-at-point 'word 'no-properties)))
(defun vterm-completion ()
(let ((vterm-chosen-item (vterm-completion-choose-item)))
(when (thing-at-point 'word)
(vterm-send-string vterm-chosen-item)))
(defun vterm-directory-sync ()
"Synchronize current working directory."
(when vterm--process
(let* ((pid (process-id vterm--process))
(dir (file-truename (format "/proc/%d/cwd/" pid))))
(setq default-directory dir))))
(:states 'insert
:keymaps 'vterm-mode-map
"<tab>" 'vterm-completion))
Copy link

ram535 commented Aug 1, 2021

Copy link

danieljamesross commented Feb 24, 2022

This is great, thanks. For those that don't use general.el (like me) I replaced lines 31-34 in my config with the following:

:bind (:map vterm-mode-map ("<tab>" . 'vterm-completion)))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment