From 95b776fa71ac2cf57c8d074a990cf0927454deff Mon Sep 17 00:00:00 2001 From: michalis Date: Sun, 26 Apr 2026 09:41:53 +0300 Subject: [PATCH] feat: configurable editor experience for `harpoon -e` Adds two tmux options that customise how the edit popup behaves when `$EDITOR` is vim or nvim: - `@tmux-harpoon-faithful-vim-controls` (bool, default `true`): remap `q` -> `:q!`, `:w` -> `:wq`, and `` -> jump to the session on the current line, so the edit popup navigates and exits like the rest of the harpoon UI. Set to `false` to keep stock vim behaviour. - `@tmux-harpoon-editor-args` (string, default empty): extra args appended to the editor invocation (e.g. `--clean`, `-u NONE`) for users who want a lighter editor instance for this popup. Also fixes a quoting bug in `_getFZFCmd`: the `fzf-tmux -p '50%,50%'` form passed literal single quotes around the size argument because the caller word-splits the unquoted command. fzf-tmux exits with status 2 and the popup never spawns, breaking `harpoon -l` on systems that fall back to fzf-tmux (fzf < 0.53). --- harpoon | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/harpoon b/harpoon index bf53da7..89b8dad 100755 --- a/harpoon +++ b/harpoon @@ -62,7 +62,7 @@ _getFZFCmd() { return 0 fi if type fzf-tmux >/dev/null 2>&1; then - echo "fzf-tmux -p '50%,50%'" + echo "fzf-tmux -p 50%,50%" return 0 fi echo "fzf" @@ -138,7 +138,29 @@ switch() { done <"$cachefile" } -edit_file() { exec tmux popup -E "$EDITOR $cachefile"; } +# Tmux options (vim/nvim only): +# @tmux-harpoon-faithful-vim-controls bool, default true +# Remap `q` -> :q!, `:w` -> :wq, and -> jump to session on the +# current line, mirroring how harpoon's UI navigates. +# @tmux-harpoon-editor-args string, default empty +# Extra args appended to the editor command (e.g. `--clean`, `-u NONE`). +edit_file() { + cmd="$EDITOR $cachefile" + editor_basename="${EDITOR##*/}" + editor_basename="${editor_basename%% *}" + case "$editor_basename" in + vim | nvim) + faithful=$(tmux show-option -gqv "@tmux-harpoon-faithful-vim-controls" 2>/dev/null) + [ -z "$faithful" ] && faithful="true" + if [ "$faithful" = "true" ]; then + cmd="$cmd -c \"nnoremap q :q!\" -c \"cnoreabbrev w wq\" -c \"nnoremap :execute '!$0 -s ' . line('.') q!\"" + fi + vim_args=$(tmux show-option -gqv "@tmux-harpoon-editor-args" 2>/dev/null) + [ -n "$vim_args" ] && cmd="$cmd $vim_args" + ;; + esac + exec tmux popup -E "$cmd" +} sessions_has_match() { list_sessions | grep -wq "^$1"; }