From 87728c4d0d2623a3bf238d49d5360f16bca788e0 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Sat, 2 Nov 2019 14:26:44 +0100 Subject: [PATCH] Pass cursor position to edit_command_buffer for some editors Fixes #6138 Naturally this does not work for many other editors/aliases, but it's still nice that we can make it work for some common editors without requiring any configuration. Of course this approach is not terribly flexible; but it's alwyas possible to just wrap edit_command_buffer and set an EDITOR that knows about the cursor position. It doesn't feel important enough to add a configuration option. --- share/functions/edit_command_buffer.fish | 28 +++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/share/functions/edit_command_buffer.fish b/share/functions/edit_command_buffer.fish index 7440741c3..41dec9b63 100644 --- a/share/functions/edit_command_buffer.fish +++ b/share/functions/edit_command_buffer.fish @@ -29,8 +29,34 @@ function edit_command_buffer --description 'Edit the command buffer in an extern end commandline -b >$f + set -l offset (commandline --cursor) + # compute cursor line/column + set -l lines (commandline)\n + set -l line 1 + while test $offset -ge (string length $lines[1]) + set offset (math $offset - (string length $lines[1])) + set line (math $line + 1) + set -e lines[1] + end + set col (math $offset + 1) + + set -l basename (string match -r '[^/]*$' -- $editor[1]) + if contains $basename vi vim nvim + set -a editor +$line +"norm $col|" $f + else if contains $basename emacs emacsclient gedit kak + set -a editor +$line:$col $f + else if contains $basename nano + set -a editor +$line,$col $f + else if contains $basename joe ee + set -a editor +$line $f + else if contains $basename code code-oss + set -a editor --goto $f:$line:$col + else + set -a editor $f + end + __fish_disable_bracketed_paste - $editor $f + $editor set -l editor_status $status __fish_enable_bracketed_paste