Hacker News new | comments | show | ask | jobs | submit login

I realise you can rebind them, but both screen and tmux do themselves a disservice by choosing binding keys which overlap with prominent keys in emacs and for users who use emacs mode in their shell.

First impressions count.

If you want to configure tmux to use just a backtick as the escape, create ~/.tmux.conf

    unbind C-b
    set -g prefix `
    bind-key ` send-prefix
When you need to type a backtick just press it twice.

For screen, I used to do this:

    escape ``
.. in ~/.screenrc, but I've just tried it and it seems that there's now no easy way to type a backtick when you need one.

Query: in screen I can switch between two buffers by doing ctrl+a, ctrl+a. This doesn't work in tmux. How do I configure this to work in tmux?

Emacs users should be using Emacs as their terminal multiplexer...

One reason to run Emacs in tmux is if you work on remote machines over, e.g. ssh. Emacs in tmux (or screen) lets you detach, log out then log back in and re-attach to the remote session with Emacs still running. That's amazingly handy.

Another option is tramp[1], which lets you open files remotely (generally via ssh/scp). Not the same thing, but often accomplishes the same goal.

[1] http://www.gnu.org/software/tramp/#Top

You still need a remote shell open if you want to run make, use SCM plugins, etc, so I've never found tramp that useful. If there's a clever solution for that I'd love to hear it.

eshell interfaces pretty well with tramp (well, not over FTP obviously, but ssh) so if you're editing a file over tramp and start eshell, it'll be in the directory of the file on the remote host. you can also use tramp-y paths in eshell:

cd /user@host:/home/user/

I realize I'm a bit late to reply, but thanks for the tip. The biggest problem I had was with p4 mode (we use perforce at work) and rope-mode - I didn't really feel like hacking those to get it to work with tramp. And I can keep everything open across network disconnects with screen or tmux...

Actually, make works in tramp by default if you use 'M-x compile' and friends.

Emacs-server does the same thing.

C-h f server-start

Well - it's my tool of choice for editing Makefiles. :) But that's all I use it for. My vim setup automatically hammers tabs to spaces, and make doesn't like that.

Shell users who use emacs mode (most ppl) may be annoyed by ctrl+a missing.

The following line in your vimrc will make vim not expand tabs for every file named "Makefile".

    au BufRead,BufNewFile Makefile set noexpandtab

Wow - this thread is full of good advice. I have not touched my dot files in about four years, and today they're all getting an upgrade. Thanks!

At least in my vim, Makefiles are automatically set to noexpandtab even-though I have it set to automatically expand tabs for everything else.

Could you elaborate? I'd love to try that.

; Open a terminal

M-x ansi-term

; Rename the buffer (escaping shell mode first)

C-c C-j M-x rename-buffer

; Shell responds to keyboard again

C-c C-k

; Split window in half horizontally

C-x 2


I stole this (possibly from Steve Yegge or another source) long ago to somewhat automate the process of renaming terminal buffers:

  (global-set-key (kbd "<f2>") 'visit-ansi-term)

  ;; Terminal awesomeness
  (require 'term)
  (defun visit-ansi-term ()
    "If the current buffer is:
       1) a running ansi-term named *ansi-term*, rename it.
       2) a stopped ansi-term, kill it and create a new one.
       3) a non ansi-term, go to an already running ansi-term
          or start a new one while killing a defunt one"
    (let ((is-term (string= "term-mode" major-mode))
          (is-running (term-check-proc (buffer-name)))
          (term-cmd "/usr/local/bin/zsh")
          (anon-term (get-buffer "*ansi-term*")))
      (if is-term
          (if is-running
              (if (string= "*ansi-term*" (buffer-name))
                  (call-interactively 'rename-buffer)
                (if anon-term
                    (switch-to-buffer "*ansi-term*")
                  (ansi-term term-cmd)))
            (kill-buffer (buffer-name))
            (ansi-term term-cmd))
        (if anon-term
            (if (term-check-proc "*ansi-term*")
                (switch-to-buffer "*ansi-term*")
              (kill-buffer "*ansi-term*")
              (ansi-term term-cmd))
          (ansi-term term-cmd)))))

