Cursor shape in the console

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Cursor shape in the console

Tony Mechelynck
In konsole 18.12.3, in a Big build of Vim (currently 8.1.1407) with
'ttybuiltin' on and 'term' set to "xterm-256color", ":set termcap"
tells me that t_SI, t_SR and t_EI are all unset, which explains why in
Console mode (i.e. invoked as "vim", "view", "vimdiff" etc., not
"gvim", "gview", "gvimdiff" etc.) the cursor never changes, it is
always a block. Is it possible (and how) to make the cursor become a
vertical bar when in Insert mode and an underscore in Replace mode
(while remaining a block in Normal mode)? ":help termcap-cursor-shape"
(which coincides with ":help termcap-cursor-color") actually gives an
example about how to change the cursor colour but not its shape but it
hints at how to do it… if only I knew the correct xterm bytecode to
make the cursor a block, a vertical bar or an underscore.

BTW, I couldn't find the required info in "man xterm" except maybe at
the very end where it says that xterm control sequences are described
by the file http://invisible-island.net/xterm/ctlseqs/ctlseqs.html
…where I couldn't find where to look for the desired information. I
guess I've been corrupted by the clear and full online help provided
by Vim, I get lost in the ordinary, badly-written and confusing
manpages. ;-)

Best regards,
Tony.

--
--
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].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CAJkCKXtPehhyQhTARoDhkwF%3DzfE%3DkHPnms9gCz9obvLtTPfVHA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Cursor shape in the console

Rob Foehl
On Mon, 27 May 2019, Tony Mechelynck wrote:

> if only I knew the correct xterm bytecode to
> make the cursor a block, a vertical bar or an underscore.

Hi Tony,

Here's what I use for real xterm, and covering a pretty good span of Vim
releases (including those predating t_SR):

if has('cursorshape') && &term =~ '^xterm'
  " Use a bar cursor in Insert mode

  let &t_SI = "\<Esc>[6 q"

  " Use a block cursor in Normal mode, and restore at Vim exit

  let &t_EI = "\<Esc>[2 q"
  let &t_te = &t_EI . substitute(&t_te, '\C' . &t_EI, '', 'g')

  " Use t_SR for an underline cursor in Replace mode, if available (Vim
  " 7.4.687 or newer); otherwise, change the value of t_SI when entering
  " Insert or Replace mode, as appropriate.

  if exists('&t_SR')
   let &t_SR = "\<Esc>[4 q"
  else
   autocmd vimrc InsertChange,InsertEnter *
   \ if v:insertmode == 'r' || v:insertmode == 'v' |
   \  let &t_SI = "\<Esc>[4 q" |
   \ else |
   \  let &t_SI = "\<Esc>[6 q" |
   \ endif
  endif
endif


Those are the non-blinking variants in xterm.  You'll probably need to
adjust that for non-xterm; there's a Vim wiki page[1] that suggests other
sequences for Konsole.  Also note the &term test at the beginning.

-Rob


[1] https://vim.fandom.com/wiki/Change_cursor_shape_in_different_modes

--
--
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].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/alpine.LFD.2.21.1905280029540.2350%40bugs.loonybin.net.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Cursor shape in the console

Tony Mechelynck
On Tue, May 28, 2019 at 6:36 AM Rob Foehl <[hidden email]> wrote:

>
> On Mon, 27 May 2019, Tony Mechelynck wrote:
>
> > if only I knew the correct xterm bytecode to
> > make the cursor a block, a vertical bar or an underscore.
>
> Hi Tony,
>
> Here's what I use for real xterm, and covering a pretty good span of Vim
> releases (including those predating t_SR):
>
> if has('cursorshape') && &term =~ '^xterm'
>   " Use a bar cursor in Insert mode
>
>   let &t_SI = "\<Esc>[6 q"
>
>   " Use a block cursor in Normal mode, and restore at Vim exit
>
>   let &t_EI = "\<Esc>[2 q"
>   let &t_te = &t_EI . substitute(&t_te, '\C' . &t_EI, '', 'g')
>
>   " Use t_SR for an underline cursor in Replace mode, if available (Vim
>   " 7.4.687 or newer); otherwise, change the value of t_SI when entering
>   " Insert or Replace mode, as appropriate.
>
>   if exists('&t_SR')
>    let &t_SR = "\<Esc>[4 q"
>   else
>    autocmd vimrc InsertChange,InsertEnter *
>    \ if v:insertmode == 'r' || v:insertmode == 'v' |
>    \  let &t_SI = "\<Esc>[4 q" |
>    \ else |
>    \  let &t_SI = "\<Esc>[6 q" |
>    \ endif
>   endif
> endif
>
>
> Those are the non-blinking variants in xterm.  You'll probably need to
> adjust that for non-xterm; there's a Vim wiki page[1] that suggests other
> sequences for Konsole.  Also note the &term test at the beginning.
>
> -Rob
>
>
> [1] https://vim.fandom.com/wiki/Change_cursor_shape_in_different_modes

Thanks, I'll try those sequences. For the Linux non-X11 console (where
$TERM is "linux") it's probably hopeless indeed, and I'll add an "if
!has("gui_running") around the whole stuff because in gvim it already
works. It would probably still work without it, because starting the
GUI sets 'term' to "builtin_gui" and changes the whole termcap, but I
don't need to add unnecessary processing for the short time between
sourcing the vimrc and starting the GUI.

If the codes for "real xterm" don't work in konsole, AFAIK I'll have
to place the whole stuff at the TermResponse event (which is fired in
both), because in konsole I have a $TERM starting with xterm but a
different v:termresponse (ESC [>0;115;0c in konsole but ESC
[>41;330;0c in xterm, IOW konsole tries to emulate xterm in vt100 but
I don't know what "terminal type 41" means in a real xterm). I notice
that in both cases, and contrary to what is said at ":help
v:termresponse", the first character after ESC [ is a greater-than
sign which is none of a digit, semicolon or period.

To restore the block cursor at Vim exit I suppose it is enough to use
(not yet tested)
        au VimLeave * exe "normal \<C-\\>\<C-N>"
to put Vim in Normal mode; however "leaving Vim normally" is by means
of a :qa or :xa command, which is started from Normal mode and leaves
Vim in it so that autocommand would only matter for "abnormal exits".

Best regards,
Tony.

--
--
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].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CAJkCKXuWHczvfZ8yPn7h%2BOODe%3DyxXyWzPmbhjjGFTbTVc5D%3DrA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Cursor shape in the console

Tony Mechelynck
The following works in xterm. I'm investigating further for konsole:

" try to change cursor shape in Console mode in xterm-like terminals
" ESC [2 q = █ (Normal)
" ESC [4 q = _ (Replace)
" ESC [6 q = | (Insert)
" ESC [5m = blink (all modes)
if !has('gui_running') && has('termresponse') && has('cursorshape') &&
has('autocmd')
  func CursorU(mode)
    if a:mode == 'r' || a:mode == 'v'
      let &t_SI = "\<ESC>[4 q"
    else
      let &t_SI = "\<Esc>[6 q"
    endif
  endfunc
  augroup consCursor
  au TermResponse *
  \  if &t_EI == '' | let &t_EI = "\<Esc>[2 q" | endif
  \| if &t_SI == '' | let &t_SI = "\<Esc>[6 q" | endif
  \| if exists('&t_SR')
    \| if &t_SR == '' | let &t_SR = "\<Esc>[4 q" | endif
  \| else
    \| au InsertChange,InsertEnter * call CursorU(v:insertmode)
  \| endif
  au VimLeave exe "normal \<C-\\>\<C-N>"
  augroup END
endif


Best regards,
Tony.

--
--
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].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CAJkCKXu9Ugjs44MCRu1c_7PSo5%3Dyg%3DJn7AX3y0Ezp1HzFe6w_w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Cursor shape in the console

Tony Mechelynck
This simpler version works in konsole but does nothing in xterm and in
the Linux console. I haven't found how to make it work in both konsole
and xterm but I'm giving up, I don't use Vim in xterm that much. Also
I left out the test on exists('&t_SR') because I on't use Vim 7 (or
earlier) anymore at all.

if !has('gui_running') && has('cursorshape')
  let &t_EI = "\<Esc>]50;CursorShape=0\x7"
  let &t_SI = "\<Esc>]50;CursorShape=1\x7"
  let &t_SR = "\<Esc>]50;CursorShape=2\x7"
endif


Best regards,
Tony.

--
--
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].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CAJkCKXsSHBfnLvF51N_xTMUXtcZqU%3Dk1cM79U7q%3D3wTC%3Dcev7A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Cursor shape in the console

