2

I am experiencing a problem for which I have no idea where I can start the search to solve it.

When I go into insert mode and start writing something and then quit insert mode with <ESC> and then use k to go up a line, the cursor indeed moves up, but leaves a highlighted q where I inserted the last letter.

When being in normal mode and I use r to overwrite text, the letter below the cursor immediatly turns into a highlighted q and moves to the right. When I then press any key, the letter below the cursor is again turned into a highlighted q and the cursor move right again. From then on, all sorts of strange things happen, like jumping one line up etc.

Except of that, vim seems to behave normal.

I'd like to give more information on that, but I have no idea what could be interesting for this problem.

I am using the same .vimrc files as in other installations where I don't have this problem.

Interestingly, when I write a file with such highlighted qs and then go to the shell and cat such a file, the text is as I typed it.

2
  • 1
    No idea whether it's relevant/helpful, but what's the output of :verb set t_EI? and :verb set t_SR? ? Does it help if you execute :set t_EI= and :set t_SR=?
    – user786441
    Feb 13 '18 at 21:11
  • 1
    This is very relevant. Turns out that I added exactly these t_* thingies because of vim.wikia.com/wiki/Change_cursor_shape_in_different_modes, and today, I used vim in a console rather than in X, so I have to uncomment them again. What these t_* thingies exactly do, is beyond me. Feb 13 '18 at 21:56
4

It seems your issue comes from setting some terminal options, with sequences to change the shape of the cursor, in a terminal/console which doesn't support them. See :h terminal-options.

You can change the shape of the cursor by sending the right sequence to the xterm terminal (and others which support it too), sometimes called DECSCUSR. Not sure what the acronym means. Just a guess (no idea what the final R means):

Digital Equipment Corporation Set CUrsor Style

The general syntax of the sequence is described here:

CSI Ps SP q

Where:

  • CSI means Control Sequence Introducer, and is produced by the keys Esc [
  • Ps is a single numeric parameter
  • SP is a space

For example, to change the shape of the cursor to an underline, you can send the sequence Esc[4 q to the terminal:

$ printf '\e[4 q'

You can use this to change the shape of the cursor depending on the current mode. For example, Vim automatically sends the sequence stored in the terminal option t_SR when you enter replace mode (see :h t_SR). So, if you wanted the cursor to go from a block to an underline when you enter replace mode, you could set t_SR like this:

let &t_SR = "\e[4 q"

Then, when you leave replace mode (or insert mode), Vim sends the sequence assigned to the option t_EI (see :h t_EI). You can use this to restore the shape of the cursor:

let &t_EI = "\e[2 q"

Some plugins do this configuration automatically.

But for the configuration to work, you must be sure that the terminal understands/supports those sequences. I don't know a reliable way to programmatically detect whether a terminal supports a given sequence. I guess you have to make the experiment to be sure.

For example, on my machine, printf '\e[4 q' works in urxvt but not in xfce4-terminal. So I know that I shouldn't set a terminal option (t_xx) with the sequence "\e[4 q" in xfce4-terminal.

You have to wrap your settings with the right guard, whose purpose is to guess the identity of the terminal. Usually this involves looking at some shell environment variables, the most important one being $TERM. As an example, you could try something like this:

if !has('gui_running') && $TERM =~# '^\%(name1\|name2\|…\)'
    " write your settings here
endif

Replace name1, name2, … with the names of the terminals you're using (as reported by echo $TERM), and for which you know the sequences are supported.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.