In Emacs, I often find myself in a situation where I need to jump back and forth between various source files to various terminals. However, I feel like I do not have a good way to do this efficiently and it's clumsy that you can only open one shell in Emacs (shell
, eshell
, or term
).
Moreover, I need an efficient way of juggle between multiple terminals and source files.
How can I achieve this?
CTRL + Shift + N will open a new terminal window if you are already working in the terminal, alternatively you can just select "Open Terminal" form the file menu as well. And like @Alex said you can open a new tab by pressing CTRL + Shift + T .
We can switch between virtual terminals in Virtualbox with CTRL+ALT+FX.
In Putty Settings > Window > Behavior, you can check one of the boxes to open the system menu on a certain keypress (I personally use ALT-Space). With this setting in place, you can hit ALT-Space, then type the d key to Duplicate Session.
Press Command-N. Choose Shell > New Window > New Window with Profile. The name of the profile that opens is concatenated to the end of the New Window with Profile menu item.
You can have as many terminals and shells open at once as you want. Just use M-x rename-buffer
to change the name of an existing *term*
or *shell*
buffer, and the next time you do M-x term
or M-x shell
, a brand new buffer will be created. In the case of M-x shell
, a prefix argument will cause you to be prompted for the name of the new shell buffer, as offby1 noted.
A few years ago I had a job where I had to regularly log in to various production servers named "host01.foo.com", "host02.foo.com", etc. I wrote a little function like this one to make it easier to manage them all:
(defun ssh-to-host (num) (interactive "P") (let* ((buffer-name (format "*host%02d*" num)) (buffer (get-buffer buffer-name))) (if buffer (switch-to-buffer buffer) (term "/bin/bash") (term-send-string (get-buffer-process (rename-buffer buffer-name)) (format "ssh host%02d.foo.com\r" num)))))
Then I bound this command to (say) s-h (super H), enabling me to just type M-5 s-h. If I didn't already have a buffer named *host05*
, it would start a new terminal emulator buffer, rename it to *host05*
, and ssh me into host05.foo.com. If buffer *host05*
already existed, it would simply switch me to it. Quite handy!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With