Tuesday, May 28, 2019

Re: Cursor shape in the console

On Tue, May 28, 2019 at 6:36 AM Rob Foehl <rwf@loonybin.net> 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 vim_use+unsubscribe@googlegroups.com.
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.

No comments:

Post a Comment