Tips on vim

VIM Control Sequence Examples

When a user uses the control sequence, the remote host can control the Tera Term behavior. The VIM procedure for using the control sequence is described below.

Changing cursor shape on entering and leaving into insert mode

Tera Term can support below control sequence changing the cursor shape.

Abbreviation Sequence Function
DECTCEM ESC [ ? 25 h Makes the cursor visible
ESC [ ? 25 l Makes the cursor invisible
DECSCUSR ESC SP 0 q Blink Block
ESC SP 1 q Blink Block
ESC SP 2 q Steady Block
ESC SP 3 q Blink Underline
ESC SP 4 q Steady Underline
ESC SP 5 q Blink Vertical line
ESC SP 6 q Steady Vertical line
WYSTCURM ESC [ 33 h Steady Wyse Cursor
ESC [ 33 l Blink Wyse Cursor
WYULCURM ESC [ 34 h Steady Wyse underline cursor
ESC [ 34 l Steady Wyse block cursor
(AT&T 610) ESC [ ? 12 l Steady Cursor
ESC [ ? 12 h Blink Cursor

The vim cursor can be changed in the insert mode to output above control sequences when a user enters(t_SI) and leaves(t_EI).
For example, when below contents is added in the .vimrc file, the cursor style is underline and blinking in the insert mode. Next, the cursor style is block and blinking outside the insert mode.

let t_SI .= "\e[3 q"
let t_EI .= "\e[1 q"

NOTICE: If a user uses the control sequence except the DECTCEM, turn on the Cursor control sequence of the Additional Settings dialog(The default value is off).

Bracketed Paste Mode

Auto indent can be disabled on pasting from clipboard

Basically, the host application can not recognize the difference between the user input and pasting from clipboard. However, when a user uses the Bracketed Paste Mode as the xterm extension, the application can recognize its difference and a user can change the behavior of pasting from clipboard.

The vim configuration is described below. The following will use xterm's bracketed paste mode to make pasting automatically enable paste mode and insert mode. Also works fine in ~/.vimrc file.

if &term == "xterm"
  let &t_ti .= "\e[?2004h"
  let &t_te .= "\e[?2004l"
  let &pastetoggle = "\e[201~"

  function XTermPasteBegin(ret)
    set paste
    return a:ret
  endfunction

  map <special> <expr> <Esc>[200~ XTermPasteBegin("0i")
  imap <special> <expr> <Esc>[200~ XTermPasteBegin("")
  cmap <special> <Esc>[200~ <nop>
  cmap <special> <Esc>[201~ <nop>
endif

Bracketed Paste mode

The bracketed paste mode is the xterm extension feature. When this feature is enabled, the pasted text is bracketed with control sequences so that the program can differentiate the pasted text from typed-in text.
The program will receive: ESC [ 200 ~, followed by the pasted text, followed by ESC [ 201 ~.

Controlling IME

Tera Term can support the original sequence to control the IME behavior. For example, A user can switch the IME status of enabling and disabling to use this control sequence.

When below contents is be added in the .vimrc file, the IME status is off after the insert mode exiting. Next, the IME status is on after the insert mode enabling.

let &t_SI .= "\e[<r"
let &t_EI .= "\e[<s\e[<0t"
let &t_te .= "\e[<0t\e[<s"

NOTICE: You are recommended to configure the Delete wait time after ESC key is pushed in insert mode.

Delete wait time after ESC key is pushed in insert mode

When the ESC key is pressed, Tera Term, xterm and other terminal emulator send the ESC(0x1b) key code. Also, when the cursor key and the function key is pushed, Tera Term sends the ESC key code. Therefore, the host application can not recognize whether the ESC key is pressed.
So, the vim waits for one second when the ESC key code is received to recognize what key is pressed. As a result, when a user presses the ESC key, the time for the insert mode exiting will be late for 1 second. This behavior can not be affected by enabling Changing cursor shape on entering and leaving into insert mode and Controlling IME.

Please use the Application Wheel Mode to resolve this problem. When below contents is added in the .vimrc file, the insert mode is quickly exited after the ESC key is pressed.

let &t_SI .= "\e[?7727h"
let &t_EI .= "\e[?7727l"
inoremap <special> <Esc>O[ <Esc>