Emit Terminal Keycodes from within ViM

524 views
Skip to first unread message

Saad Malik

unread,
Sep 14, 2013, 6:14:41 PM9/14/13
to v...@vim.org
Hi All,
I've been searching on this topic for hours but couldn't find anything relevant on the internetz.

_What_:
In VIM, map <F6> to emit/send the following Mintty terminal keycode "\e[?7727h".

_Why_:
Cygwin Mintty terminal has a special mode (app escape mode) when enabled emits \eO[ (instead of regular \[) on ESC key. Using this I mapped <Esc>O[ to <ESC> which immediately exits insert mode. To enable App Escape mode for mintty, the following terminal code needs to be sent "\e[?7727h". To disable the app escape mode: "\e[?7727l".

I've set my &t_ti = "\e[?7727h" and &t_te = "\e[?7727l". This works great--as soon as I start VIM, vim emits the t_ti code to enable Mintty app escape mode. As soon as I exit, t_te emits the app escape off code.

However, I run into a little bit of trouble when running vim inside of tmux. If I exit Vim in a window, the app escape mode OFF is sent--then switching to another running window with ViM ALREADY running causes issues since app escape mode is off and ESC key won't generate the special \eO[ code.

I was thinking of a simple manual step to just emit App Escape Mode ON keycode (using F6) whenever I find ESC not working properly.

_How_:
..... half-way through writing this post I realized a simple fix .... If I execute any SHELL command from within VIM (e.g: :!echo "hellooo"), Vim will run the script and then regain control. What I just realized is that when Vim regains control--it'll emit whatever is in &t_ti --which includes my App Escape Mode ON.

Anyway, for the sake of argument is there a Vim one liner that emits terminal keycodes from INSIDE Vim (without running an external script)?


See the following links for more info:

Hayaki Saito

unread,
Sep 15, 2013, 1:46:28 AM9/15/13
to vim...@googlegroups.com, v...@vim.org
Hi,

I usually use app escape mode, too.
I hope this smart feature becomes widespread.

By the way, I may be able to answer your question if I don’t misunderstand it.
I always send raw sequence to the terminal by the following way.

:call writefile(["\e[?7727h"], '/dev/tty', 'b’)

This is equivalent to:

:call system(‘echo -en “\e[?7727h” > /dev/tty’)

if vim runs in tmux session, we need to call as follows,

:call writefile(["\ePtmux;\e\e[?7727h\e\\"], '/dev/tty', 'b’)

-- Hayaki Saito


2013/09/15 7:14、Saad Malik <saam...@gmail.com> のメール:
> --
> --
> 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+u...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

Saad Malik

unread,
Sep 16, 2013, 1:28:04 PM9/16/13
to vim...@googlegroups.com, v...@vim.org
On Saturday, September 14, 2013 10:46:28 PM UTC-7, Hayaki Saito wrote:
> Hi,
>
>
>
> I usually use app escape mode, too.
>
> I hope this smart feature becomes widespread.
>
>
>
> By the way, I may be able to answer your question if I don’t misunderstand it.
>
> I always send raw sequence to the terminal by the following way.
>
>
>
> :call writefile(["\e[?7727h"], '/dev/tty', 'b’)
>
>
>
> This is equivalent to:
>
>
>
> :call system(‘echo -en “\e[?7727h” > /dev/tty’)
>
>
>
> if vim runs in tmux session, we need to call as follows,
>
>
>
> :call writefile(["\ePtmux;\e\e[?7727h\e\\"], '/dev/tty', 'b’)
>
>
>
> -- Hayaki Saito
>
>
>
>
>
> 2013/09/15 7:14、Saad Malik <s...@gmail.com> のメール:
Thank you Hayaki. That's exactly what I was looking for. Do you bind the new escape sequence like this?

noremap <Esc>O[ <Esc>
noremap! <Esc>O[ <C-c>

Also, when you abort a single letter replace: (hit ESC on a 'r' normal command), is there a '[' on the line above? Presumably because 'r' eats up the ESC but the O[ is inserts the character [ on the line above. This doesn't bother me a whole lot, but did you figure out a way to fix this?

Saad Malik

unread,
Sep 16, 2013, 1:31:07 PM9/16/13
to vim...@googlegroups.com, v...@vim.org
Ooops I apologize for including the entire post in the reply.
Reply all
Reply to author
Forward
0 new messages