50

Can anyone help me set up this configuration?

If I create a new pane, the new pane should start out in the same working directory as the pane I was just in. If I create a new window, the new window should start out in the home directory (or any other global default path).

Is this possible with tmux 1.8?

0

2 Answers 2

88

Add -c "#{pane_current_path}" to the new-window/split-window commands.

Example configuration using the default key bindings:

bind  c  new-window      -c "#{pane_current_path}"
bind  %  split-window -h -c "#{pane_current_path}"
bind '"' split-window -v -c "#{pane_current_path}"

I found the pane_current_path trick here. It's also documented in upstream CHANGES.

5
  • 4
    For me, $PWD does not work, but #{pane_current_path} works.
    – Henry Hu
    Nov 7, 2015 at 4:11
  • I don't think this answers the OP's question, because he asked whether it was possible to have new windows start in the home directory. Based on this answer and the ones considered duplicates, I thought placing bind c new-window -c "$HOME" would work, but new windows are still created in the pane_current_path
    – cbcoutinho
    Mar 24, 2018 at 23:09
  • 2
    If you want to override <prefix>" you have to escape the double quote like this: bind '"' split-window -v -c "#{pane_current_path}". Hopefully saves someone some time.
    – jchook
    May 7, 2020 at 0:07
  • 1
    I should add that the characters c,|,- after "bind" represent the keys used to create new panes. By default these are c,%,".
    – Peaceful
    Feb 11, 2023 at 7:45
  • Since this was the first tmux config I modified, just wanted to say that after you add this to config, run tmux source ~/.tmux.conf Aug 22, 2023 at 19:03
9

While @mmoya's answer works for tmux version 1.9 and beyond, the -c option for new-window is not present in earlier versions. For earlier versions, this requires a bit of mucking with default-path. Here is how I have it set up in my .tmux.conf file.

set -g default-path "~"
bind % set default-path "" \; split-window -h \; set -u default-path
bind '"' set default-path "" \; split-window -v \; set -u default-path

This makes the new-window command use the global default-path. However, when splitting a window into panes, it makes a local default-path to override it.

Not the answer you're looking for? Browse other questions tagged .