tooth pik
On Tue, May 28, 2019 at 4:31 PM Tony Mechelynck
<[hidden email]> wrote:

>
> This simpler version works in konsole but does nothing in xterm and in
> the Linux console. I haven't found how to make it work in both konsole
> and xterm but I'm giving up, I don't use Vim in xterm that much. Also
> I left out the test on exists('&t_SR') because I on't use Vim 7 (or
> earlier) anymore at all.
>
> if !has('gui_running') && has('cursorshape')
>   let &t_EI = "\<Esc>]50;CursorShape=0\x7"
>   let &t_SI = "\<Esc>]50;CursorShape=1\x7"
>   let &t_SR = "\<Esc>]50;CursorShape=2\x7"
> endif


cool beans tony, thanx!  i didn't know terminal vim in konsole could do that!

tp

--
--
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].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CALfSX1xu8h70MZzidiPtknqGBOk%3DbQxLQzJb9HZm3Ft1j%2B26kA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Cursor shape in the console

Tony Mechelynck
On Tue, May 28, 2019 at 11:43 PM tooth pik <[hidden email]> wrote:
[...]
> cool beans tony, thanx!  i didn't know terminal vim in konsole could do that!
>
> tp

I pasted this code from the wiki page linked to by Rob Foehl in his
answer above; in that same wiki page you'll find escape sequences for
various kinds of terminal emulators. What I haven't found is how to
fashion a well-thought-of conditional statement to change the cursor
shape the right way in various incompatible terminals while using a
single vimrc.

Best regards,
Tony.

--
--
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].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CAJkCKXtZWXvwb75M8Mu8aAkVfve00DDQoMiKTAf7i7NtxBPyfA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Cursor shape in the console

John Little-4
In reply to this post by Tony Mechelynck
On Wednesday, May 29, 2019 at 9:31:17 AM UTC+12, Tony Mechelynck wrote:
> ... I haven't found how to make it work in both konsole
> and xterm ...

I use the XTERM_VERSION environment variable.  xterm defines it, konsole doesn't.

Note that if xterm is started with -bc for a blinking cursor, the effects of the 5 and 6 are reversed, so that 5 is steady and 6 blinking.

Also, I sometimes use the "Set Text Parameters" sequence to change the colour of the cursor; so

if $XTERM_VERSION =~? "xterm"
    let &t_SI = "\<Esc>]12;green\x7"
    let &t_EI = "\<Esc>]12;red\x7"
endif

--
--
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].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/070410f8-649c-464c-8153-1d8bc22b77bb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Cursor shape in the console

Tony Mechelynck
On Fri, May 31, 2019 at 6:45 AM John Little <[hidden email]> wrote:
>
> On Wednesday, May 29, 2019 at 9:31:17 AM UTC+12, Tony Mechelynck wrote:
> > ... I haven't found how to make it work in both konsole
> > and xterm ...
>
> I use the XTERM_VERSION environment variable.  xterm defines it, konsole doesn't.

Ah, interesting. Yes, indeed, in bash in xterm, "echo $XTERM_VERSION"
answers Xterm(330) but in konsole the answer is empty. Thanks!
>
> Note that if xterm is started with -bc for a blinking cursor, the effects of the 5 and 6 are reversed, so that 5 is steady and 6 blinking.

IOW, if the cursor is blinking in bash in xterm, with the "even" codes
it wil remain blinking in Vim.

Thanks to you, my problem is solved in both xterm and konsole, with
the folowing code:

" try to change cursor shape in Console mode in xterm-like terminals
" t_EI = █ (Normal)
" t_SR = _ (Replace)
" t_SI = | (Insert)
if !has('gui_running') && has('cursorshape')
  if $XTERM_VERSION =~? '^xterm'  " a «real» xterm
    let &t_EI = "\<Esc>[2 q"
    let &t_SI = "\<Esc>[6 q"
    let &t_SR = "\<Esc>[4 q"
  else                            " assume konsole
    let &t_EI = "\<Esc>]50;CursorShape=0\x7"
    let &t_SI = "\<Esc>]50;CursorShape=1\x7"
    let &t_SR = "\<Esc>]50;CursorShape=2\x7"
  endif
endif


Best regards,
Tony.

--
--
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].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CAJkCKXu9Frb-5nYQkFg6BEmrfh%3D4Ov%2BkLJV5Hwnp5_d6M%2BZ0Sw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.