0

When in terminal mode, I would like that <c-i> and <c-o> work like in insert mode, i.e. the cursor jumps to its next/previous position in accordance with the jumplist.

How to make this to happen?

EDIT: this becomes very annoying when you jump into a terminal window with <c-o> (or with <c-i>) and then can't get out it not with another <c-o> or with a <c-i>.

14
  • I believe in terminal mode you are limited to the possibility of the terminal and it is very likely that it is not possible. Oct 10, 2022 at 14:56
  • Hum, I see. Any workaround to avoid adding entries in the jumplist when jumping into a terminal buffer? A common scenario is when you have a sequence of e.g. <c-o> and you end up in a terminal window and you won't get out from there with another <c-o>. Very annoying.
    – Barzi2001
    Oct 10, 2022 at 15:06
  • Vim. But actually it jumps into terminals… :/
    – Barzi2001
    Oct 10, 2022 at 18:12
  • Thank you! Very appreciated!
    – Barzi2001
    Oct 11, 2022 at 5:15
  • Is the thing where you jump into a terminal window with <c-o> and then can't get out the actual problem you are trying to solve? If so, could you please edit that information into the question?
    – Rich
    Oct 11, 2022 at 9:34

2 Answers 2

1

Looking at the source code, it looks like there is no way other than :h keepjump to avoid adding to jumplist (which you can do: most of the movements can be done through :h :norm, and when in terminal buffer, prepending those commands with :keepjump will avoid adding the terminal buffer to the jumplist, but I suspect most people will find that workaround not a solution at all, so back to the source code):

    // for :global the mark is set only once
    if (global_busy || listcmd_busy || (cmdmod.cmod_flags & CMOD_KEEPJUMPS))
        return;

The easiest way to achieve what OP wants is adding one more condition to the above if block: a condition to check if current buffer is a terminal buffer. Below is the patch.

diff --git a/src/mark.c b/src/mark.c
index 584db033d3ca..b5752653ea0d 100644
--- a/src/mark.c
+++ b/src/mark.c
@@ -143,6 +143,9 @@ setpcmark(void)
     if (global_busy || listcmd_busy || (cmdmod.cmod_flags & CMOD_KEEPJUMPS))
    return;
 
+    if (curbuf->b_term != NULL)
+      return;
+
     curwin->w_prev_pcmark = curwin->w_pcmark;
     curwin->w_pcmark = curwin->w_cursor;

You can apply it by copying it to your clipboard and using ${PASTECMD} | patch -p1, where $PASTECMD is the command associated with your clipboard for pasting.

For xclip:

xclip -selection clipboard -o | patch -p1

NOTE that the last empty line in the patch is expected (although not required) by patch.

1
0

As it's likely not possible to do what you want, if it's a *nix terminal you could use tmux to jump back through terminal history in copy-mode.There are various plugins which can make this faster, like:

You could disable the tmux statusline when running in vim terminal to reduce visual clutter.

1
  • Good to know! But unfortunately I use Win 10.
    – Barzi2001
    Oct 11, 2022 at 5:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.