Hey, I found that code hard to follow, with the if-then-elses nested 4 deep. A refactor, pretty much untested since I don't use ansi-term:

    (defun visit-ansi-term ()
      "If the current buffer is:
         1) a running ansi-term named *ansi-term*, rename it.
         2) a stopped ansi-term, kill it and create a new one.
         3) a non ansi-term, go to an already running ansi-term
            or start a new one while killing a defunct one."
      (let ((is-term      (string= "term-mode" major-mode))
            (is-ansi-term (string= "*ansi-term*" (buffer-name)))
            (is-running   (term-check-proc (buffer-name)))
            (anon-term    (get-buffer "*ansi-term*")))
         ((and is-term is-running is-ansi-term)
          (call-interactively 'rename-buffer))
         ((and anon-term (if is-term
                             (and is-running (not is-ansi-term))
                           (term-check-proc "*ansi-term*")))
          (switch-to-buffer "*ansi-term*"))
          (cond ((and is-term (not is-running))
                 (kill-buffer (buffer-name)))
                ((and anon-term (not (term-check-proc "*ansi-term*")))
                 (kill-buffer "*ansi-term*")))
          (ansi-term "/usr/local/bin/zsh")))))

M+x ansi-term should do it. I'm not sure how well that scales to many terminals though. M+x term also works. There is also eshell.

ansi-term and term are massively buggy.

I've never been able to get it to deal well with vast amounts of output well. Constant overwriting issues etc. Definitely prefer to use tmux + emacs considering the huge amount of stuff i end up throwing at my term.

Just open several terminal buffers in Emacs.

This isn't very useful if what you want to run in your terminal buffer needs to constantly update its screen while you're working in a different buffer (e.g. irc, tailing log files, etc)

Umm.. why is it not useful? Emacs will allow multiple buffers to update at once, and you can work in a third while watching them... That's kind of the idea.

shell mode + emacs --daemon + emacsclient = all the multiplexing a growing engineer might need.

Per your query: ctrl+a ctrl+a is how I switch between two windows (tmux calls them windows, they're basically tabs). If you want to switch between two panes (divisions inside a window, the equivalent of splitting the screen in a regular editor or visible buffers in vim/emacs), use ctrl-a o. I also have these bindings in my tmux conf for moving between panes painlessly:

    # use hjkl for moving
    bind h select-pane -L
    bind j select-pane -D
    bind k select-pane -U
    bind l select-pane -R

Nice one. I've now also added resize variations of these.

    bind-key C-j resize-pane -D 8
    bind-key C-k resize-pane -U 8
    bind-key C-h resize-pane -L 8
    bind-key C-l resize-pane -R 8

    bind C-a last-window
Switch the C-a for whatever your bind-key is.

thank you sir! I am now entirely migrated to tmux. :)

I use ` as the prefix, so you might take a look at my tmux.conf[1] if you want help transitioning.

[1] http://pastebin.com/g6frvnnr

I use the null character in GNU screen:

    escape ^@^@
On most keyboards, you can enter it with control-space, which is very easy to type and rarely used for other purposes (though emacs uses for `set-mark-command`).

Control-] can also be a good choice (at least for US-style keyboards that don't require shift for the square brackets).

   bindkey 'a' last-window
   bindkey C-a last-window
if you use the command frequently enough, it might be worthwhile binding `^a a` and `^a^a`, similar to the tactic of binding F1 to <esc> in vim

I bind C-z as the escape character (in screen). It seems to serve me well :)

> Query: in screen I can switch between two buffers by doing ctrl+a, ctrl+a. This doesn't work in tmux. How do I configure this to work in tmux?

"Ctrl-b n" for next-window?

I think the idea is to be able to pound on whatever the defined escape key is to be able to toggle buffers, not that's he unable to find a command to switch to the next window.

That's not quite what I'm after. I guess it's hard for non-screen people to know what I'm talking about from my vague description above :)

Here's a scenario to show what I mean: you're in buffer 5. You switch to buffer 2. Now if you do ctrl+a, ctrl+a, you leap back to buffer 5. And if you do it again, you go back to buffer 2. This is great when you're editing code in one session and running it in the other.

I use that screen behaviour for panes:

bind C-a last-pane

but last-window exists too.

Is there a way to set it up to do this if you hit (escape-key) (current buffer index)? That's the way weechat works, and I keep expecting it to work in tmux as well :/

awesome. I hadn't thought of that but it's much better. thank you.

I've now switched last-window to bind C-s last-window, because it's fast to tap out.

If ctrl-a is your escape key then just do this:

    bind-key C-a last-window

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact