Thursday, November 9, 2017

Re: Help needed on terminal mappings

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 vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment