diff --git a/evil-collection-vterm.el b/evil-collection-vterm.el new file mode 100644 index 0000000..2509139 --- /dev/null +++ b/evil-collection-vterm.el @@ -0,0 +1,76 @@ +;;; evil-collection-vterm.el --- Bindings for `vterm'. -*- lexical-binding: t -*- + +;; Copyright (C) 2019 James Nguyen + +;; Author: James Nguyen +;; Maintainer: James Nguyen +;; Pierre Neidhardt +;; URL: https://github.com/emacs-evil/evil-collection +;; Version: 0.0.1 +;; Package-Requires: ((emacs "25.1")) +;; Keywords: evil, vterm, tools + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Commentary: +;;; Bindings for `vterm'. + +;;; Code: +(require 'evil-collection) +(require 'vterm nil t) + +(defconst evil-collection-vterm-maps '(vterm-mode-map)) + +(defun evil-collection-vterm-escape-stay () + "Go back to normal state but don't move cursor backwards. +Moving cursor backwards is the default vim behavior but +it is not appropriate in some cases like terminals." + (setq-local evil-move-cursor-back nil)) + +;;;###autoload +(defun evil-collection-vterm-setup () + "Set up `evil' bindings for `vterm'." + (evil-set-initial-state 'vterm-mode 'insert) + + (add-hook 'vterm-mode-hook #'evil-collection-vterm-escape-stay) + + ;; Evil has some "C-" bindings in insert state that shadow regular terminal + ;; bindings. Don't raw-send "C-c" (prefix key) nor "C-h" (help prefix). + (evil-collection-define-key 'insert 'vterm-mode-map + (kbd "C-a") 'vterm--self-insert + (kbd "C-b") 'vterm--self-insert ; Should not be necessary. + (kbd "C-d") 'vterm--self-insert + (kbd "C-e") 'vterm--self-insert + (kbd "C-f") 'vterm--self-insert ; Should not be necessary. + (kbd "C-k") 'vterm--self-insert + (kbd "C-l") 'vterm--self-insert ; Should not be necessary. + (kbd "C-n") 'vterm--self-insert + (kbd "C-o") 'vterm--self-insert + (kbd "C-p") 'vterm--self-insert + (kbd "C-q") 'vterm--self-insert ; Should not be necessary. + (kbd "C-r") 'vterm--self-insert + (kbd "C-s") 'vterm--self-insert ; Should not be necessary. + (kbd "C-t") 'vterm--self-insert + (kbd "C-u") 'vterm--self-insert ; Should not be necessary. + (kbd "C-v") 'vterm--self-insert ; Should not be necessary. + (kbd "C-w") 'vterm--self-insert + (kbd "C-y") 'vterm--self-insert + (kbd "C-z") 'vterm--self-insert) + + (evil-collection-define-key 'normal 'vterm-mode-map + "p" 'vterm-yank + "u" 'vterm-undo)) + +(provide 'evil-collection-vterm) +;;; evil-collection-vterm.el ends here diff --git a/evil-collection.el b/evil-collection.el index 4cf86a7..e2533ff 100644 --- a/evil-collection.el +++ b/evil-collection.el @@ -214,6 +214,7 @@ through removing their entry from `evil-collection-mode-list'." vdiff view vlf + vterm w3m wdired wgrep