Skip to content

Instantly share code, notes, and snippets.

@william8th
Last active July 7, 2025 07:12
Show Gist options
  • Save william8th/faf23d311fc842be698a1d80737d9631 to your computer and use it in GitHub Desktop.
Save william8th/faf23d311fc842be698a1d80737d9631 to your computer and use it in GitHub Desktop.
Tmux open new pane in same directory
# Set the control character to Ctrl+Spacebar (instead of Ctrl+B)
set -g prefix C-space
unbind-key C-b
bind-key C-space send-prefix
# Set new panes to open in current directory
bind c new-window -c "#{pane_current_path}"
bind '"' split-window -c "#{pane_current_path}"
bind % split-window -h -c "#{pane_current_path}"
@naltun
Copy link

naltun commented Aug 11, 2022

Exactly what I was looking for, and easy to grok! Thank you @william8th!

@tony-sol
Copy link

tony-sol commented Sep 28, 2022

Is there a way to open new pane not only in same directory but alse in same shell?
For example:

  1. i open term, default SHELL is '/bin/zsh'
  2. split pane and run powershell - now i have 2 panes, with zsh and pwsh
  3. being in pwsh pane, split-pane creates another zsh pane, but pwsh needed

i've tried with setting

$env:SHELL = '%full pwsh path%'

in pwsh profile and

set-option -g default-command "${SHELL}"
set-option -g default-shell "${SHELL}"
bind '"' split-window -c "#{pane_current_path}" "${SHELL}"
bind % split-window -h -c "#{pane_current_path}" "${SHELL}"

in tmux.conf but it not works :c

@robsgreen
Copy link

Thank you! Saves me so much daily frustration.

@MrRoiz
Copy link

MrRoiz commented Nov 2, 2022

Awesome, thanks! 🚀

@helmerdx
Copy link

🙌

@endepointe
Copy link

this did not work in cygwin 3.3.6. hmmm

@jonathanforhan
Copy link

you're a G thank you

@mtovmassian
Copy link

🙏

@halshar
Copy link

halshar commented May 28, 2023

Here is all I added to mine, if you wanna see the "bare minimum requirements":

# window splits
bind-key v split-window -h -c "#{pane_current_path}"
bind-key b split-window -c "#{pane_current_path}"

thank you for this :) @shmup

@chmnoh
Copy link

chmnoh commented Jun 29, 2023

Great!

@Normanras
Copy link

Did not think it would work so flawlessly. Just adding to the awesomeness and praise! Good job 👍

@anggakharisma
Copy link

Amazing thank you for this 👌

@adityak714
Copy link

Thanks!!

@yoandresaav
Copy link

thanks!

@ltyiz07
Copy link

ltyiz07 commented Mar 18, 2024

Just working!

@LordMoMA
Copy link

thanks, so good!

@phakeandy
Copy link

it works!! thanks.

@tracure1337
Copy link

how to make it work with
set -g mouse on ?

image

@maestromac
Copy link

Thank you for this!

@raphaklaus
Copy link

Indeed a time saver :D

@morphalus
Copy link

Thanks!

@smith-doug
Copy link

@tracure1337 You can see how the menu is created with tmux list-keys > ~/keybindings.txt and can edit the right click binding to include -c #{pane_current_path}

bind-key -T root MouseDown3Pane if-shell -F -t = "#{||:#{mouse_any_flag},#{&&:#{pane_in_mode},#{?#{m/r:(copy|view)-mode,#{pane_mode}},0,1}}}" "select-pane -t= ; send -M" "display-menu -t= -xM -yM -T \"#[align=centre]#{pane_index} (#{pane_id})\" \"#{?#{m/r:(copy|view)-mode,#{pane_mode}},Go To Top,}\" < \"send -X history-top\" \"#{?#{m/r:(copy|view)-mode,#{pane_mode}},Go To Bottom,}\" > \"send -X history-bottom\" '' \"#{?mouse_word,Search For #[underscore]#{=/9/...:mouse_word},}\" C-r \"if -F \\\"#{?#{m/r:(copy|view)-mode,#{pane_mode}},0,1}\\\" \\\"copy-mode -t=\\\" ; send -Xt= search-backward \\\"#{q:mouse_word}\\\"\" \"#{?mouse_word,Type #[underscore]#{=/9/...:mouse_word},}\" C-y \"copy-mode -q ; send-keys -l -- \\\"#{q:mouse_word}\\\"\" \"#{?mouse_word,Copy #[underscore]#{=/9/...:mouse_word},}\" c \"copy-mode -q ; set-buffer -- \\\"#{q:mouse_word}\\\"\" \"#{?mouse_line,Copy Line,}\" l \"copy-mode -q ; set-buffer -- \\\"#{q:mouse_line}\\\"\" '' \"Horizontal Split\" h \"split-window -h -c #{pane_current_path}\" \"Vertical Split\" v \"split-window -v -c #{pane_current_path}\" '' \"#{?#{>:#{window_panes},1},,-}Swap Up\" u \"swap-pane -U\" \"#{?#{>:#{window_panes},1},,-}Swap Down\" d \"swap-pane -D\" \"#{?pane_marked_set,,-}Swap Marked\" s swap-pane '' Kill X kill-pane Respawn R \"respawn-pane -k\" \"#{?pane_marked,Unmark,Mark}\" m \"select-pane -m\" \"#{?#{>:#{window_panes},1},,-}#{?window_zoomed_flag,Unzoom,Zoom}\" z \"resize-pane -Z\""

@windymelt
Copy link

you saved my life.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment