28

When I press Ctrl+" (create a new pane) while in a pane, which has the PWD /tmp for example, the new pane starts as my home folder ~.

I looked at https://unix.stackexchange.com/a/109255/72471 and it helped me with the same issue concerning windows.

However, I couldn't fix the split-window issue by inserting

bind " split-window -c "#{pane_current_path}"

into my ~/.tmux.conf.

I am using tmux 1.9a and therefor don't want a rather messy solution for older versions stated here (it doesn't work in my case, anyway):

bind '"' set default-path "" \; split-window -v \; set -u default-path

How can I tell tmux to set the default directory as the current path of a pane, when creating a new pane?

polym
  • 10,852

4 Answers4

49

Try specifying v for vertical or h for horizontal

My .tmux.conf file has:

bind \ split-window -h -c '#{pane_current_path}'  # Split panes horizontal
bind - split-window -v -c '#{pane_current_path}'  # Split panes vertically

(I use \ and - as one-finger pane splitters.)

New panes open for me using my current directory, wherever I am.
It's certainly a key feature for me!

One other critical thing with tmux (this was the issue in this case) is that you have to apply changes with:

tmux source-file ~/.tmux.conf

Note that closing terminals, even logging off and restarting, will NOT apply tmux changes – you have to actually use that command (or use Ctrl+B :source-file ~/.tmux.conf).

You can see my full .tmux.conf file at https://github.com/durrantm/setups.

  • 2
    You said "Note that closing terminals, even logging off and restarting will NOT apply tmux changes".

    Of course if you only detached tmux it won't but killing and restarting the server will apply changes :).

    – soyuka Feb 11 '15 at 19:16
  • 2
    Thanks so much! This was super helpful. However, I'm pretty sure restarting the computer applies tmux changes :) – vitiral Oct 28 '15 at 16:52
  • Restarting the computer did not apply changes for me previously leading to confusion for me. ymmv – Michael Durrant Feb 18 '17 at 13:40
  • Note that the same thing can be done for new-window – math2001 May 25 '18 at 08:58
31
bind '%' split-window -h -c '#{pane_current_path}'  # Split panes horizontal
bind '"' split-window -v -c '#{pane_current_path}'  # Split panes vertically
bind c new-window -c '#{pane_current_path}' # Create new window

Add last line to your ~/.tmux.conf to maintain $PWD in new window as well.

Shubham
  • 419
7

That's because,

bind " split-window -c "#{pane_current_path}"

should be

bind '"' split-window -c "#{pane_current_path}"
Giumo
  • 93
2

In case someone gets here by searching, this works fine with tmux 2.7 and should be ok with likely all versions

unbind '"'
bind '"' split-window -v -c '#{pane_current_path}'  # Split panes vertically

unbind %
bind % split-window -h -c '#{pane_current_path}'  # Split panes horizontal