Skip to main content
added 626 characters in body
Source Link
qeatzy
  • 968
  • 9
  • 18

vim 8 support terminal, and has a api to let command in terminal to communicate back to vim.

For example:

In vim, define function like

" .vimrc
let g:cnt = get(g:, 'cnt', 0)
func! Tapi_Command_finish(bufnum, arglist) abort
    let g:cnt += 1
endfunc " Tapi_Command_finish

open a terminal buffer, run command

printf '\033]51;["call","Tapi_%s", ["%s"]]\007' Command_finish

then go back to vim, :echo g:cnt, 1 will be echoed, demonstrate function Tapi_Command_finish being called.

This works in linux, but when i tried on windows gvim 8, it did not work.

I search around, some say cmd do not support ansi escape sequence. (not sure if \033]51... is ansi escape sequence or not.)

The question:

Is there a way to use terminal api on windows gvim?

== EDIT == (The echo part)

Below are 3 ways I can thought of to reproduce the echo part.

  • 1 cat file approach

under posix shell, eg, cygwin

printf '\033]51;["call","Tapi_%s", ["%s"]]\007' Command_finish > xx

and cp or scp to current directory. then in terminal buffer

type xx
  • 2 use python

create file yy.py, with content

print('\033]51;["call","Tapi_%s", ["%s"]]\007' % ("Command_finish",""))

then in terminal buffer, run

python yy.py
  • 3 use echo

not tried, since I don't know how to reliably send '\033'.

Of the 3 ways, both 1 & 2 works on cygwin.

vim 8 support terminal, and has a api to let command in terminal to communicate back to vim.

For example:

In vim, define function like

" .vimrc
let g:cnt = get(g:, 'cnt', 0)
func! Tapi_Command_finish(bufnum, arglist) abort
    let g:cnt += 1
endfunc " Tapi_Command_finish

open a terminal buffer, run command

printf '\033]51;["call","Tapi_%s", ["%s"]]\007' Command_finish

then go back to vim, :echo g:cnt, 1 will be echoed, demonstrate function Tapi_Command_finish being called.

This works in linux, but when i tried on windows gvim 8, it did not work.

I search around, some say cmd do not support ansi escape sequence. (not sure if \033]51... is ansi escape sequence or not.)

The question:

Is there a way to use terminal api on windows gvim?

vim 8 support terminal, and has a api to let command in terminal to communicate back to vim.

For example:

In vim, define function like

" .vimrc
let g:cnt = get(g:, 'cnt', 0)
func! Tapi_Command_finish(bufnum, arglist) abort
    let g:cnt += 1
endfunc " Tapi_Command_finish

open a terminal buffer, run command

printf '\033]51;["call","Tapi_%s", ["%s"]]\007' Command_finish

then go back to vim, :echo g:cnt, 1 will be echoed, demonstrate function Tapi_Command_finish being called.

This works in linux, but when i tried on windows gvim 8, it did not work.

I search around, some say cmd do not support ansi escape sequence. (not sure if \033]51... is ansi escape sequence or not.)

The question:

Is there a way to use terminal api on windows gvim?

== EDIT == (The echo part)

Below are 3 ways I can thought of to reproduce the echo part.

  • 1 cat file approach

under posix shell, eg, cygwin

printf '\033]51;["call","Tapi_%s", ["%s"]]\007' Command_finish > xx

and cp or scp to current directory. then in terminal buffer

type xx
  • 2 use python

create file yy.py, with content

print('\033]51;["call","Tapi_%s", ["%s"]]\007' % ("Command_finish",""))

then in terminal buffer, run

python yy.py
  • 3 use echo

not tried, since I don't know how to reliably send '\033'.

Of the 3 ways, both 1 & 2 works on cygwin.

Source Link
qeatzy
  • 968
  • 9
  • 18

terminal api not working on gvim

vim 8 support terminal, and has a api to let command in terminal to communicate back to vim.

For example:

In vim, define function like

" .vimrc
let g:cnt = get(g:, 'cnt', 0)
func! Tapi_Command_finish(bufnum, arglist) abort
    let g:cnt += 1
endfunc " Tapi_Command_finish

open a terminal buffer, run command

printf '\033]51;["call","Tapi_%s", ["%s"]]\007' Command_finish

then go back to vim, :echo g:cnt, 1 will be echoed, demonstrate function Tapi_Command_finish being called.

This works in linux, but when i tried on windows gvim 8, it did not work.

I search around, some say cmd do not support ansi escape sequence. (not sure if \033]51... is ansi escape sequence or not.)

The question:

Is there a way to use terminal api on windows gvim?