tmux new pane has home directory as default instead of previous directory

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?

Asked By: polym

||

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.

Answered By: Michael Durrant

That’s because,

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

should be

bind '"' split-window -c "#{pane_current_path}"
Answered By: Giumo
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.

Answered By: Shubham

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
Answered By: ShahinSorkh
Categories: Answers Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.