Skip to content

Instantly share code, notes, and snippets.

@msoeken
Last active January 8, 2023 16:31
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save msoeken/4b2e3ee07b7252f8cb99 to your computer and use it in GitHub Desktop.
Save msoeken/4b2e3ee07b7252f8cb99 to your computer and use it in GitHub Desktop.
Toggle between current buffer and terminal in emacs
(defun toggle-term ()
"Toggles between terminal and current buffer (creates terminal, if none exists)"
(interactive)
(if (string= (buffer-name) "*ansi-term*")
(switch-to-buffer (other-buffer (current-buffer)))
(if (get-buffer "*ansi-term*")
(switch-to-buffer "*ansi-term*")
(progn
(ansi-term (getenv "SHELL"))
(setq show-trailing-whitespace nil)))))
(global-set-key (kbd "<f9>") 'toggle-term)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment