Skip to content

Commit ba36a13

Browse files
committed
Initial commit
0 parents  commit ba36a13

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

README.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
A Zsh plugin to open files in a running Vim (or NeoVim) session, from an adjacent Tmux pane.
2+
3+
When running either of these commands, they will find the first Tmux pane with Vim running in it, in the same window, and use `send-keys` to open the file there. Each command takes exactly one argument; the file path to open.
4+
5+
## Available Commands
6+
7+
* `tmux-vim-tabedit`
8+
* `tmux-vim-split`
9+
* `tmux-vim-vsplit`

tmux-vim-integration.plugin.zsh

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Finds the first pane which has vim running, in the same window
2+
__tmux_get_vim_pane() {
3+
local vim_pane
4+
5+
tmux list-panes -F '#I #P [command:#{pane_current_command}] #{?pane_active,(active),}' | while read -r pane; do
6+
if [[ "${pane#*(active)}" = "${pane}" ]] && [[ "${pane}" =~ "\[command:n?vim\]" ]]; then
7+
vim_pane=$(echo "${pane}" | awk '{print $2}')
8+
fi
9+
done
10+
11+
echo $vim_pane
12+
}
13+
14+
# Open a file in adjacent vim
15+
# $1 is the vim command to use (tabedit, split, vsplit)
16+
# $2 is the path of the file to open
17+
__tmux_vim_open() {
18+
local vim_command="$1"
19+
local filepath=$(realpath "$2")
20+
local vim_pane=$(__tmux_get_vim_pane)
21+
22+
if [ -z $vim_pane ]; then
23+
echo "error: Vim pane not found"
24+
return
25+
fi
26+
27+
tmux send-keys -t $vim_pane Escape ":${vim_command} $(printf "%q" "${filepath}")" Enter
28+
tmux select-pane -t $vim_pane
29+
}
30+
31+
# Make available if inside a Tmux session
32+
if [ -n "${TMUX}" ]; then
33+
tmux-vim-tabedit() {
34+
__tmux_vim_open "tabedit" "$1"
35+
}
36+
37+
tmux-vim-split() {
38+
__tmux_vim_open "split" "$1"
39+
}
40+
41+
tmux-vim-vsplit() {
42+
__tmux_vim_open "vsplit" "$1"
43+
}
44+
fi

0 commit comments

Comments
 (0)