summaryrefslogtreecommitdiffstats
path: root/runtime/doc/term.txt
blob: 1256d750d2af23217a3ec78a7753d210cfcce745 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
*term.txt*      For Vim version 9.1.  Last change: 2024 Apr 14


		  VIM REFERENCE MANUAL    by Bram Moolenaar


Terminal information					*terminal-info*

Vim uses information about the terminal you are using to fill the screen and
recognize what keys you hit.  If this information is not correct, the screen
may be messed up or keys may not be recognized.  The actions which have to be
performed on the screen are accomplished by outputting a string of
characters.  Special keys produce a string of characters.  These strings are
stored in the terminal options, see |terminal-options|.

NOTE: Most of this is not used when running the |GUI|.

1. Startup			|startup-terminal|
2. Terminal options		|terminal-options|
3. Window size			|window-size|
4. Slow and fast terminals	|slow-fast-terminal|
5. Using the mouse		|mouse-using|

==============================================================================
1. Startup						*startup-terminal*

When Vim is started a default terminal type is assumed.  For the Amiga this is
a standard CLI window, for MS-Windows the pc terminal, for Unix an ansi
terminal.  A few other terminal types are always available, see below
|builtin-terms|.

You can give the terminal name with the '-T' Vim argument.  If it is not given
Vim will try to get the name from the TERM environment variable.

				*termcap* *terminfo* *E557* *E558* *E559*
On Unix the terminfo database or termcap file is used.  This is referred to as
"termcap" in all the documentation.  At compile time, when running configure,
the choice whether to use terminfo or termcap is done automatically.  When
running Vim the output of ":version" will show |+terminfo| if terminfo is
used.  Also see |xterm-screens|.

On non-Unix systems a termcap is only available if Vim was compiled with
TERMCAP defined.

					*builtin-terms* *builtin_terms*
A number of builtin terminals are available.  Since patch 9.0.0280 there is no
difference between Vim versions.  You can see a list of available builtin
terminals in the error message you get for `:set term=xxx` (when not running
the GUI).  Also see |++builtin_terms|.

If the termcap code is included Vim will try to get the strings for the
terminal you are using from the termcap file and the builtin termcaps.  Both
are always used, if an entry for the terminal you are using is present.  Which
one is used first depends on the 'ttybuiltin' option:

'ttybuiltin' on		1: builtin termcap	2: external termcap
'ttybuiltin' off	1: external termcap	2: builtin termcap

If an option is missing in one of them, it will be obtained from the other
one.  If an option is present in both, the one first encountered is used.

Which external termcap file is used varies from system to system and may
depend on the environment variables "TERMCAP" and "TERMPATH".  See "man
tgetent".

Settings depending on terminal			*term-dependent-settings*

If you want to set options or mappings, depending on the terminal name, you
can do this best in your .vimrc.  Example: >

   if &term == "xterm"
     ... xterm maps and settings ...
   elseif &term =~ "vt10."
     ... vt100, vt102 maps and settings ...
   endif
<
						*raw-terminal-mode*
For normal editing the terminal will be put into "raw" mode.  The strings
defined with 't_ti', 't_TI' and 't_ks' will be sent to the terminal.  Normally
this puts the terminal in a state where the termcap codes are valid and
activates the cursor and function keys.
When Vim exits the terminal will be put back into the mode it was before Vim
started.  The strings defined with 't_te', 't_TE' and 't_ke' will be sent to
the terminal.  On the Amiga, with commands that execute an external command
(e.g., "!!"), the terminal will be put into Normal mode for a moment.  This
means that you can stop the output to the screen by hitting a printing key.
Output resumes when you hit <BS>.

Note: When 't_ti' is not empty, Vim assumes that it causes switching to the
alternate screen.  This may slightly change what happens when executing a
shell command or exiting Vim.  To avoid this use 't_TI' and 't_TE' (but make
sure to add to them, not overwrite).

Vim will try to detect what keyboard protocol the terminal is using with the
't_RK' termcap entry.  This is sent after 't_TI', but only when there is no
work to do (no typeahead and no pending commands).  That is to avoid the
response to end up in a shell command or arrive after Vim exits.

						*xterm-bracketed-paste*
When the 't_BE' option is set then 't_BE' will be sent to the
terminal when entering "raw" mode and 't_BD' when leaving "raw" mode.  The
terminal is then expected to put 't_PS' before pasted text and 't_PE' after
pasted text.  This way Vim can separate text that is pasted from characters
that are typed.  The pasted text is handled like when the middle mouse button
is used, it is inserted literally and not interpreted as commands.

Please note: while bracketed paste is trying to prevent nasty side-effects
from pasting (like the CTRL-C or <ESC> key), it's not a guaranteed security
measure because different terminals may implement this mode slightly
differently.  You should still be careful with what you paste into Vim.

When the cursor is in the first column, the pasted text will be inserted
before it.  Otherwise the pasted text is appended after the cursor position.
This means one cannot paste after the first column.  Unfortunately Vim does
not have a way to tell where the mouse pointer was.

Note that in some situations Vim will not recognize the bracketed paste and
you will get the raw text.  In other situations Vim will only get the first
pasted character and drop the rest, e.g. when using the "r" command.  If you
have a problem with this, disable bracketed paste by putting this in your
.vimrc: >
	set t_BE=
If this is done while Vim is running the 't_BD' will be sent to the terminal
to disable bracketed paste.

If |t_PS| or |t_PE| is not set, then |t_BE| will not be used.  This is to make
sure that bracketed paste is not enabled when the escape codes surrounding
pasted text cannot be recognized.

Note: bracketed paste mode will be disabled, when the 'esckeys' option is not
set (also when the 'compatible' option is set).

If your terminal supports bracketed paste, but the options are not set
automatically, you can try using something like this: >

	if &term =~ "screen"
	  let &t_BE = "\e[?2004h"
	  let &t_BD = "\e[?2004l"
	  exec "set t_PS=\e[200~"
	  exec "set t_PE=\e[201~"
	endif

The terminfo entries "BE", "BD", "PS" and "PE" were added in ncurses version
6.4, early 2023, for some terminals.  If you have this version then you may
not have to manually configure your terminal.

							*tmux-integration*
If you experience issues when running Vim inside tmux, here are a few hints.
You can comment-out parts if something doesn't work (it may depend on the
terminal that tmux is running in): >

    if !has('gui_running') && &term =~ '^\%(screen\|tmux\)'
        " Better mouse support, see  :help 'ttymouse'
        set ttymouse=sgr

        " Enable true colors, see  :help xterm-true-color
        let &termguicolors = v:true
        let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
        let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"

        " Enable bracketed paste mode, see  :help xterm-bracketed-paste
        let &t_BE = "\<Esc>[?2004h"
        let &t_BD = "\<Esc>[?2004l"
        let &t_PS = "\<Esc>[200~"
        let &t_PE = "\<Esc>[201~"

        " Enable focus event tracking, see  :help xterm-focus-event
        let &t_fe = "\<Esc>[?1004h"
        let &t_fd = "\<Esc>[?1004l"
	execute "set <FocusGained>=\<Esc>[I"
        execute "set <FocusLost>=\<Esc>[O"

        " Enable modified arrow keys, see  :help arrow_modifiers
        execute "silent! set <xUp>=\<Esc>[@;*A"
        execute "silent! set <xDown>=\<Esc>[@;*B"
        execute "silent! set <xRight>=\<Esc>[@;*C"
        execute "silent! set <xLeft>=\<Esc>[@;*D"
    endif
<
							*cs7-problem*
Note: If the terminal settings are changed after running Vim, you might have
an illegal combination of settings.  This has been reported on Solaris 2.5
with "stty cs8 parenb", which is restored as "stty cs7 parenb".  Use
"stty cs8 -parenb -istrip" instead, this is restored correctly.

Some termcap entries are wrong in the sense that after sending 't_ks' the
cursor keys send codes different from the codes defined in the termcap.  To
avoid this you can set 't_ks' (and 't_ke') to empty strings.  This must be
done during initialization (see |initialization|), otherwise it's too late.

Some termcap entries assume that the highest bit is always reset.  For
example: The cursor-up entry for the Amiga could be ":ku=\E[A:".  But the
Amiga really sends "\233A".  This works fine if the highest bit is reset,
e.g., when using an Amiga over a serial line.  If the cursor keys don't work,
try the entry ":ku=\233A:".

Some termcap entries have the entry ":ku=\E[A:".  But the Amiga really sends
"\233A".  On output "\E[" and "\233" are often equivalent, on input they
aren't.  You will have to change the termcap entry, or change the key code with
the :set command to fix this.

Many cursor key codes start with an <Esc>.  Vim must find out if this is a
single hit of the <Esc> key or the start of a cursor key sequence.  It waits
for a next character to arrive.  If it does not arrive within one second a
single <Esc> is assumed.  On very slow systems this may fail, causing cursor
keys not to work sometimes.  If you discover this problem reset the 'timeout'
option.  Vim will wait for the next character to arrive after an <Esc>.  If
you want to enter a single <Esc> you must type it twice.  Resetting the
'esckeys' option avoids this problem in Insert mode, but you lose the
possibility to use cursor and function keys in Insert mode.

On the Amiga the recognition of window resizing is activated only when the
terminal name is "amiga" or "builtin_amiga".

