Help needed on terminal mappings

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Help needed on terminal mappings

Lifepillar
I have my terminal (Terminal.app on macOS) configured with the
following mappings:

Shift+Left_arrow  \033[1;2D
Shift+Right_arrow \033[1;2C
Alt+Left_arrow    \033b
Alt+Right_arrow   \033f

The latter two, in particular, allow me to jump between words in
a shell using Alt+arrows.

Besides, in my vimrc, I have the following:

     set <s-left>=^[b
     set <s-right>=^[f

(^[ is literal Esc). With those, I can use Shift/Alt + arrows to
jump between words in the command line and in buffers.

In Vim's terminal, however, Alt+arrows send ^[1;2C and ^[1;2D, like
Shift+arrows. How can I configure Vim so that Alt+arrows behave the
same as in my shell (i.e., jump between words)?

I have tried:

tmap <a-left> ^[b
tmap <s-left> ^[b

to no avail. If I remove those two lines above from my vimrc, then
Alt+arrows correctly send ^[b and ^[f in Vim's terminal, but I lose
the ability to use Alt+arrows elsewhere.

Thanks,
Life.



--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Help needed on terminal mappings

Bram Moolenaar

Lifepillar wrote:

> I have my terminal (Terminal.app on macOS) configured with the
> following mappings:
>
> Shift+Left_arrow  \033[1;2D
> Shift+Right_arrow \033[1;2C
> Alt+Left_arrow    \033b
> Alt+Right_arrow   \033f
>
> The latter two, in particular, allow me to jump between words in
> a shell using Alt+arrows.
>
> Besides, in my vimrc, I have the following:
>
>      set <s-left>=^[b
>      set <s-right>=^[f
>
> (^[ is literal Esc). With those, I can use Shift/Alt + arrows to
> jump between words in the command line and in buffers.
>
> In Vim's terminal, however, Alt+arrows send ^[1;2C and ^[1;2D, like
> Shift+arrows. How can I configure Vim so that Alt+arrows behave the
> same as in my shell (i.e., jump between words)?
>
> I have tried:
>
> tmap <a-left> ^[b
> tmap <s-left> ^[b
>
> to no avail. If I remove those two lines above from my vimrc, then
> Alt+arrows correctly send ^[b and ^[f in Vim's terminal, but I lose
> the ability to use Alt+arrows elsewhere.

This runs into a few limitations, main problem is that these keys are
not supported by termcap.  Vim does not recognize them as specific keys,
but you can map the escape sequence.  However, that doesn't work for
passing the code on to the terminal.

Ideally Vim would recognize the key, but that requires a lot of work.
And then libvterm needs to be able to handle it (a quick check is that
this isn't done properly, it mixes up ESC and CSI).

Assuming you just want to make this work for your specific setup and
accept that it's not portable: We can define escape sequences that Vim
passes on literally to the program runnin in the terminal window.
That's very flexible, but not portable.

Hmm, perhaps you could try something like this:

        :tmap <expr> <Esc>b SendToTerm("\<Esc>b")
        func SendToTerm(what)
          call term_sendkeys('', a:what)
          return ''
        endfunc

No idea if this works, haven't tried it.

--
It might look like I'm doing nothing, but at the cellular level
I'm really quite busy.

 /// Bram Moolenaar -- [hidden email] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Help needed on terminal mappings

arocker

> --
> It might look like I'm doing nothing, but at the cellular level
> I'm really quite busy.
>

Even if I wasn't a Vim fan, I think I'd subscribe just for Bram's sigs. :-)*

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Help needed on terminal mappings

Lifepillar
In reply to this post by Bram Moolenaar
On 08/11/2017 22:15, Bram Moolenaar wrote:

>
> Lifepillar wrote:
>
>> I have my terminal (Terminal.app on macOS) configured with the
>> following mappings:
>>
>> Shift+Left_arrow  \033[1;2D
>> Shift+Right_arrow \033[1;2C
>> Alt+Left_arrow    \033b
>> Alt+Right_arrow   \033f
>>
>> The latter two, in particular, allow me to jump between words in
>> a shell using Alt+arrows.
>>
>> Besides, in my vimrc, I have the following:
>>
>>       set <s-left>=^[b
>>       set <s-right>=^[f
>>
>> (^[ is literal Esc). With those, I can use Shift/Alt + arrows to
>> jump between words in the command line and in buffers.
>>
>> In Vim's terminal, however, Alt+arrows send ^[1;2C and ^[1;2D, like
>> Shift+arrows. How can I configure Vim so that Alt+arrows behave the
>> same as in my shell (i.e., jump between words)?
>>
>> I have tried:
>>
>> tmap <a-left> ^[b
>> tmap <s-left> ^[b
>>
>> to no avail. If I remove those two lines above from my vimrc, then
>> Alt+arrows correctly send ^[b and ^[f in Vim's terminal, but I lose
>> the ability to use Alt+arrows elsewhere.
>
> This runs into a few limitations, main problem is that these keys are
> not supported by termcap.  Vim does not recognize them as specific keys,
> but you can map the escape sequence.  However, that doesn't work for
> passing the code on to the terminal.
>
> Ideally Vim would recognize the key, but that requires a lot of work.
> And then libvterm needs to be able to handle it (a quick check is that
> this isn't done properly, it mixes up ESC and CSI).
>
> Assuming you just want to make this work for your specific setup and
> accept that it's not portable: We can define escape sequences that Vim
> passes on literally to the program runnin in the terminal window.
> That's very flexible, but not portable.
>
> Hmm, perhaps you could try something like this:
>
> :tmap <expr> <Esc>b SendToTerm("\<Esc>b")
> func SendToTerm(what)
>  call term_sendkeys('', a:what)
>  return ''
> endfunc
>
> No idea if this works, haven't tried it.

That appears to work fine!

Thanks,
Life.




--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
ds
Reply | Threaded
Open this post in threaded view
|

Re: Help needed on terminal mappings

ds
In reply to this post by Bram Moolenaar
Speaking of <A-Arrows>... My terminal (iTerm.app on macOS) sure does distinguish <A-Left> from <Left> (cat reports ^[[1;9D for the former, and ^[[D for the latter), my Vim does understand those keys, too, and I have the following in my $VIMRC (which works perfectly):

```
" go to the previous word
nnoremap <Esc>[1;9D <S-Left>
inoremap <Esc>[1;9D <S-Left>
xnoremap <Esc>[1;9D <S-Left>
cnoremap <Esc>[1;9D <S-Left>
" go to the next word
nnoremap <Esc>[1;9C <S-Right>
inoremap <Esc>[1;9C <S-Right>
xnoremap <Esc>[1;9C <S-Right>
cnoremap <Esc>[1;9C <S-Right>
```

But unfortunately :terminal fails to separate those, and cat reports ^[[D for both <A-Left> and <Left>.

Having that in mind, the solution you provided allows to map <C-Arrows> or <S-Arrows> but not <A-Arrows>. What do you think, is there any way to fix that?


Thanks,


--
ds

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.