1
votes

I'm using Mac OS 10.13.4.

iTerm2 Version is Build 2.1.1

Vim Version is VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Nov 29 2017 18:37:46) Included patches: 1-503, 505-680, 682-1283 Compiled by [email protected]

And I Installed the Vundle plugin

And when I open vim in iTerm2 with oh-my-zsh, the $p appears at the first line. enter image description here

It doesn't appear with Terminal.app of Apple?

How to solve this problem?

4
There is no code here. This is not a programming question. Try superuser.com?melpomene
Actually it's a question about escape sequences, which is topical. vi.SE won't offer a better answer.Thomas Dickey

4 Answers

2
votes

vim is assuming that iTerm2 is xterm (not a good assumption), and attempting to determine the state of the cursorBlink resource by sending an escape sequence containing $p which iTerm2 does not handle properly (see source-code for vim for the escape sequence, and also where it uses the feature). While vim starts with the TERM setting (i.e., "xterm"), it does make a few checks to exclude things like gnome-terminal as noted in the source code comment. But iTerm2 happens to fool vim in this case. So the result goes to the screen.

In XTerm Control Sequences that is documented like this:

CSI ? Ps$ p
          Request DEC private mode (DECRQM).  For VT300 and up, reply is
            CSI ? Ps; Pm$ y
          where Ps is the mode number as in DECSET/DECSET, Pm is the
          mode value as in the ANSI DECRQM.
          Two private modes are read-only (i.e., 1 3  and 1 4 ), pro-
          vided only for reporting their values using this control
          sequence.  They correspond to the resources cursorBlink and
          cursorBlinkXOR.

Although vim is fooled here, the problem is due to iTerm2, for which you've probably set the TERM environment variable to xterm-256color, or something like that. It doesn't match iTerm2's behavior very well (the function keys don't match up, etc). ncurses provides a better one. But out-of-the-box MacOS has a terminal database that's about ten years old, and lacks that entry. To get a good terminal database (i.e., one where you could set TERM to iterm2), you could do that with MacPorts or home-brew.

Running infocmp to get a measure of the differences between the (correct) iterm2 entry and linux, xterm-256color shows that

  • it's actually closer to nsterm-256color (a correct entry for Terminal.app which Apple doesn't provide) with 38 lines of difference,
  • next closest linux with 76 lines and
  • still further away from xterm-256color with 94 lines.

The feature that's missing or mis-implemented in iTerm2 isn't in the terminal description: it's a special feature that vim has to guess about.

2
votes

As mentioned above, this $p is due to vim sending a control sequence for a cursor blink request. In your .vimrc, you can turn off the cursor blink request by clearing the t_RC terminal option. I wrapped this in a conditional which turns it off only for 256 color terminals.

if &term =~ '256color'
  set t_RC=
endif
0
votes

Setting the terminal explicitly to linux solved it for me: export TERM=linux

-1
votes

The p means print, which is the command the range is being given to, and yes.. it displays to you what is in that range.

In vim you can look at :help :range and :help :print to find out more about how this works. These types of ranges are also used by sed and other editors.

They probably used the 1,$ terminology in the tutorial to be explicit, but note that you can also use % as its equivalent. Thus, %p will also print all the lines in the file.