Some terminals have confusing codes for the cursor keys.  The televideo 925 is
such a terminal.  It sends a CTRL-H for cursor-left.  This would make it
impossible to distinguish a backspace and cursor-left.  To avoid this problem
CTRL-H is never recognized as cursor-left.

					*vt100-cursor-keys* *xterm-cursor-keys*
Other terminals (e.g., vt100 and xterm) have cursor keys that send <Esc>OA,
<Esc>OB, etc.  Unfortunately these are valid commands in insert mode: Stop
insert, Open a new line above the new one, start inserting 'A', 'B', etc.
Instead of performing these commands Vim will erroneously recognize this typed
key sequence as a cursor key movement.  To avoid this and make Vim do what you
want in either case you could use these settings: >
	:set notimeout		" don't timeout on mappings
	:set ttimeout		" do timeout on terminal key codes
	:set timeoutlen=100	" timeout after 100 msec
This requires the key-codes to be sent within 100 msec in order to recognize
them as a cursor key.  When you type you normally are not that fast, so they
are recognized as individual typed commands, even though Vim receives the same
sequence of bytes.

				*vt100-function-keys* *xterm-function-keys*
An xterm can send function keys F1 to F4 in two modes: vt100 compatible or
not.  Because Vim may not know what the xterm is sending, both types of keys
are recognized.  The same happens for the <Home> and <End> keys.
			normal			vt100 ~
	<F1>	t_k1	<Esc>[11~	<xF1>	<Esc>OP	    *<xF1>-xterm*
	<F2>	t_k2	<Esc>[12~	<xF2>	<Esc>OQ	    *<xF2>-xterm*
	<F3>	t_k3	<Esc>[13~	<xF3>	<Esc>OR	    *<xF3>-xterm*
	<F4>	t_k4	<Esc>[14~	<xF4>	<Esc>OS	    *<xF4>-xterm*
	<Home>	t_kh	<Esc>[7~	<xHome>	<Esc>OH	    *<xHome>-xterm*
	<End>	t_@7	<Esc>[4~	<xEnd>	<Esc>OF	    *<xEnd>-xterm*

When Vim starts, <xF1> is mapped to <F1>, <xF2> to <F2> etc.  This means that
by default both codes do the same thing.  If you make a mapping for <xF2>,
because your terminal does have two keys, the default mapping is overwritten,
thus you can use the <F2> and <xF2> keys for something different.

							*xterm-shifted-keys*
Newer versions of xterm support shifted function keys and special keys.  Vim
recognizes most of them.  Use ":set termcap" to check which are supported and
what the codes are.  Mostly these are not in a termcap, they are only
supported by the builtin_xterm termcap.

							*xterm-modifier-keys*
Newer versions of xterm support Alt and Ctrl for most function keys.  To avoid
having to add all combinations of Alt, Ctrl and Shift for every key a special
sequence is recognized at the end of a termcap entry: ";*X".  The "X" can be
any character, often '~' is used.  The ";*" stands for an optional modifier
argument.  ";2" is Shift, ";3" is Alt, ";5" is Ctrl and ";9" is Meta (when
it's different from Alt).  They can be combined.  Examples: >
	:set <F8>=^[[19;*~
	:set <Home>=^[[1;*H
Another speciality about these codes is that they are not overwritten by
another code.  That is to avoid that the codes obtained from xterm directly
|t_RV| overwrite them.

Another special value is a termcap entry ending in "@;*X".  This is for cursor
keys, which either use "CSI X" or "CSI 1 ; modifier X".  Thus the "@"
stands for either "1" if a modifier follows, or nothing.
							*arrow_modifiers*
Several terminal emulators (alacritty, gnome, konsole, etc.) send special
codes for keys with modifiers, but these do not have an entry in the
termcap/terminfo database.  You can make them work by adding a few lines in
your vimrc.  For example, to make the Control modifier work with arrow keys
for the gnome terminal: >
	if &term =~ 'gnome'
	   execute "set <xUp>=\<Esc>[@;*A"
	   execute "set <xDown>=\<Esc>[@;*B"
	   execute "set <xRight>=\<Esc>[@;*C"
	   execute "set <xLeft>=\<Esc>[@;*D"
	endif
<							*xterm-scroll-region*
The default termcap entry for xterm on Sun and other platforms does not
contain the entry for scroll regions.  Add ":cs=\E[%i%d;%dr:" to the xterm
entry in /etc/termcap and everything should work.

							*xterm-end-home-keys*
On some systems (at least on FreeBSD with XFree86 3.1.2) the codes that the
<End> and <Home> keys send contain a <Nul> character.  To make these keys send
the proper key code, add these lines to your ~/.Xdefaults