blob: 789e44cd2596fca1237012b0587019a5617d1eea [file] [log] [blame]
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001" Test for edit functions
Bram Moolenaar215ba3b2019-11-06 15:07:07 +01002
Bram Moolenaareb992cb2017-03-09 18:20:16 +01003if exists("+t_kD")
4 let &t_kD="[3;*~"
5endif
Bram Moolenaareb992cb2017-03-09 18:20:16 +01006
Bram Moolenaar215ba3b2019-11-06 15:07:07 +01007source check.vim
Bram Moolenaarc174c2e2023-03-25 20:06:49 +00008source screendump.vim
Bram Moolenaareb992cb2017-03-09 18:20:16 +01009source view_util.vim
10
11" Needs to come first until the bug in getchar() is
12" fixed: https://groups.google.com/d/msg/vim_dev/fXL9yme4H4c/bOR-U6_bAQAJ
Bram Moolenaar1e115362019-01-09 23:01:02 +010013func Test_edit_00b()
Bram Moolenaareb992cb2017-03-09 18:20:16 +010014 new
15 call setline(1, ['abc '])
16 inoreabbr <buffer> h here some more
17 call cursor(1, 4)
18 " <c-l> expands the abbreviation and ends insertmode
19 call feedkeys(":set im\<cr> h\<c-l>:set noim\<cr>", 'tix')
20 call assert_equal(['abc here some more '], getline(1,'$'))
21 iunabbr <buffer> h
22 bw!
23endfunc
24
Bram Moolenaar1e115362019-01-09 23:01:02 +010025func Test_edit_01()
Bram Moolenaareb992cb2017-03-09 18:20:16 +010026 " set for Travis CI?
27 " set nocp noesckeys
28 new
Bram Moolenaareb992cb2017-03-09 18:20:16 +010029 " 1) empty buffer
30 call assert_equal([''], getline(1,'$'))
31 " 2) delete in an empty line
32 call feedkeys("i\<del>\<esc>", 'tnix')
33 call assert_equal([''], getline(1,'$'))
34 %d
35 " 3) delete one character
36 call setline(1, 'a')
37 call feedkeys("i\<del>\<esc>", 'tnix')
38 call assert_equal([''], getline(1,'$'))
39 %d
40 " 4) delete a multibyte character
Bram Moolenaar30276f22019-01-24 17:59:39 +010041 call setline(1, "\u0401")
42 call feedkeys("i\<del>\<esc>", 'tnix')
43 call assert_equal([''], getline(1,'$'))
44 %d
Bram Moolenaareb992cb2017-03-09 18:20:16 +010045 " 5.1) delete linebreak with 'bs' option containing eol
46 let _bs=&bs
47 set bs=eol
48 call setline(1, ["abc def", "ghi jkl"])
49 call cursor(1, 1)
50 call feedkeys("A\<del>\<esc>", 'tnix')
51 call assert_equal(['abc defghi jkl'], getline(1, 2))
52 %d
53 " 5.2) delete linebreak with backspace option w/out eol
54 set bs=
55 call setline(1, ["abc def", "ghi jkl"])
56 call cursor(1, 1)
57 call feedkeys("A\<del>\<esc>", 'tnix')
58 call assert_equal(["abc def", "ghi jkl"], getline(1, 2))
Bram Moolenaareb992cb2017-03-09 18:20:16 +010059 let &bs=_bs
60 bw!
61endfunc
62
Bram Moolenaar1e115362019-01-09 23:01:02 +010063func Test_edit_02()
Bram Moolenaareb992cb2017-03-09 18:20:16 +010064 " Change cursor position in InsertCharPre command
65 new
66 call setline(1, 'abc')
67 call cursor(1, 1)
68 fu! DoIt(...)
69 call cursor(1, 4)
70 if len(a:000)
71 let v:char=a:1
72 endif
73 endfu
74 au InsertCharPre <buffer> :call DoIt('y')
75 call feedkeys("ix\<esc>", 'tnix')
76 call assert_equal(['abcy'], getline(1, '$'))
77 " Setting <Enter> in InsertCharPre
78 au! InsertCharPre <buffer> :call DoIt("\n")
79 call setline(1, 'abc')
80 call cursor(1, 1)
81 call feedkeys("ix\<esc>", 'tnix')
82 call assert_equal(['abc', ''], getline(1, '$'))
83 %d
84 au! InsertCharPre
85 " Change cursor position in InsertEnter command
86 " 1) when setting v:char, keeps changed cursor position
87 au! InsertEnter <buffer> :call DoIt('y')
88 call setline(1, 'abc')
89 call cursor(1, 1)
90 call feedkeys("ix\<esc>", 'tnix')
91 call assert_equal(['abxc'], getline(1, '$'))
92 " 2) when not setting v:char, restores changed cursor position
93 au! InsertEnter <buffer> :call DoIt()
94 call setline(1, 'abc')
95 call cursor(1, 1)
96 call feedkeys("ix\<esc>", 'tnix')
97 call assert_equal(['xabc'], getline(1, '$'))
98 au! InsertEnter
99 delfu DoIt
100 bw!
101endfunc
102
Bram Moolenaar1e115362019-01-09 23:01:02 +0100103func Test_edit_03()
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100104 " Change cursor after <c-o> command to end of line
105 new
106 call setline(1, 'abc')
107 call cursor(1, 1)
108 call feedkeys("i\<c-o>$y\<esc>", 'tnix')
109 call assert_equal(['abcy'], getline(1, '$'))
110 %d
111 call setline(1, 'abc')
112 call cursor(1, 1)
113 call feedkeys("i\<c-o>80|y\<esc>", 'tnix')
114 call assert_equal(['abcy'], getline(1, '$'))
115 %d
116 call setline(1, 'abc')
117 call feedkeys("Ad\<c-o>:s/$/efg/\<cr>hij", 'tnix')
118 call assert_equal(['hijabcdefg'], getline(1, '$'))
119 bw!
120endfunc
121
Bram Moolenaar1e115362019-01-09 23:01:02 +0100122func Test_edit_04()
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100123 " test for :stopinsert
124 new
125 call setline(1, 'abc')
126 call cursor(1, 1)
127 call feedkeys("i\<c-o>:stopinsert\<cr>$", 'tnix')
128 call feedkeys("aX\<esc>", 'tnix')
129 call assert_equal(['abcX'], getline(1, '$'))
130 %d
131 bw!
132endfunc
133
Bram Moolenaar1e115362019-01-09 23:01:02 +0100134func Test_edit_05()
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100135 " test for folds being opened
136 new
137 call setline(1, ['abcX', 'abcX', 'zzzZ'])
138 call cursor(1, 1)
139 set foldmethod=manual foldopen+=insert
140 " create fold for those two lines
141 norm! Vjzf
142 call feedkeys("$ay\<esc>", 'tnix')
143 call assert_equal(['abcXy', 'abcX', 'zzzZ'], getline(1, '$'))
144 %d
145 call setline(1, ['abcX', 'abcX', 'zzzZ'])
146 call cursor(1, 1)
147 set foldmethod=manual foldopen-=insert
148 " create fold for those two lines
149 norm! Vjzf
150 call feedkeys("$ay\<esc>", 'tnix')
151 call assert_equal(['abcXy', 'abcX', 'zzzZ'], getline(1, '$'))
152 %d
153 bw!
154endfunc
155
Bram Moolenaar1e115362019-01-09 23:01:02 +0100156func Test_edit_06()
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100157 " Test in diff mode
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200158 CheckFeature diff
159 CheckExecutable diff
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100160 new
161 call setline(1, ['abc', 'xxx', 'yyy'])
162 vnew
163 call setline(1, ['abc', 'zzz', 'xxx', 'yyy'])
164 wincmd p
165 diffthis
166 wincmd p
167 diffthis
168 wincmd p
169 call cursor(2, 1)
170 norm! zt
171 call feedkeys("Ozzz\<esc>", 'tnix')
172 call assert_equal(['abc', 'zzz', 'xxx', 'yyy'], getline(1,'$'))
173 bw!
174 bw!
175endfunc
176
Bram Moolenaar1e115362019-01-09 23:01:02 +0100177func Test_edit_07()
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100178 " 1) Test with completion <c-l> when popupmenu is visible
179 new
180 call setline(1, 'J')
181
182 func! ListMonths()
183 call complete(col('.')-1, ['January', 'February', 'March',
184 \ 'April', 'May', 'June', 'July', 'August', 'September',
185 \ 'October', 'November', 'December'])
186 return ''
187 endfunc
188 inoremap <buffer> <F5> <C-R>=ListMonths()<CR>
189
190 call feedkeys("A\<f5>\<c-p>". repeat("\<down>", 6)."\<c-l>\<down>\<c-l>\<cr>", 'tx')
191 call assert_equal(['July'], getline(1,'$'))
192 " 1) Test completion when InsertCharPre kicks in
193 %d
194 call setline(1, 'J')
195 fu! DoIt()
196 if v:char=='u'
197 let v:char='an'
198 endif
199 endfu
200 au InsertCharPre <buffer> :call DoIt()
201 call feedkeys("A\<f5>\<c-p>u\<cr>\<c-l>\<cr>", 'tx')
Bram Moolenaar4c313b12019-08-24 22:58:31 +0200202 call assert_equal(["Jan\<c-l>",''], 1->getline('$'))
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100203 %d
204 call setline(1, 'J')
205 call feedkeys("A\<f5>\<c-p>u\<down>\<c-l>\<cr>", 'tx')
Bram Moolenaar4c313b12019-08-24 22:58:31 +0200206 call assert_equal(["January"], 1->getline('$'))
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100207
208 delfu ListMonths
209 delfu DoIt
210 iunmap <buffer> <f5>
211 bw!
212endfunc
213
Bram Moolenaar1e115362019-01-09 23:01:02 +0100214func Test_edit_08()
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100215 " reset insertmode from i_ctrl-r_=
Bram Moolenaar2a45d642017-10-27 01:35:00 +0200216 let g:bufnr = bufnr('%')
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100217 new
218 call setline(1, ['abc'])
219 call cursor(1, 4)
Bram Moolenaar2a45d642017-10-27 01:35:00 +0200220 call feedkeys(":set im\<cr>ZZZ\<c-r>=setbufvar(g:bufnr,'&im', 0)\<cr>",'tnix')
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100221 call assert_equal(['abZZZc'], getline(1,'$'))
222 call assert_equal([0, 1, 1, 0], getpos('.'))
223 call assert_false(0, '&im')
224 bw!
Bram Moolenaar2a45d642017-10-27 01:35:00 +0200225 unlet g:bufnr
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100226endfunc
227
Bram Moolenaar1e115362019-01-09 23:01:02 +0100228func Test_edit_09()
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100229 " test i_CTRL-\ combinations
230 new
231 call setline(1, ['abc', 'def', 'ghi'])
232 call cursor(1, 1)
233 " 1) CTRL-\ CTLR-N
234 call feedkeys(":set im\<cr>\<c-\>\<c-n>ccABC\<c-l>", 'txin')
235 call assert_equal(['ABC', 'def', 'ghi'], getline(1,'$'))
236 call setline(1, ['ABC', 'def', 'ghi'])
237 " 2) CTRL-\ CTLR-G
238 call feedkeys("j0\<c-\>\<c-g>ZZZ\<cr>\<c-l>", 'txin')
239 call assert_equal(['ABC', 'ZZZ', 'def', 'ghi'], getline(1,'$'))
240 call feedkeys("I\<c-\>\<c-g>YYY\<c-l>", 'txin')
241 call assert_equal(['ABC', 'ZZZ', 'YYYdef', 'ghi'], getline(1,'$'))
242 set noinsertmode
243 " 3) CTRL-\ CTRL-O
244 call setline(1, ['ABC', 'ZZZ', 'def', 'ghi'])
245 call cursor(1, 1)
246 call feedkeys("A\<c-o>ix", 'txin')
247 call assert_equal(['ABxC', 'ZZZ', 'def', 'ghi'], getline(1,'$'))
248 call feedkeys("A\<c-\>\<c-o>ix", 'txin')
249 call assert_equal(['ABxCx', 'ZZZ', 'def', 'ghi'], getline(1,'$'))
250 " 4) CTRL-\ a (should be inserted literally, not special after <c-\>
251 call setline(1, ['ABC', 'ZZZ', 'def', 'ghi'])
252 call cursor(1, 1)
253 call feedkeys("A\<c-\>a", 'txin')
254 call assert_equal(["ABC\<c-\>a", 'ZZZ', 'def', 'ghi'], getline(1, '$'))
255 bw!
256endfunc
257
Bram Moolenaar1e115362019-01-09 23:01:02 +0100258func Test_edit_11()
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100259 " Test that indenting kicks in
260 new
261 set cindent
262 call setline(1, ['{', '', ''])
263 call cursor(2, 1)
264 call feedkeys("i\<c-f>int c;\<esc>", 'tnix')
265 call cursor(3, 1)
Bram Moolenaar1671f442020-03-10 07:48:13 +0100266 call feedkeys("\<Insert>/* comment */", 'tnix')
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100267 call assert_equal(['{', "\<tab>int c;", "/* comment */"], getline(1, '$'))
268 " added changed cindentkeys slightly
269 set cindent cinkeys+=*/
270 call setline(1, ['{', '', ''])
271 call cursor(2, 1)
272 call feedkeys("i\<c-f>int c;\<esc>", 'tnix')
273 call cursor(3, 1)
274 call feedkeys("i/* comment */", 'tnix')
275 call assert_equal(['{', "\<tab>int c;", "\<tab>/* comment */"], getline(1, '$'))
276 set cindent cinkeys+==end
277 call feedkeys("oend\<cr>\<esc>", 'tnix')
278 call assert_equal(['{', "\<tab>int c;", "\<tab>/* comment */", "\tend", ''], getline(1, '$'))
279 set cinkeys-==end
280 %d
281 " Use indentexpr instead of cindenting
282 func! Do_Indent()
283 if v:lnum == 3
284 return 3*shiftwidth()
285 else
286 return 2*shiftwidth()
287 endif
288 endfunc
289 setl indentexpr=Do_Indent() indentkeys+=*/
290 call setline(1, ['{', '', ''])
291 call cursor(2, 1)
292 call feedkeys("i\<c-f>int c;\<esc>", 'tnix')
293 call cursor(3, 1)
294 call feedkeys("i/* comment */", 'tnix')
295 call assert_equal(['{', "\<tab>\<tab>int c;", "\<tab>\<tab>\<tab>/* comment */"], getline(1, '$'))
296 set cinkeys&vim indentkeys&vim
297 set nocindent indentexpr=
298 delfu Do_Indent
299 bw!
300endfunc
301
Bram Moolenaar1e115362019-01-09 23:01:02 +0100302func Test_edit_11_indentexpr()
Bram Moolenaar1b383442017-09-26 20:04:54 +0200303 " Test that indenting kicks in
304 new
305 " Use indentexpr instead of cindenting
306 func! Do_Indent()
307 let pline=prevnonblank(v:lnum)
308 if empty(getline(v:lnum))
309 if getline(pline) =~ 'if\|then'
310 return shiftwidth()
311 else
312 return 0
313 endif
314 else
315 return 0
316 endif
317 endfunc
318 setl indentexpr=Do_Indent() indentkeys+=0=then,0=fi
319 call setline(1, ['if [ $this ]'])
320 call cursor(1, 1)
321 call feedkeys("othen\<cr>that\<cr>fi", 'tnix')
322 call assert_equal(['if [ $this ]', "then", "\<tab>that", "fi"], getline(1, '$'))
323 set cinkeys&vim indentkeys&vim
324 set nocindent indentexpr=
325 delfu Do_Indent
Yegappan Lakshmanan8bb65f22021-12-26 10:51:39 +0000326
327 " Using a script-local function
328 func s:NewIndentExpr()
329 endfunc
330 set indentexpr=s:NewIndentExpr()
331 call assert_equal(expand('<SID>') .. 'NewIndentExpr()', &indentexpr)
zeertzjq01d4efe2023-01-25 15:31:28 +0000332 call assert_equal(expand('<SID>') .. 'NewIndentExpr()', &g:indentexpr)
Yegappan Lakshmanan8bb65f22021-12-26 10:51:39 +0000333 set indentexpr=<SID>NewIndentExpr()
334 call assert_equal(expand('<SID>') .. 'NewIndentExpr()', &indentexpr)
zeertzjq01d4efe2023-01-25 15:31:28 +0000335 call assert_equal(expand('<SID>') .. 'NewIndentExpr()', &g:indentexpr)
336 setlocal indentexpr=
337 setglobal indentexpr=s:NewIndentExpr()
338 call assert_equal(expand('<SID>') .. 'NewIndentExpr()', &g:indentexpr)
339 call assert_equal('', &indentexpr)
340 new
341 call assert_equal(expand('<SID>') .. 'NewIndentExpr()', &indentexpr)
342 bw!
343 setglobal indentexpr=<SID>NewIndentExpr()
344 call assert_equal(expand('<SID>') .. 'NewIndentExpr()', &g:indentexpr)
345 call assert_equal('', &indentexpr)
346 new
347 call assert_equal(expand('<SID>') .. 'NewIndentExpr()', &indentexpr)
348 bw!
Yegappan Lakshmanan8bb65f22021-12-26 10:51:39 +0000349 set indentexpr&
350
Bram Moolenaar1b383442017-09-26 20:04:54 +0200351 bw!
352endfunc
353
Bram Moolenaarf9ab52e2020-05-05 19:57:18 +0200354" Test changing indent in replace mode
Bram Moolenaar1e115362019-01-09 23:01:02 +0100355func Test_edit_12()
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100356 new
357 call setline(1, ["\tabc", "\tdef"])
358 call cursor(2, 4)
359 call feedkeys("R^\<c-d>", 'tnix')
360 call assert_equal(["\tabc", "def"], getline(1, '$'))
Bram Moolenaar4c313b12019-08-24 22:58:31 +0200361 call assert_equal([0, 2, 2, 0], '.'->getpos())
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100362 %d
363 call setline(1, ["\tabc", "\t\tdef"])
364 call cursor(2, 2)
365 call feedkeys("R^\<c-d>", 'tnix')
366 call assert_equal(["\tabc", "def"], getline(1, '$'))
367 call assert_equal([0, 2, 1, 0], getpos('.'))
368 %d
369 call setline(1, ["\tabc", "\t\tdef"])
370 call cursor(2, 2)
371 call feedkeys("R\<c-t>", 'tnix')
372 call assert_equal(["\tabc", "\t\t\tdef"], getline(1, '$'))
373 call assert_equal([0, 2, 2, 0], getpos('.'))
374 bw!
375 10vnew
376 call setline(1, ["\tabc", "\t\tdef"])
377 call cursor(2, 2)
378 call feedkeys("R\<c-t>", 'tnix')
379 call assert_equal(["\tabc", "\t\t\tdef"], getline(1, '$'))
380 call assert_equal([0, 2, 2, 0], getpos('.'))
381 %d
382 set sw=4
383 call setline(1, ["\tabc", "\t\tdef"])
384 call cursor(2, 2)
385 call feedkeys("R\<c-t>\<c-t>", 'tnix')
386 call assert_equal(["\tabc", "\t\t\tdef"], getline(1, '$'))
387 call assert_equal([0, 2, 2, 0], getpos('.'))
388 %d
389 call setline(1, ["\tabc", "\t\tdef"])
390 call cursor(2, 2)
391 call feedkeys("R\<c-t>\<c-t>", 'tnix')
392 call assert_equal(["\tabc", "\t\t\tdef"], getline(1, '$'))
393 call assert_equal([0, 2, 2, 0], getpos('.'))
Bram Moolenaarf9ab52e2020-05-05 19:57:18 +0200394 set sw&
395
396 " In replace mode, after hitting enter in a line with tab characters,
397 " pressing backspace should restore the tab characters.
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100398 %d
Bram Moolenaarf9ab52e2020-05-05 19:57:18 +0200399 setlocal autoindent backspace=2
400 call setline(1, "\tone\t\ttwo")
401 exe "normal ggRred\<CR>six" .. repeat("\<BS>", 8)
402 call assert_equal(["\tone\t\ttwo"], getline(1, '$'))
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100403 bw!
404endfunc
405
Bram Moolenaar1e115362019-01-09 23:01:02 +0100406func Test_edit_13()
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100407 " Test smartindenting
Bram Moolenaar8e145b82022-05-21 20:17:31 +0100408 new
409 set smartindent autoindent
410 call setline(1, ["\tabc"])
411 call feedkeys("A {\<cr>more\<cr>}\<esc>", 'tnix')
412 call assert_equal(["\tabc {", "\t\tmore", "\t}"], getline(1, '$'))
413 set smartindent& autoindent&
414 bwipe!
Bram Moolenaar2ba42382019-03-16 18:11:07 +0100415
416 " Test autoindent removing indent of blank line.
417 new
418 call setline(1, ' foo bar baz')
419 set autoindent
420 exe "normal 0eea\<CR>\<CR>\<Esc>"
421 call assert_equal(" foo bar", getline(1))
422 call assert_equal("", getline(2))
423 call assert_equal(" baz", getline(3))
424 set autoindent&
Bram Moolenaar845e0ee2020-06-20 16:05:32 +0200425
426 " pressing <C-U> to erase line should keep the indent with 'autoindent'
427 set backspace=2 autoindent
428 %d
429 exe "normal i\tone\<CR>three\<C-U>two"
430 call assert_equal(["\tone", "\ttwo"], getline(1, '$'))
431 set backspace& autoindent&
432
Bram Moolenaar2ba42382019-03-16 18:11:07 +0100433 bwipe!
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100434endfunc
435
Bram Moolenaar1f448d92021-03-22 19:37:06 +0100436" Test for autoindent removing indent when insert mode is stopped. Some parts
437" of the code is exercised only when interactive mode is used. So use Vim in a
438" terminal.
439func Test_autoindent_remove_indent()
440 CheckRunVimInTerminal
Bram Moolenaar61abe7d2022-08-30 21:46:08 +0100441 let buf = RunVimInTerminal('-N Xarifile', {'rows': 6, 'cols' : 20})
Bram Moolenaar1f448d92021-03-22 19:37:06 +0100442 call TermWait(buf)
443 call term_sendkeys(buf, ":set autoindent\n")
444 " leaving insert mode in a new line with indent added by autoindent, should
445 " remove the indent.
446 call term_sendkeys(buf, "i\<Tab>foo\<CR>\<Esc>")
Dominique Pelle923dce22021-11-21 11:36:04 +0000447 " Need to delay for some time, otherwise the code in getchar.c will not be
Bram Moolenaar1f448d92021-03-22 19:37:06 +0100448 " exercised.
449 call TermWait(buf, 50)
450 " when a line is wrapped and the cursor is at the start of the second line,
451 " leaving insert mode, should move the cursor back to the first line.
452 call term_sendkeys(buf, "o" .. repeat('x', 20) .. "\<Esc>")
Dominique Pelle923dce22021-11-21 11:36:04 +0000453 " Need to delay for some time, otherwise the code in getchar.c will not be
Bram Moolenaar1f448d92021-03-22 19:37:06 +0100454 " exercised.
455 call TermWait(buf, 50)
456 call term_sendkeys(buf, ":w\n")
457 call TermWait(buf)
458 call StopVimInTerminal(buf)
Bram Moolenaar61abe7d2022-08-30 21:46:08 +0100459 call assert_equal(["\tfoo", '', repeat('x', 20)], readfile('Xarifile'))
460 call delete('Xarifile')
Bram Moolenaar1f448d92021-03-22 19:37:06 +0100461endfunc
462
Bram Moolenaar1e115362019-01-09 23:01:02 +0100463func Test_edit_CR()
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100464 " Test for <CR> in insert mode
Dominique Pelle923dce22021-11-21 11:36:04 +0000465 " basically only in quickfix mode it's tested, the rest
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100466 " has been taken care of by other tests
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200467 CheckFeature quickfix
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100468 botright new
Bram Moolenaar14f91762022-09-21 15:13:52 +0100469 call writefile(range(1, 10), 'Xqflist.txt', 'D')
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100470 call setqflist([{'filename': 'Xqflist.txt', 'lnum': 2}])
471 copen
472 set modifiable
473 call feedkeys("A\<cr>", 'tnix')
474 call assert_equal('Xqflist.txt', bufname(''))
475 call assert_equal(2, line('.'))
476 cclose
477 botright new
478 call setloclist(0, [{'filename': 'Xqflist.txt', 'lnum': 10}])
479 lopen
480 set modifiable
481 call feedkeys("A\<cr>", 'tnix')
482 call assert_equal('Xqflist.txt', bufname(''))
483 call assert_equal(10, line('.'))
484 call feedkeys("A\<Enter>", 'tnix')
485 call feedkeys("A\<kEnter>", 'tnix')
486 call feedkeys("A\n", 'tnix')
487 call feedkeys("A\r", 'tnix')
488 call assert_equal(map(range(1, 10), 'string(v:val)') + ['', '', '', ''], getline(1, '$'))
Bram Moolenaar14f91762022-09-21 15:13:52 +0100489
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100490 bw!
491 lclose
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100492endfunc
493
Bram Moolenaar1e115362019-01-09 23:01:02 +0100494func Test_edit_CTRL_()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200495 CheckFeature rightleft
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100496 " disabled for Windows builds, why?
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200497 CheckNotMSWindows
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100498 let _encoding=&encoding
499 set encoding=utf-8
500 " Test for CTRL-_
501 new
502 call setline(1, ['abc'])
503 call cursor(1, 1)
504 call feedkeys("i\<c-_>xyz\<esc>", 'tnix')
505 call assert_equal(["\<C-_>xyzabc"], getline(1, '$'))
506 call assert_false(&revins)
507 set ari
508 call setline(1, ['abc'])
509 call cursor(1, 1)
510 call feedkeys("i\<c-_>xyz\<esc>", 'tnix')
511 call assert_equal(["æèñabc"], getline(1, '$'))
512 call assert_true(&revins)
513 call setline(1, ['abc'])
514 call cursor(1, 1)
515 call feedkeys("i\<c-_>xyz\<esc>", 'tnix')
516 call assert_equal(["xyzabc"], getline(1, '$'))
517 call assert_false(&revins)
518 set noari
519 let &encoding=_encoding
520 bw!
521endfunc
522
523" needs to come first, to have the @. register empty
Bram Moolenaar1e115362019-01-09 23:01:02 +0100524func Test_edit_00a_CTRL_A()
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100525 " Test pressing CTRL-A
526 new
527 call setline(1, repeat([''], 5))
528 call cursor(1, 1)
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100529 try
530 call feedkeys("A\<NUL>", 'tnix')
531 catch /^Vim\%((\a\+)\)\=:E29/
532 call assert_true(1, 'E29 error caught')
533 endtry
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100534 call cursor(1, 1)
535 call feedkeys("Afoobar \<esc>", 'tnix')
536 call cursor(2, 1)
537 call feedkeys("A\<c-a>more\<esc>", 'tnix')
538 call cursor(3, 1)
539 call feedkeys("A\<NUL>and more\<esc>", 'tnix')
540 call assert_equal(['foobar ', 'foobar more', 'foobar morend more', '', ''], getline(1, '$'))
541 bw!
542endfunc
543
Bram Moolenaar1e115362019-01-09 23:01:02 +0100544func Test_edit_CTRL_EY()
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100545 " Ctrl-E/ Ctrl-Y in insert mode completion to scroll
546 10new
547 call setline(1, range(1, 100))
548 call cursor(30, 1)
549 norm! z.
550 call feedkeys("A\<c-x>\<c-e>\<c-e>\<c-e>\<c-e>\<c-e>", 'tnix')
551 call assert_equal(30, winsaveview()['topline'])
552 call assert_equal([0, 30, 2, 0], getpos('.'))
553 call feedkeys("A\<c-x>\<c-e>\<c-e>\<c-e>\<c-e>\<c-e>", 'tnix')
554 call feedkeys("A\<c-x>".repeat("\<c-y>", 10), 'tnix')
555 call assert_equal(21, winsaveview()['topline'])
556 call assert_equal([0, 30, 2, 0], getpos('.'))
557 bw!
558endfunc
559
Bram Moolenaar1e115362019-01-09 23:01:02 +0100560func Test_edit_CTRL_G()
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100561 new
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100562 call setline(1, ['foobar', 'foobar', 'foobar'])
563 call cursor(2, 4)
564 call feedkeys("ioooooooo\<c-g>k\<c-r>.\<esc>", 'tnix')
565 call assert_equal(['foooooooooobar', 'foooooooooobar', 'foobar'], getline(1, '$'))
566 call assert_equal([0, 1, 11, 0], getpos('.'))
567 call feedkeys("i\<c-g>k\<esc>", 'tnix')
568 call assert_equal([0, 1, 10, 0], getpos('.'))
569 call cursor(2, 4)
570 call feedkeys("i\<c-g>jzzzz\<esc>", 'tnix')
571 call assert_equal(['foooooooooobar', 'foooooooooobar', 'foozzzzbar'], getline(1, '$'))
572 call assert_equal([0, 3, 7, 0], getpos('.'))
573 call feedkeys("i\<c-g>j\<esc>", 'tnix')
574 call assert_equal([0, 3, 6, 0], getpos('.'))
zeertzjq4f026ea2023-02-26 14:47:24 +0000575 call assert_nobeep("normal! i\<c-g>\<esc>")
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100576 bw!
577endfunc
578
Bram Moolenaar1e115362019-01-09 23:01:02 +0100579func Test_edit_CTRL_I()
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100580 " Tab in completion mode
581 let path=expand("%:p:h")
582 new
Bram Moolenaarca851592018-06-06 21:04:07 +0200583 call setline(1, [path. "/", ''])
Bram Moolenaarc5379472017-03-16 22:38:00 +0100584 call feedkeys("Arunt\<c-x>\<c-f>\<tab>\<cr>\<esc>", 'tnix')
585 call assert_match('runtest\.vim', getline(1))
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100586 %d
Bram Moolenaar14f91762022-09-21 15:13:52 +0100587 call writefile(['one', 'two', 'three'], 'Xinclude.txt', 'D')
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100588 let include='#include Xinclude.txt'
589 call setline(1, [include, ''])
590 call cursor(2, 1)
591 call feedkeys("A\<c-x>\<tab>\<cr>\<esc>", 'tnix')
592 call assert_equal([include, 'one', ''], getline(1, '$'))
593 call feedkeys("2ggC\<c-x>\<tab>\<down>\<cr>\<esc>", 'tnix')
594 call assert_equal([include, 'two', ''], getline(1, '$'))
595 call feedkeys("2ggC\<c-x>\<tab>\<down>\<down>\<cr>\<esc>", 'tnix')
596 call assert_equal([include, 'three', ''], getline(1, '$'))
597 call feedkeys("2ggC\<c-x>\<tab>\<down>\<down>\<down>\<cr>\<esc>", 'tnix')
598 call assert_equal([include, '', ''], getline(1, '$'))
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100599 bw!
600endfunc
601
Bram Moolenaar1e115362019-01-09 23:01:02 +0100602func Test_edit_CTRL_K()
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100603 " Test pressing CTRL-K (basically only dictionary completion and digraphs
604 " the rest is already covered
Bram Moolenaar14f91762022-09-21 15:13:52 +0100605 call writefile(['A', 'AA', 'AAA', 'AAAA'], 'Xdictionary.txt', 'D')
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100606 set dictionary=Xdictionary.txt
607 new
608 call setline(1, 'A')
609 call cursor(1, 1)
610 call feedkeys("A\<c-x>\<c-k>\<cr>\<esc>", 'tnix')
611 call assert_equal(['AA', ''], getline(1, '$'))
612 %d
613 call setline(1, 'A')
614 call cursor(1, 1)
615 call feedkeys("A\<c-x>\<c-k>\<down>\<cr>\<esc>", 'tnix')
616 call assert_equal(['AAA'], getline(1, '$'))
617 %d
618 call setline(1, 'A')
619 call cursor(1, 1)
620 call feedkeys("A\<c-x>\<c-k>\<down>\<down>\<cr>\<esc>", 'tnix')
621 call assert_equal(['AAAA'], getline(1, '$'))
622 %d
623 call setline(1, 'A')
624 call cursor(1, 1)
625 call feedkeys("A\<c-x>\<c-k>\<down>\<down>\<down>\<cr>\<esc>", 'tnix')
626 call assert_equal(['A'], getline(1, '$'))
627 %d
628 call setline(1, 'A')
629 call cursor(1, 1)
630 call feedkeys("A\<c-x>\<c-k>\<down>\<down>\<down>\<down>\<cr>\<esc>", 'tnix')
631 call assert_equal(['AA'], getline(1, '$'))
632
Bram Moolenaar4b96df52020-01-26 22:00:26 +0100633 " press an unexpected key after dictionary completion
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100634 %d
635 call setline(1, 'A')
636 call cursor(1, 1)
637 call feedkeys("A\<c-x>\<c-k>\<c-]>\<cr>\<esc>", 'tnix')
638 call assert_equal(['AA', ''], getline(1, '$'))
639 %d
640 call setline(1, 'A')
641 call cursor(1, 1)
642 call feedkeys("A\<c-x>\<c-k>\<c-s>\<cr>\<esc>", 'tnix')
643 call assert_equal(["AA\<c-s>", ''], getline(1, '$'))
644 %d
645 call setline(1, 'A')
646 call cursor(1, 1)
647 call feedkeys("A\<c-x>\<c-k>\<c-f>\<cr>\<esc>", 'tnix')
648 call assert_equal(["AA\<c-f>", ''], getline(1, '$'))
649
650 set dictionary=
651 %d
652 call setline(1, 'A')
653 call cursor(1, 1)
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100654 let v:testing = 1
655 try
656 call feedkeys("A\<c-x>\<c-k>\<esc>", 'tnix')
657 catch
658 " error sleeps 2 seconds, when v:testing is not set
659 let v:testing = 0
660 endtry
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100661
Bram Moolenaar30276f22019-01-24 17:59:39 +0100662 call test_override("char_avail", 1)
663 set showcmd
664 %d
665 call feedkeys("A\<c-k>a:\<esc>", 'tnix')
666 call assert_equal(['ä'], getline(1, '$'))
667 call test_override("char_avail", 0)
668 set noshowcmd
669
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100670 bw!
671endfunc
672
Bram Moolenaar1e115362019-01-09 23:01:02 +0100673func Test_edit_CTRL_L()
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100674 " Test Ctrl-X Ctrl-L (line completion)
675 new
676 set complete=.
677 call setline(1, ['one', 'two', 'three', '', '', '', ''])
678 call cursor(4, 1)
679 call feedkeys("A\<c-x>\<c-l>\<esc>", 'tnix')
680 call assert_equal(['one', 'two', 'three', 'three', '', '', ''], getline(1, '$'))
681 call feedkeys("cct\<c-x>\<c-l>\<c-n>\<esc>", 'tnix')
682 call assert_equal(['one', 'two', 'three', 't', '', '', ''], getline(1, '$'))
683 call feedkeys("cct\<c-x>\<c-l>\<c-n>\<c-n>\<esc>", 'tnix')
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100684 call assert_equal(['one', 'two', 'three', 'two', '', '', ''], getline(1, '$'))
Bram Moolenaar02ae9b42018-02-09 15:06:02 +0100685 call feedkeys("cct\<c-x>\<c-l>\<c-n>\<c-n>\<c-n>\<esc>", 'tnix')
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100686 call assert_equal(['one', 'two', 'three', 'three', '', '', ''], getline(1, '$'))
Bram Moolenaar02ae9b42018-02-09 15:06:02 +0100687 call feedkeys("cct\<c-x>\<c-l>\<c-n>\<c-n>\<c-n>\<c-n>\<esc>", 'tnix')
688 call assert_equal(['one', 'two', 'three', 't', '', '', ''], getline(1, '$'))
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100689 call feedkeys("cct\<c-x>\<c-l>\<c-p>\<esc>", 'tnix')
690 call assert_equal(['one', 'two', 'three', 'two', '', '', ''], getline(1, '$'))
691 call feedkeys("cct\<c-x>\<c-l>\<c-p>\<c-p>\<esc>", 'tnix')
692 call assert_equal(['one', 'two', 'three', 't', '', '', ''], getline(1, '$'))
693 call feedkeys("cct\<c-x>\<c-l>\<c-p>\<c-p>\<c-p>\<esc>", 'tnix')
694 call assert_equal(['one', 'two', 'three', 'three', '', '', ''], getline(1, '$'))
695 set complete=
696 call cursor(5, 1)
697 call feedkeys("A\<c-x>\<c-l>\<c-p>\<c-n>\<esc>", 'tnix')
698 call assert_equal(['one', 'two', 'three', 'three', "\<c-l>\<c-p>\<c-n>", '', ''], getline(1, '$'))
699 set complete&
700 %d
701 if has("conceal") && has("syntax")
702 call setline(1, ['foo', 'bar', 'foobar'])
703 call test_override("char_avail", 1)
704 set conceallevel=2 concealcursor=n
705 syn on
706 syn match ErrorMsg "^bar"
707 call matchadd("Conceal", 'oo', 10, -1, {'conceal': 'X'})
708 func! DoIt()
709 let g:change=1
710 endfunc
711 au! TextChangedI <buffer> :call DoIt()
712
713 call cursor(2, 1)
714 call assert_false(exists("g:change"))
715 call feedkeys("A \<esc>", 'tnix')
716 call assert_equal(['foo', 'bar ', 'foobar'], getline(1, '$'))
717 call assert_equal(1, g:change)
718
719 call test_override("char_avail", 0)
720 call clearmatches()
721 syn off
722 au! TextChangedI
723 delfu DoIt
724 unlet! g:change
725 endif
726 bw!
727endfunc
728
Bram Moolenaar1e115362019-01-09 23:01:02 +0100729func Test_edit_CTRL_N()
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100730 " Check keyword completion
Bram Moolenaara1070ea2021-02-20 19:21:36 +0100731 for e in ['latin1', 'utf-8']
732 exe 'set encoding=' .. e
733 new
734 set complete=.
735 call setline(1, ['INFER', 'loWER', '', '', ])
736 call cursor(3, 1)
737 call feedkeys("Ai\<c-n>\<cr>\<esc>", "tnix")
738 call feedkeys("ILO\<c-n>\<cr>\<esc>", 'tnix')
739 call assert_equal(['INFER', 'loWER', 'i', 'LO', '', ''], getline(1, '$'), e)
740 %d
741 call setline(1, ['INFER', 'loWER', '', '', ])
742 call cursor(3, 1)
743 set ignorecase infercase
744 call feedkeys("Ii\<c-n>\<cr>\<esc>", "tnix")
745 call feedkeys("ILO\<c-n>\<cr>\<esc>", 'tnix')
746 call assert_equal(['INFER', 'loWER', 'infer', 'LOWER', '', ''], getline(1, '$'), e)
Yegappan Lakshmanane9825862022-01-03 11:03:48 +0000747 set noignorecase noinfercase
748 %d
749 call setline(1, ['one word', 'two word'])
750 exe "normal! Goo\<C-P>\<C-X>\<C-P>"
751 call assert_equal('one word', getline(3))
752 %d
753 set complete&
Bram Moolenaara1070ea2021-02-20 19:21:36 +0100754 bw!
755 endfor
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100756endfunc
757
Bram Moolenaar1e115362019-01-09 23:01:02 +0100758func Test_edit_CTRL_O()
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100759 " Check for CTRL-O in insert mode
760 new
761 inoreabbr <buffer> h here some more
762 call setline(1, ['abc', 'def'])
763 call cursor(1, 1)
764 " Ctrl-O after an abbreviation
765 exe "norm A h\<c-o>:set nu\<cr> text"
766 call assert_equal(['abc here some more text', 'def'], getline(1, '$'))
767 call assert_true(&nu)
768 set nonu
769 iunabbr <buffer> h
770 " Ctrl-O at end of line with 've'=onemore
771 call cursor(1, 1)
772 call feedkeys("A\<c-o>:let g:a=getpos('.')\<cr>\<esc>", 'tnix')
773 call assert_equal([0, 1, 23, 0], g:a)
774 call cursor(1, 1)
775 set ve=onemore
776 call feedkeys("A\<c-o>:let g:a=getpos('.')\<cr>\<esc>", 'tnix')
777 call assert_equal([0, 1, 24, 0], g:a)
778 set ve=
779 unlet! g:a
780 bw!
781endfunc
782
Bram Moolenaar1e115362019-01-09 23:01:02 +0100783func Test_edit_CTRL_R()
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100784 " Insert Register
785 new
786 call test_override("ALL", 1)
787 set showcmd
788 call feedkeys("AFOOBAR eins zwei\<esc>", 'tnix')
789 call feedkeys("O\<c-r>.", 'tnix')
790 call feedkeys("O\<c-r>=10*500\<cr>\<esc>", 'tnix')
791 call feedkeys("O\<c-r>=getreg('=', 1)\<cr>\<esc>", 'tnix')
792 call assert_equal(["getreg('=', 1)", '5000', "FOOBAR eins zwei", "FOOBAR eins zwei"], getline(1, '$'))
793 call test_override("ALL", 0)
794 set noshowcmd
795 bw!
796endfunc
797
Bram Moolenaar1e115362019-01-09 23:01:02 +0100798func Test_edit_CTRL_S()
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100799 " Test pressing CTRL-S (basically only spellfile completion)
800 " the rest is already covered
801 new
802 if !has("spell")
803 call setline(1, 'vim')
804 call feedkeys("A\<c-x>ss\<cr>\<esc>", 'tnix')
805 call assert_equal(['vims', ''], getline(1, '$'))
806 bw!
807 return
808 endif
809 call setline(1, 'vim')
810 " spell option not yet set
811 try
812 call feedkeys("A\<c-x>\<c-s>\<cr>\<esc>", 'tnix')
813 catch /^Vim\%((\a\+)\)\=:E756/
814 call assert_true(1, 'error caught')
815 endtry
816 call assert_equal(['vim', ''], getline(1, '$'))
817 %d
818 setl spell spelllang=en
819 call setline(1, 'vim')
820 call cursor(1, 1)
821 call feedkeys("A\<c-x>\<c-s>\<cr>\<esc>", 'tnix')
822 call assert_equal(['Vim', ''], getline(1, '$'))
823 %d
824 call setline(1, 'vim')
825 call cursor(1, 1)
826 call feedkeys("A\<c-x>\<c-s>\<down>\<cr>\<esc>", 'tnix')
827 call assert_equal(['Aim'], getline(1, '$'))
828 %d
829 call setline(1, 'vim')
830 call cursor(1, 1)
831 call feedkeys("A\<c-x>\<c-s>\<c-p>\<cr>\<esc>", 'tnix')
832 call assert_equal(['vim', ''], getline(1, '$'))
833 %d
834 " empty buffer
835 call cursor(1, 1)
836 call feedkeys("A\<c-x>\<c-s>\<c-p>\<cr>\<esc>", 'tnix')
837 call assert_equal(['', ''], getline(1, '$'))
838 setl nospell
839 bw!
840endfunc
841
Bram Moolenaar1e115362019-01-09 23:01:02 +0100842func Test_edit_CTRL_T()
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100843 " Check for CTRL-T and CTRL-X CTRL-T in insert mode
844 " 1) increase indent
845 new
846 call setline(1, "abc")
847 call cursor(1, 1)
848 call feedkeys("A\<c-t>xyz", 'tnix')
849 call assert_equal(["\<tab>abcxyz"], getline(1, '$'))
850 " 2) also when paste option is set
851 set paste
852 call setline(1, "abc")
853 call cursor(1, 1)
854 call feedkeys("A\<c-t>xyz", 'tnix')
855 call assert_equal(["\<tab>abcxyz"], getline(1, '$'))
856 set nopaste
857 " CTRL-X CTRL-T (thesaurus complete)
Bram Moolenaar14f91762022-09-21 15:13:52 +0100858 call writefile(['angry furious mad enraged'], 'Xthesaurus', 'D')
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100859 set thesaurus=Xthesaurus
860 call setline(1, 'mad')
861 call cursor(1, 1)
862 call feedkeys("A\<c-x>\<c-t>\<cr>\<esc>", 'tnix')
863 call assert_equal(['mad', ''], getline(1, '$'))
864 %d
865 call setline(1, 'mad')
866 call cursor(1, 1)
867 call feedkeys("A\<c-x>\<c-t>\<c-n>\<cr>\<esc>", 'tnix')
868 call assert_equal(['angry', ''], getline(1, '$'))
869 %d
870 call setline(1, 'mad')
871 call cursor(1, 1)
872 call feedkeys("A\<c-x>\<c-t>\<c-n>\<c-n>\<cr>\<esc>", 'tnix')
873 call assert_equal(['furious', ''], getline(1, '$'))
874 %d
875 call setline(1, 'mad')
876 call cursor(1, 1)
877 call feedkeys("A\<c-x>\<c-t>\<c-n>\<c-n>\<c-n>\<cr>\<esc>", 'tnix')
878 call assert_equal(['enraged', ''], getline(1, '$'))
879 %d
880 call setline(1, 'mad')
881 call cursor(1, 1)
882 call feedkeys("A\<c-x>\<c-t>\<c-n>\<c-n>\<c-n>\<c-n>\<cr>\<esc>", 'tnix')
883 call assert_equal(['mad', ''], getline(1, '$'))
884 %d
885 call setline(1, 'mad')
886 call cursor(1, 1)
887 call feedkeys("A\<c-x>\<c-t>\<c-n>\<c-n>\<c-n>\<c-n>\<c-n>\<cr>\<esc>", 'tnix')
888 call assert_equal(['mad', ''], getline(1, '$'))
889 " Using <c-p> <c-n> when 'complete' is empty
890 set complete=
891 %d
892 call setline(1, 'mad')
893 call cursor(1, 1)
894 call feedkeys("A\<c-x>\<c-t>\<c-n>\<cr>\<esc>", 'tnix')
895 call assert_equal(['angry', ''], getline(1, '$'))
896 %d
897 call setline(1, 'mad')
898 call cursor(1, 1)
899 call feedkeys("A\<c-x>\<c-t>\<c-p>\<cr>\<esc>", 'tnix')
900 call assert_equal(['mad', ''], getline(1, '$'))
901 set complete&
902
903 set thesaurus=
904 %d
905 call setline(1, 'mad')
906 call cursor(1, 1)
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100907 let v:testing = 1
908 try
909 call feedkeys("A\<c-x>\<c-t>\<esc>", 'tnix')
910 catch
911 " error sleeps 2 seconds, when v:testing is not set
912 let v:testing = 0
913 endtry
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100914 call assert_equal(['mad'], getline(1, '$'))
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100915 bw!
916endfunc
917
Yegappan Lakshmanane9825862022-01-03 11:03:48 +0000918" Test thesaurus completion with different encodings
919func Test_thesaurus_complete_with_encoding()
Bram Moolenaar14f91762022-09-21 15:13:52 +0100920 call writefile(['angry furious mad enraged'], 'Xthesaurus', 'D')
Yegappan Lakshmanane9825862022-01-03 11:03:48 +0000921 set thesaurus=Xthesaurus
922 for e in ['latin1', 'utf-8']
923 exe 'set encoding=' .. e
924 new
925 call setline(1, 'mad')
926 call cursor(1, 1)
927 call feedkeys("A\<c-x>\<c-t>\<cr>\<esc>", 'tnix')
928 call assert_equal(['mad', ''], getline(1, '$'))
929 bw!
930 endfor
931 set thesaurus=
Yegappan Lakshmanane9825862022-01-03 11:03:48 +0000932endfunc
933
Yegappan Lakshmanan160e9942021-10-16 15:41:29 +0100934" Test 'thesaurusfunc'
935func MyThesaurus(findstart, base)
936 let mythesaurus = [
937 \ #{word: "happy",
938 \ synonyms: "cheerful,blissful,flying high,looking good,peppy"},
939 \ #{word: "kind",
940 \ synonyms: "amiable,bleeding-heart,heart in right place"}]
941 if a:findstart
942 " locate the start of the word
943 let line = getline('.')
944 let start = col('.') - 1
945 while start > 0 && line[start - 1] =~ '\a'
946 let start -= 1
947 endwhile
948 return start
949 else
950 " find strings matching with "a:base"
951 let res = []
952 for w in mythesaurus
953 if w.word =~ '^' . a:base
954 call add(res, w.word)
955 call extend(res, split(w.synonyms, ","))
956 endif
957 endfor
958 return res
959 endif
960endfunc
961
962func Test_thesaurus_func()
963 new
Bram Moolenaarf4d8b762021-10-17 14:13:09 +0100964 set thesaurus=notused
965 set thesaurusfunc=NotUsed
966 setlocal thesaurusfunc=MyThesaurus
Yegappan Lakshmanan160e9942021-10-16 15:41:29 +0100967 call setline(1, "an ki")
968 call cursor(1, 1)
969 call feedkeys("A\<c-x>\<c-t>\<c-n>\<cr>\<esc>", 'tnix')
970 call assert_equal(['an amiable', ''], getline(1, '$'))
Bram Moolenaarf4d8b762021-10-17 14:13:09 +0100971
972 setlocal thesaurusfunc=NonExistingFunc
973 call assert_fails("normal $a\<C-X>\<C-T>", 'E117:')
974
975 setlocal thesaurusfunc=
Yegappan Lakshmanan160e9942021-10-16 15:41:29 +0100976 set thesaurusfunc=NonExistingFunc
977 call assert_fails("normal $a\<C-X>\<C-T>", 'E117:')
Yegappan Lakshmanan160e9942021-10-16 15:41:29 +0100978 %bw!
Bram Moolenaarf4d8b762021-10-17 14:13:09 +0100979
980 set thesaurusfunc=
981 set thesaurus=
Yegappan Lakshmanan160e9942021-10-16 15:41:29 +0100982endfunc
983
Bram Moolenaar1e115362019-01-09 23:01:02 +0100984func Test_edit_CTRL_U()
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100985 " Test 'completefunc'
986 new
987 " -1, -2 and -3 are special return values
988 let g:special=0
989 fun! CompleteMonths(findstart, base)
990 if a:findstart
991 " locate the start of the word
992 return g:special
993 else
994 " find months matching with "a:base"
995 let res = []
996 for m in split("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec")
997 if m =~ '^\c'.a:base
998 call add(res, {'word': m, 'abbr': m.' Month', 'icase': 0})
999 endif
1000 endfor
1001 return {'words': res, 'refresh': 'always'}
1002 endif
1003 endfun
1004 set completefunc=CompleteMonths
1005 call setline(1, ['', ''])
1006 call cursor(1, 1)
1007 call feedkeys("AX\<c-x>\<c-u>\<cr>\<esc>", 'tnix')
1008 call assert_equal(['X', '', ''], getline(1, '$'))
1009 %d
1010 let g:special=-1
1011 call feedkeys("AX\<c-x>\<c-u>\<cr>\<esc>", 'tnix')
1012 call assert_equal(['XJan', ''], getline(1, '$'))
1013 %d
1014 let g:special=-2
1015 call feedkeys("AX\<c-x>\<c-u>\<cr>\<esc>", 'tnix')
1016 call assert_equal(['X', ''], getline(1, '$'))
1017 %d
1018 let g:special=-3
1019 call feedkeys("AX\<c-x>\<c-u>\<cr>\<esc>", 'tnix')
1020 call assert_equal(['X', ''], getline(1, '$'))
1021 %d
1022 let g:special=0
1023 call feedkeys("AM\<c-x>\<c-u>\<cr>\<esc>", 'tnix')
1024 call assert_equal(['Mar', ''], getline(1, '$'))
1025 %d
1026 call feedkeys("AM\<c-x>\<c-u>\<c-n>\<cr>\<esc>", 'tnix')
1027 call assert_equal(['May', ''], getline(1, '$'))
1028 %d
1029 call feedkeys("AM\<c-x>\<c-u>\<c-n>\<c-n>\<cr>\<esc>", 'tnix')
1030 call assert_equal(['M', ''], getline(1, '$'))
1031 delfu CompleteMonths
1032 %d
1033 try
1034 call feedkeys("A\<c-x>\<c-u>", 'tnix')
1035 call assert_fails(1, 'unknown completion function')
1036 catch /^Vim\%((\a\+)\)\=:E117/
1037 call assert_true(1, 'E117 error caught')
1038 endtry
1039 set completefunc=
1040 bw!
1041endfunc
1042
Bram Moolenaarff06f282020-04-21 22:01:14 +02001043func Test_edit_completefunc_delete()
1044 func CompleteFunc(findstart, base)
1045 if a:findstart == 1
1046 return col('.') - 1
1047 endif
1048 normal dd
1049 return ['a', 'b']
1050 endfunc
1051 new
1052 set completefunc=CompleteFunc
1053 call setline(1, ['', 'abcd', ''])
1054 2d
zeertzjqcfe45652022-05-27 17:26:55 +01001055 call assert_fails("normal 2G$a\<C-X>\<C-U>", 'E565:')
Bram Moolenaarff06f282020-04-21 22:01:14 +02001056 bwipe!
1057endfunc
1058
1059
Bram Moolenaar1e115362019-01-09 23:01:02 +01001060func Test_edit_CTRL_Z()
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001061 " Ctrl-Z when insertmode is not set inserts it literally
1062 new
1063 call setline(1, 'abc')
1064 call feedkeys("A\<c-z>\<esc>", 'tnix')
1065 call assert_equal(["abc\<c-z>"], getline(1,'$'))
1066 bw!
1067 " TODO: How to Test Ctrl-Z in insert mode, e.g. suspend?
1068endfunc
1069
Bram Moolenaar1e115362019-01-09 23:01:02 +01001070func Test_edit_DROP()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001071 CheckFeature dnd
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001072 new
1073 call setline(1, ['abc def ghi'])
1074 call cursor(1, 1)
1075 try
1076 call feedkeys("i\<Drop>\<Esc>", 'tnix')
1077 call assert_fails(1, 'Invalid register name')
1078 catch /^Vim\%((\a\+)\)\=:E353/
1079 call assert_true(1, 'error caught')
1080 endtry
1081 bw!
1082endfunc
1083
Bram Moolenaar1e115362019-01-09 23:01:02 +01001084func Test_edit_CTRL_V()
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001085 new
1086 call setline(1, ['abc'])
1087 call cursor(2, 1)
zeertzjq502d8ae2022-01-24 15:27:50 +00001088
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001089 " force some redraws
1090 set showmode showcmd
zeertzjq502d8ae2022-01-24 15:27:50 +00001091 call test_override('char_avail', 1)
1092
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001093 call feedkeys("A\<c-v>\<c-n>\<c-v>\<c-l>\<c-v>\<c-b>\<esc>", 'tnix')
1094 call assert_equal(["abc\x0e\x0c\x02"], getline(1, '$'))
1095
1096 if has("rightleft") && exists("+rl")
1097 set rl
1098 call setline(1, ['abc'])
1099 call cursor(2, 1)
1100 call feedkeys("A\<c-v>\<c-n>\<c-v>\<c-l>\<c-v>\<c-b>\<esc>", 'tnix')
1101 call assert_equal(["abc\x0e\x0c\x02"], getline(1, '$'))
1102 set norl
1103 endif
1104
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001105 set noshowmode showcmd
zeertzjq502d8ae2022-01-24 15:27:50 +00001106 call test_override('char_avail', 0)
1107
1108 " No modifiers should be applied to the char typed using i_CTRL-V_digit.
1109 call feedkeys(":append\<CR>\<C-V>76c\<C-V>76\<C-F2>\<C-V>u3c0j\<C-V>u3c0\<M-F3>\<CR>.\<CR>", 'tnix')
1110 call assert_equal('LcL<C-F2>πjπ<M-F3>', getline(2))
1111
1112 if has('osx')
1113 " A char with a modifier should not be a valid char for i_CTRL-V_digit.
1114 call feedkeys("o\<C-V>\<D-j>\<C-V>\<D-1>\<C-V>\<D-o>\<C-V>\<D-x>\<C-V>\<D-u>", 'tnix')
1115 call assert_equal('<D-j><D-1><D-o><D-x><D-u>', getline(3))
1116 endif
1117
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001118 bw!
1119endfunc
1120
Bram Moolenaar1e115362019-01-09 23:01:02 +01001121func Test_edit_F1()
Bram Moolenaar5a4c3082019-12-01 15:23:11 +01001122 CheckFeature quickfix
1123
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001124 " Pressing <f1>
1125 new
1126 call feedkeys(":set im\<cr>\<f1>\<c-l>", 'tnix')
1127 set noinsertmode
1128 call assert_equal('help', &buftype)
1129 bw
1130 bw
1131endfunc
1132
Bram Moolenaar1e115362019-01-09 23:01:02 +01001133func Test_edit_F21()
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001134 " Pressing <f21>
1135 " sends a netbeans command
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001136 CheckFeature netbeans_intg
1137 new
1138 " I have no idea what this is supposed to do :)
1139 call feedkeys("A\<F21>\<F1>\<esc>", 'tnix')
1140 bw
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001141endfunc
1142
Bram Moolenaar1e115362019-01-09 23:01:02 +01001143func Test_edit_HOME_END()
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001144 " Test Home/End Keys
1145 new
1146 set foldopen+=hor
1147 call setline(1, ['abc', 'def'])
1148 call cursor(1, 1)
1149 call feedkeys("AX\<Home>Y\<esc>", 'tnix')
1150 call cursor(2, 1)
1151 call feedkeys("iZ\<End>Y\<esc>", 'tnix')
1152 call assert_equal(['YabcX', 'ZdefY'], getline(1, '$'))
1153
1154 set foldopen-=hor
1155 bw!
1156endfunc
1157
Bram Moolenaar1e115362019-01-09 23:01:02 +01001158func Test_edit_INS()
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001159 " Test for Pressing <Insert>
1160 new
1161 call setline(1, ['abc', 'def'])
1162 call cursor(1, 1)
1163 call feedkeys("i\<Insert>ZYX>", 'tnix')
1164 call assert_equal(['ZYX>', 'def'], getline(1, '$'))
1165 call setline(1, ['abc', 'def'])
1166 call cursor(1, 1)
1167 call feedkeys("i\<Insert>Z\<Insert>YX>", 'tnix')
1168 call assert_equal(['ZYX>bc', 'def'], getline(1, '$'))
1169 bw!
1170endfunc
1171
Bram Moolenaar1e115362019-01-09 23:01:02 +01001172func Test_edit_LEFT_RIGHT()
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001173 " Left, Shift-Left, Right, Shift-Right
1174 new
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001175 call setline(1, ['abc def ghi', 'ABC DEF GHI', 'ZZZ YYY XXX'])
1176 let _ww=&ww
1177 set ww=
1178 call cursor(2, 1)
1179 call feedkeys("i\<left>\<esc>", 'tnix')
1180 call assert_equal([0, 2, 1, 0], getpos('.'))
1181 " Is this a bug, <s-left> does not respect whichwrap option
1182 call feedkeys("i\<s-left>\<esc>", 'tnix')
1183 call assert_equal([0, 1, 8, 0], getpos('.'))
1184 call feedkeys("i". repeat("\<s-left>", 3). "\<esc>", 'tnix')
1185 call assert_equal([0, 1, 1, 0], getpos('.'))
1186 call feedkeys("i\<right>\<esc>", 'tnix')
1187 call assert_equal([0, 1, 1, 0], getpos('.'))
1188 call feedkeys("i\<right>\<right>\<esc>", 'tnix')
1189 call assert_equal([0, 1, 2, 0], getpos('.'))
1190 call feedkeys("A\<right>\<esc>", 'tnix')
1191 call assert_equal([0, 1, 11, 0], getpos('.'))
1192 call feedkeys("A\<s-right>\<esc>", 'tnix')
1193 call assert_equal([0, 2, 1, 0], getpos('.'))
1194 call feedkeys("i\<s-right>\<esc>", 'tnix')
1195 call assert_equal([0, 2, 4, 0], getpos('.'))
1196 call cursor(3, 11)
1197 call feedkeys("A\<right>\<esc>", 'tnix')
1198 call feedkeys("A\<s-right>\<esc>", 'tnix')
1199 call assert_equal([0, 3, 11, 0], getpos('.'))
1200 call cursor(2, 11)
1201 " <S-Right> does not respect 'whichwrap' option
1202 call feedkeys("A\<s-right>\<esc>", 'tnix')
1203 call assert_equal([0, 3, 1, 0], getpos('.'))
1204 " Check motion when 'whichwrap' contains cursor keys for insert mode
1205 set ww+=[,]
1206 call cursor(2, 1)
1207 call feedkeys("i\<left>\<esc>", 'tnix')
1208 call assert_equal([0, 1, 11, 0], getpos('.'))
1209 call cursor(2, 11)
1210 call feedkeys("A\<right>\<esc>", 'tnix')
1211 call assert_equal([0, 3, 1, 0], getpos('.'))
1212 call cursor(2, 11)
1213 call feedkeys("A\<s-right>\<esc>", 'tnix')
1214 call assert_equal([0, 3, 1, 0], getpos('.'))
1215 let &ww = _ww
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001216 bw!
1217endfunc
1218
Bram Moolenaar1e115362019-01-09 23:01:02 +01001219func Test_edit_MOUSE()
Christian Brabandtee17b6f2023-09-09 11:23:50 +02001220 " This is a simple test, since we're not really using the mouse here
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001221 CheckFeature mouse
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001222 10new
1223 call setline(1, range(1, 100))
1224 call cursor(1, 1)
Bram Moolenaar8e8dc9b2022-05-08 20:38:06 +01001225 call assert_equal(1, line('w0'))
1226 call assert_equal(10, line('w$'))
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001227 set mouse=a
Bram Moolenaar8e8dc9b2022-05-08 20:38:06 +01001228 " One scroll event moves three lines.
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001229 call feedkeys("A\<ScrollWheelDown>\<esc>", 'tnix')
Bram Moolenaar8e8dc9b2022-05-08 20:38:06 +01001230 call assert_equal(4, line('w0'))
1231 call assert_equal(13, line('w$'))
1232 " This should move by one page down.
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001233 call feedkeys("A\<S-ScrollWheelDown>\<esc>", 'tnix')
Bram Moolenaar8e8dc9b2022-05-08 20:38:06 +01001234 call assert_equal(14, line('w0'))
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001235 set nostartofline
Bram Moolenaar8e8dc9b2022-05-08 20:38:06 +01001236 " Another page down.
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001237 call feedkeys("A\<C-ScrollWheelDown>\<esc>", 'tnix')
Bram Moolenaar8e8dc9b2022-05-08 20:38:06 +01001238 call assert_equal(24, line('w0'))
1239
1240 call assert_equal([0, 24, 2, 0], getpos('.'))
1241 call test_setmouse(4, 3)
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001242 call feedkeys("A\<LeftMouse>\<esc>", 'tnix')
Bram Moolenaar8e8dc9b2022-05-08 20:38:06 +01001243 call assert_equal([0, 27, 2, 0], getpos('.'))
Bram Moolenaarb3707712022-05-08 22:49:43 +01001244 set mousemodel=extend
Bram Moolenaar8e8dc9b2022-05-08 20:38:06 +01001245 call test_setmouse(5, 3)
1246 call feedkeys("A\<RightMouse>\<esc>\<esc>", 'tnix')
1247 call assert_equal([0, 28, 2, 0], getpos('.'))
Bram Moolenaarb3707712022-05-08 22:49:43 +01001248 set mousemodel&
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001249 call cursor(1, 100)
1250 norm! zt
1251 " this should move by a screen up, but when the test
1252 " is run, it moves up to the top of the buffer...
1253 call feedkeys("A\<ScrollWheelUp>\<esc>", 'tnix')
1254 call assert_equal([0, 1, 1, 0], getpos('.'))
1255 call cursor(1, 30)
1256 norm! zt
1257 call feedkeys("A\<S-ScrollWheelUp>\<esc>", 'tnix')
1258 call assert_equal([0, 1, 1, 0], getpos('.'))
1259 call cursor(1, 30)
1260 norm! zt
1261 call feedkeys("A\<C-ScrollWheelUp>\<esc>", 'tnix')
1262 call assert_equal([0, 1, 1, 0], getpos('.'))
1263 %d
1264 call setline(1, repeat(["12345678901234567890"], 100))
1265 call cursor(2, 1)
1266 call feedkeys("A\<ScrollWheelRight>\<esc>", 'tnix')
1267 call assert_equal([0, 2, 20, 0], getpos('.'))
1268 call feedkeys("A\<ScrollWheelLeft>\<esc>", 'tnix')
1269 call assert_equal([0, 2, 20, 0], getpos('.'))
1270 call feedkeys("A\<S-ScrollWheelRight>\<esc>", 'tnix')
1271 call assert_equal([0, 2, 20, 0], getpos('.'))
1272 call feedkeys("A\<S-ScrollWheelLeft>\<esc>", 'tnix')
1273 call assert_equal([0, 2, 20, 0], getpos('.'))
1274 call feedkeys("A\<C-ScrollWheelRight>\<esc>", 'tnix')
1275 call assert_equal([0, 2, 20, 0], getpos('.'))
1276 call feedkeys("A\<C-ScrollWheelLeft>\<esc>", 'tnix')
1277 call assert_equal([0, 2, 20, 0], getpos('.'))
1278 set mouse& startofline
1279 bw!
1280endfunc
1281
Bram Moolenaar1e115362019-01-09 23:01:02 +01001282func Test_edit_PAGEUP_PAGEDOWN()
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001283 10new
1284 call setline(1, repeat(['abc def ghi'], 30))
1285 call cursor(1, 1)
1286 call feedkeys("i\<PageDown>\<esc>", 'tnix')
1287 call assert_equal([0, 9, 1, 0], getpos('.'))
1288 call feedkeys("i\<PageDown>\<esc>", 'tnix')
1289 call assert_equal([0, 17, 1, 0], getpos('.'))
1290 call feedkeys("i\<PageDown>\<esc>", 'tnix')
1291 call assert_equal([0, 25, 1, 0], getpos('.'))
1292 call feedkeys("i\<PageDown>\<esc>", 'tnix')
1293 call assert_equal([0, 30, 1, 0], getpos('.'))
1294 call feedkeys("i\<PageDown>\<esc>", 'tnix')
1295 call assert_equal([0, 30, 1, 0], getpos('.'))
1296 call feedkeys("A\<PageUp>\<esc>", 'tnix')
Luuk van Baal5a2e3ec2024-03-28 10:07:29 +01001297 call assert_equal([0, 29, 1, 0], getpos('.'))
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001298 call feedkeys("A\<PageUp>\<esc>", 'tnix')
Luuk van Baal5a2e3ec2024-03-28 10:07:29 +01001299 call assert_equal([0, 21, 1, 0], getpos('.'))
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001300 call feedkeys("A\<PageUp>\<esc>", 'tnix')
Luuk van Baal5a2e3ec2024-03-28 10:07:29 +01001301 call assert_equal([0, 13, 1, 0], getpos('.'))
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001302 call feedkeys("A\<PageUp>\<esc>", 'tnix')
Luuk van Baalb9f5b952024-03-26 18:46:45 +01001303 call assert_equal([0, 10, 1, 0], getpos('.'))
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001304 call feedkeys("A\<PageUp>\<esc>", 'tnix')
Luuk van Baalcb204e62024-04-02 20:49:45 +02001305 call assert_equal([0, 10, 11, 0], getpos('.'))
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001306 " <S-Up> is the same as <PageUp>
1307 " <S-Down> is the same as <PageDown>
1308 call cursor(1, 1)
1309 call feedkeys("i\<S-Down>\<esc>", 'tnix')
1310 call assert_equal([0, 9, 1, 0], getpos('.'))
1311 call feedkeys("i\<S-Down>\<esc>", 'tnix')
1312 call assert_equal([0, 17, 1, 0], getpos('.'))
1313 call feedkeys("i\<S-Down>\<esc>", 'tnix')
1314 call assert_equal([0, 25, 1, 0], getpos('.'))
1315 call feedkeys("i\<S-Down>\<esc>", 'tnix')
1316 call assert_equal([0, 30, 1, 0], getpos('.'))
1317 call feedkeys("i\<S-Down>\<esc>", 'tnix')
1318 call assert_equal([0, 30, 1, 0], getpos('.'))
1319 call feedkeys("A\<S-Up>\<esc>", 'tnix')
Luuk van Baal5a2e3ec2024-03-28 10:07:29 +01001320 call assert_equal([0, 29, 1, 0], getpos('.'))
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001321 call feedkeys("A\<S-Up>\<esc>", 'tnix')
Luuk van Baal5a2e3ec2024-03-28 10:07:29 +01001322 call assert_equal([0, 21, 1, 0], getpos('.'))
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001323 call feedkeys("A\<S-Up>\<esc>", 'tnix')
Luuk van Baal5a2e3ec2024-03-28 10:07:29 +01001324 call assert_equal([0, 13, 1, 0], getpos('.'))
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001325 call feedkeys("A\<S-Up>\<esc>", 'tnix')
Luuk van Baalb9f5b952024-03-26 18:46:45 +01001326 call assert_equal([0, 10, 1, 0], getpos('.'))
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001327 call feedkeys("A\<S-Up>\<esc>", 'tnix')
Luuk van Baalcb204e62024-04-02 20:49:45 +02001328 call assert_equal([0, 10, 11, 0], getpos('.'))
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001329 set nostartofline
1330 call cursor(30, 11)
1331 norm! zt
1332 call feedkeys("A\<PageUp>\<esc>", 'tnix')
Luuk van Baal5a2e3ec2024-03-28 10:07:29 +01001333 call assert_equal([0, 29, 11, 0], getpos('.'))
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001334 call feedkeys("A\<PageUp>\<esc>", 'tnix')
Luuk van Baal5a2e3ec2024-03-28 10:07:29 +01001335 call assert_equal([0, 21, 11, 0], getpos('.'))
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001336 call feedkeys("A\<PageUp>\<esc>", 'tnix')
Luuk van Baal5a2e3ec2024-03-28 10:07:29 +01001337 call assert_equal([0, 13, 11, 0], getpos('.'))
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001338 call feedkeys("A\<PageUp>\<esc>", 'tnix')
Luuk van Baalb9f5b952024-03-26 18:46:45 +01001339 call assert_equal([0, 10, 11, 0], getpos('.'))
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001340 call feedkeys("A\<PageUp>\<esc>", 'tnix')
Luuk van Baalcb204e62024-04-02 20:49:45 +02001341 call assert_equal([0, 10, 11, 0], getpos('.'))
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001342 call cursor(1, 1)
1343 call feedkeys("A\<PageDown>\<esc>", 'tnix')
1344 call assert_equal([0, 9, 11, 0], getpos('.'))
1345 call feedkeys("A\<PageDown>\<esc>", 'tnix')
1346 call assert_equal([0, 17, 11, 0], getpos('.'))
1347 call feedkeys("A\<PageDown>\<esc>", 'tnix')
1348 call assert_equal([0, 25, 11, 0], getpos('.'))
1349 call feedkeys("A\<PageDown>\<esc>", 'tnix')
1350 call assert_equal([0, 30, 11, 0], getpos('.'))
1351 call feedkeys("A\<PageDown>\<esc>", 'tnix')
1352 call assert_equal([0, 30, 11, 0], getpos('.'))
1353 " <S-Up> is the same as <PageUp>
1354 " <S-Down> is the same as <PageDown>
1355 call cursor(30, 11)
1356 norm! zt
1357 call feedkeys("A\<S-Up>\<esc>", 'tnix')
Luuk van Baal5a2e3ec2024-03-28 10:07:29 +01001358 call assert_equal([0, 29, 11, 0], getpos('.'))
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001359 call feedkeys("A\<S-Up>\<esc>", 'tnix')
Luuk van Baal5a2e3ec2024-03-28 10:07:29 +01001360 call assert_equal([0, 21, 11, 0], getpos('.'))
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001361 call feedkeys("A\<S-Up>\<esc>", 'tnix')
Luuk van Baal5a2e3ec2024-03-28 10:07:29 +01001362 call assert_equal([0, 13, 11, 0], getpos('.'))
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001363 call feedkeys("A\<S-Up>\<esc>", 'tnix')
Luuk van Baalb9f5b952024-03-26 18:46:45 +01001364 call assert_equal([0, 10, 11, 0], getpos('.'))
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001365 call feedkeys("A\<S-Up>\<esc>", 'tnix')
Luuk van Baalcb204e62024-04-02 20:49:45 +02001366 call assert_equal([0, 10, 11, 0], getpos('.'))
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001367 call cursor(1, 1)
1368 call feedkeys("A\<S-Down>\<esc>", 'tnix')
1369 call assert_equal([0, 9, 11, 0], getpos('.'))
1370 call feedkeys("A\<S-Down>\<esc>", 'tnix')
1371 call assert_equal([0, 17, 11, 0], getpos('.'))
1372 call feedkeys("A\<S-Down>\<esc>", 'tnix')
1373 call assert_equal([0, 25, 11, 0], getpos('.'))
1374 call feedkeys("A\<S-Down>\<esc>", 'tnix')
1375 call assert_equal([0, 30, 11, 0], getpos('.'))
1376 call feedkeys("A\<S-Down>\<esc>", 'tnix')
1377 call assert_equal([0, 30, 11, 0], getpos('.'))
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001378 bw!
1379endfunc
1380
Bram Moolenaar1e115362019-01-09 23:01:02 +01001381func Test_edit_forbidden()
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001382 new
1383 " 1) edit in the sandbox is not allowed
1384 call setline(1, 'a')
1385 com! Sandbox :sandbox call feedkeys("i\<del>\<esc>", 'tnix')
1386 call assert_fails(':Sandbox', 'E48:')
1387 com! Sandbox :sandbox exe "norm! i\<del>"
1388 call assert_fails(':Sandbox', 'E48:')
1389 delcom Sandbox
1390 call assert_equal(['a'], getline(1,'$'))
Bram Moolenaar52797ba2021-12-16 14:45:13 +00001391
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001392 " 2) edit with textlock set
1393 fu! DoIt()
1394 call feedkeys("i\<del>\<esc>", 'tnix')
1395 endfu
1396 au InsertCharPre <buffer> :call DoIt()
1397 try
1398 call feedkeys("ix\<esc>", 'tnix')
1399 call assert_fails(1, 'textlock')
Bram Moolenaarff06f282020-04-21 22:01:14 +02001400 catch /^Vim\%((\a\+)\)\=:E565/ " catch E565: not allowed here
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001401 endtry
1402 " TODO: Might be a bug: should x really be inserted here
1403 call assert_equal(['xa'], getline(1, '$'))
1404 delfu DoIt
1405 try
1406 call feedkeys("ix\<esc>", 'tnix')
1407 call assert_fails(1, 'unknown function')
1408 catch /^Vim\%((\a\+)\)\=:E117/ " catch E117: unknown function
1409 endtry
1410 au! InsertCharPre
Bram Moolenaar52797ba2021-12-16 14:45:13 +00001411
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001412 " 3) edit when completion is shown
1413 fun! Complete(findstart, base)
1414 if a:findstart
1415 return col('.')
1416 else
1417 call feedkeys("i\<del>\<esc>", 'tnix')
1418 return []
1419 endif
1420 endfun
1421 set completefunc=Complete
1422 try
1423 call feedkeys("i\<c-x>\<c-u>\<esc>", 'tnix')
1424 call assert_fails(1, 'change in complete function')
Bram Moolenaarff06f282020-04-21 22:01:14 +02001425 catch /^Vim\%((\a\+)\)\=:E565/ " catch E565
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001426 endtry
1427 delfu Complete
1428 set completefunc=
Bram Moolenaar52797ba2021-12-16 14:45:13 +00001429
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001430 if has("rightleft") && exists("+fkmap")
1431 " 4) 'R' when 'fkmap' and 'revins' is set.
1432 set revins fkmap
1433 try
1434 normal Ri
1435 call assert_fails(1, "R with 'fkmap' and 'ri' set")
1436 catch
1437 finally
1438 set norevins nofkmap
1439 endtry
1440 endif
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001441 bw!
1442endfunc
1443
Bram Moolenaar1e115362019-01-09 23:01:02 +01001444func Test_edit_rightleft()
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001445 " Cursor in rightleft mode moves differently
Bram Moolenaar845e0ee2020-06-20 16:05:32 +02001446 CheckFeature rightleft
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001447 call NewWindow(10, 20)
1448 call setline(1, ['abc', 'def', 'ghi'])
1449 call cursor(1, 2)
1450 set rightleft
1451 " Screen looks as expected
1452 let lines = ScreenLines([1, 4], winwidth(0))
1453 let expect = [
1454 \" cba",
1455 \" fed",
1456 \" ihg",
1457 \" ~"]
1458 call assert_equal(join(expect, "\n"), join(lines, "\n"))
1459 " 2) right moves to the left
1460 call feedkeys("i\<right>\<esc>x", 'txin')
1461 call assert_equal(['bc', 'def', 'ghi'], getline(1,'$'))
1462 call cursor(1, 2)
1463 call feedkeys("i\<s-right>\<esc>", 'txin')
1464 call cursor(1, 2)
1465 call feedkeys("i\<c-right>\<esc>", 'txin')
1466 " Screen looks as expected
1467 let lines = ScreenLines([1, 4], winwidth(0))
1468 let expect = [
1469 \" cb",
1470 \" fed",
1471 \" ihg",
1472 \" ~"]
1473 call assert_equal(join(expect, "\n"), join(lines, "\n"))
1474 " 2) left moves to the right
1475 call setline(1, ['abc', 'def', 'ghi'])
1476 call cursor(1, 2)
1477 call feedkeys("i\<left>\<esc>x", 'txin')
1478 call assert_equal(['ac', 'def', 'ghi'], getline(1,'$'))
1479 call cursor(1, 2)
1480 call feedkeys("i\<s-left>\<esc>", 'txin')
1481 call cursor(1, 2)
1482 call feedkeys("i\<c-left>\<esc>", 'txin')
1483 " Screen looks as expected
1484 let lines = ScreenLines([1, 4], winwidth(0))
1485 let expect = [
1486 \" ca",
1487 \" fed",
1488 \" ihg",
1489 \" ~"]
1490 call assert_equal(join(expect, "\n"), join(lines, "\n"))
Bram Moolenaar845e0ee2020-06-20 16:05:32 +02001491 %d _
1492 call test_override('redraw_flag', 1)
1493 call test_override('char_avail', 1)
1494 call feedkeys("a\<C-V>x41", "xt")
1495 redraw!
1496 call assert_equal(repeat(' ', 19) .. 'A', Screenline(1))
1497 call test_override('ALL', 0)
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001498 set norightleft
1499 bw!
1500endfunc
Bram Moolenaar658a3a22017-03-31 22:27:12 +02001501
1502func Test_edit_complete_very_long_name()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001503 " Long directory names only work on Unix.
1504 CheckUnix
Bram Moolenaar15ecbd62017-04-07 14:10:48 +02001505
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01001506 let dirname = getcwd() . "/Xlongdir"
Bram Moolenaar15ecbd62017-04-07 14:10:48 +02001507 let longdirname = dirname . repeat('/' . repeat('d', 255), 4)
1508 try
Bram Moolenaar14f91762022-09-21 15:13:52 +01001509 call mkdir(longdirname, 'pR')
Bram Moolenaar15ecbd62017-04-07 14:10:48 +02001510 catch /E739:/
1511 " Long directory name probably not supported.
1512 call delete(dirname, 'rf')
1513 return
1514 endtry
1515
Bram Moolenaarf8191c52019-05-18 17:22:54 +02001516 " Try to get the Vim window position before setting 'columns', so that we can
1517 " move the window back to where it was.
Bram Moolenaarba6ec182017-04-04 22:41:10 +02001518 let winposx = getwinposx()
1519 let winposy = getwinposy()
Bram Moolenaarf8191c52019-05-18 17:22:54 +02001520
1521 if winposx >= 0 && winposy >= 0 && !has('gui_running')
1522 " We did get the window position, but xterm may report the wrong numbers.
1523 " Move the window to the reported position and compute any offset.
1524 exe 'winpos ' . winposx . ' ' . winposy
1525 sleep 100m
1526 let x = getwinposx()
1527 if x >= 0
1528 let winposx += winposx - x
1529 endif
1530 let y = getwinposy()
1531 if y >= 0
1532 let winposy += winposy - y
1533 endif
1534 endif
1535
Bram Moolenaar658a3a22017-03-31 22:27:12 +02001536 let save_columns = &columns
Bram Moolenaar15ecbd62017-04-07 14:10:48 +02001537 " Need at least about 1100 columns to reproduce the problem.
Bram Moolenaarba6ec182017-04-04 22:41:10 +02001538 set columns=2000
Bram Moolenaar658a3a22017-03-31 22:27:12 +02001539 set noswapfile
Bram Moolenaarba6ec182017-04-04 22:41:10 +02001540
Bram Moolenaar658a3a22017-03-31 22:27:12 +02001541 let longfilename = longdirname . '/' . repeat('a', 255)
Bram Moolenaar658a3a22017-03-31 22:27:12 +02001542 call writefile(['Totum', 'Table'], longfilename)
1543 new
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001544 exe "next Xnofile " . longfilename
Bram Moolenaar658a3a22017-03-31 22:27:12 +02001545 exe "normal iT\<C-N>"
1546
1547 bwipe!
1548 exe 'bwipe! ' . longfilename
Bram Moolenaar658a3a22017-03-31 22:27:12 +02001549 let &columns = save_columns
Bram Moolenaarba6ec182017-04-04 22:41:10 +02001550 if winposx >= 0 && winposy >= 0
1551 exe 'winpos ' . winposx . ' ' . winposy
1552 endif
Bram Moolenaar658a3a22017-03-31 22:27:12 +02001553 set swapfile&
1554endfunc
Bram Moolenaarff930ca2017-10-19 17:12:10 +02001555
Bram Moolenaar2c8c6812018-07-28 17:07:52 +02001556func Test_edit_backtick()
1557 next a\`b c
1558 call assert_equal('a`b', expand('%'))
1559 next
1560 call assert_equal('c', expand('%'))
1561 call assert_equal('a\`b c', expand('##'))
1562endfunc
1563
Bram Moolenaarff930ca2017-10-19 17:12:10 +02001564func Test_edit_quit()
1565 edit foo.txt
1566 split
1567 new
1568 call setline(1, 'hello')
1569 3wincmd w
1570 redraw!
1571 call assert_fails('1q', 'E37:')
1572 bwipe! foo.txt
1573 only
1574endfunc
1575
Bram Moolenaaradb8fbe2018-06-04 20:34:23 +02001576func Test_edit_alt()
1577 " Keeping the cursor line didn't happen when the first line has indent.
1578 new
1579 call setline(1, [' one', 'two', 'three'])
1580 w XAltFile
1581 $
1582 call assert_equal(3, line('.'))
1583 e Xother
1584 e #
1585 call assert_equal(3, line('.'))
1586
1587 bwipe XAltFile
1588 call delete('XAltFile')
1589endfunc
Bram Moolenaar4dbc2622018-11-02 11:59:15 +01001590
Bram Moolenaardb934952020-04-27 20:18:31 +02001591func Test_edit_InsertLeave()
Bram Moolenaar4dbc2622018-11-02 11:59:15 +01001592 new
Bram Moolenaarb53e13a2020-10-21 12:19:53 +02001593 au InsertLeavePre * let g:did_au_pre = 1
Bram Moolenaar4dbc2622018-11-02 11:59:15 +01001594 au InsertLeave * let g:did_au = 1
Bram Moolenaarb53e13a2020-10-21 12:19:53 +02001595 let g:did_au_pre = 0
Bram Moolenaar4dbc2622018-11-02 11:59:15 +01001596 let g:did_au = 0
1597 call feedkeys("afoo\<Esc>", 'tx')
Bram Moolenaarb53e13a2020-10-21 12:19:53 +02001598 call assert_equal(1, g:did_au_pre)
Bram Moolenaar4dbc2622018-11-02 11:59:15 +01001599 call assert_equal(1, g:did_au)
1600 call assert_equal('foo', getline(1))
1601
Bram Moolenaarb53e13a2020-10-21 12:19:53 +02001602 let g:did_au_pre = 0
Bram Moolenaar4dbc2622018-11-02 11:59:15 +01001603 let g:did_au = 0
1604 call feedkeys("Sbar\<C-C>", 'tx')
Bram Moolenaarb53e13a2020-10-21 12:19:53 +02001605 call assert_equal(1, g:did_au_pre)
Bram Moolenaar4dbc2622018-11-02 11:59:15 +01001606 call assert_equal(0, g:did_au)
1607 call assert_equal('bar', getline(1))
1608
1609 inoremap x xx<Esc>
Bram Moolenaarb53e13a2020-10-21 12:19:53 +02001610 let g:did_au_pre = 0
Bram Moolenaar4dbc2622018-11-02 11:59:15 +01001611 let g:did_au = 0
1612 call feedkeys("Saax", 'tx')
Bram Moolenaarb53e13a2020-10-21 12:19:53 +02001613 call assert_equal(1, g:did_au_pre)
Bram Moolenaar4dbc2622018-11-02 11:59:15 +01001614 call assert_equal(1, g:did_au)
1615 call assert_equal('aaxx', getline(1))
1616
1617 inoremap x xx<C-C>
Bram Moolenaarb53e13a2020-10-21 12:19:53 +02001618 let g:did_au_pre = 0
Bram Moolenaar4dbc2622018-11-02 11:59:15 +01001619 let g:did_au = 0
1620 call feedkeys("Sbbx", 'tx')
Bram Moolenaarb53e13a2020-10-21 12:19:53 +02001621 call assert_equal(1, g:did_au_pre)
Bram Moolenaar4dbc2622018-11-02 11:59:15 +01001622 call assert_equal(0, g:did_au)
1623 call assert_equal('bbxx', getline(1))
1624
1625 bwipe!
Bram Moolenaarb53e13a2020-10-21 12:19:53 +02001626 au! InsertLeave InsertLeavePre
Bram Moolenaar4dbc2622018-11-02 11:59:15 +01001627 iunmap x
1628endfunc
Bram Moolenaarc6b37db2019-04-27 18:00:34 +02001629
Bram Moolenaardb934952020-04-27 20:18:31 +02001630func Test_edit_InsertLeave_undo()
1631 new XtestUndo
1632 set undofile
1633 au InsertLeave * wall
1634 exe "normal ofoo\<Esc>"
1635 call assert_equal(2, line('$'))
1636 normal u
1637 call assert_equal(1, line('$'))
1638
1639 bwipe!
1640 au! InsertLeave
1641 call delete('XtestUndo')
Bram Moolenaarb340bae2020-06-15 19:51:56 +02001642 call delete(undofile('XtestUndo'))
Bram Moolenaardb934952020-04-27 20:18:31 +02001643 set undofile&
1644endfunc
1645
Bram Moolenaarc6b37db2019-04-27 18:00:34 +02001646" Test for inserting characters using CTRL-V followed by a number.
1647func Test_edit_special_chars()
1648 new
1649
Bram Moolenaar424bcae2022-01-31 14:59:41 +00001650 let t = "o\<C-V>65\<C-V>x42\<C-V>o103 \<C-V>33a\<C-V>xfg\<C-V>o78\<Esc>"
Bram Moolenaarc6b37db2019-04-27 18:00:34 +02001651
1652 exe "normal " . t
1653 call assert_equal("ABC !a\<C-O>g\<C-G>8", getline(2))
1654
1655 close!
1656endfunc
Bram Moolenaar8d3b5102019-09-05 21:29:01 +02001657
1658func Test_edit_startinsert()
1659 new
1660 set backspace+=start
1661 call setline(1, 'foobar')
1662 call feedkeys("A\<C-U>\<Esc>", 'xt')
1663 call assert_equal('', getline(1))
1664
1665 call setline(1, 'foobar')
1666 call feedkeys(":startinsert!\<CR>\<C-U>\<Esc>", 'xt')
1667 call assert_equal('', getline(1))
1668
1669 set backspace&
1670 bwipe!
1671endfunc
Bram Moolenaar177c9f22019-11-06 13:59:16 +01001672
Bram Moolenaarbc2b71d2020-02-17 21:33:30 +01001673" Test for :startreplace and :startgreplace
1674func Test_edit_startreplace()
1675 new
1676 call setline(1, 'abc')
1677 call feedkeys("l:startreplace\<CR>xyz\e", 'xt')
1678 call assert_equal('axyz', getline(1))
1679 call feedkeys("0:startreplace!\<CR>abc\e", 'xt')
1680 call assert_equal('axyzabc', getline(1))
1681 call setline(1, "a\tb")
1682 call feedkeys("0l:startgreplace\<CR>xyz\e", 'xt')
1683 call assert_equal("axyz\tb", getline(1))
1684 call feedkeys("0i\<C-R>=execute('startreplace')\<CR>12\e", 'xt')
1685 call assert_equal("12axyz\tb", getline(1))
1686 close!
1687endfunc
1688
Bram Moolenaar177c9f22019-11-06 13:59:16 +01001689func Test_edit_noesckeys()
Bram Moolenaar215ba3b2019-11-06 15:07:07 +01001690 CheckNotGui
Bram Moolenaar177c9f22019-11-06 13:59:16 +01001691 new
1692
1693 " <Left> moves cursor when 'esckeys' is set
1694 exe "set t_kl=\<Esc>OD"
1695 set esckeys
1696 call feedkeys("axyz\<Esc>ODX", "xt")
1697 call assert_equal("xyXz", getline(1))
1698
1699 " <Left> exits Insert mode when 'esckeys' is off
1700 set noesckeys
1701 call setline(1, '')
1702 call feedkeys("axyz\<Esc>ODX", "xt")
1703 call assert_equal(["DX", "xyz"], getline(1, 2))
1704
1705 bwipe!
1706 set esckeys
1707endfunc
Bram Moolenaarbc2b71d2020-02-17 21:33:30 +01001708
Bram Moolenaar1671f442020-03-10 07:48:13 +01001709" Test for running an invalid ex command in insert mode using CTRL-O
Bram Moolenaar1671f442020-03-10 07:48:13 +01001710func Test_edit_ctrl_o_invalid_cmd()
1711 new
1712 set showmode showcmd
Bram Moolenaarb340bae2020-06-15 19:51:56 +02001713 " Avoid a sleep of 3 seconds. Zero might have side effects.
1714 call test_override('ui_delay', 50)
Bram Moolenaar1671f442020-03-10 07:48:13 +01001715 let caught_e492 = 0
1716 try
1717 call feedkeys("i\<C-O>:invalid\<CR>abc\<Esc>", "xt")
1718 catch /E492:/
1719 let caught_e492 = 1
1720 endtry
1721 call assert_equal(1, caught_e492)
1722 call assert_equal('abc', getline(1))
1723 set showmode& showcmd&
Bram Moolenaarb340bae2020-06-15 19:51:56 +02001724 call test_override('ui_delay', 0)
Bram Moolenaar1671f442020-03-10 07:48:13 +01001725 close!
1726endfunc
1727
Bram Moolenaarb340bae2020-06-15 19:51:56 +02001728" Test for editing a file with a very long name
1729func Test_edit_illegal_filename()
1730 CheckEnglish
1731 new
1732 redir => msg
1733 exe 'edit ' . repeat('f', 5000)
1734 redir END
1735 call assert_match("Illegal file name$", split(msg, "\n")[0])
1736 close!
1737endfunc
1738
Bram Moolenaarc8fe6452020-10-03 17:04:37 +02001739" Test for editing a directory
1740func Test_edit_is_a_directory()
1741 CheckEnglish
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01001742 let dirname = getcwd() . "/Xeditdir"
Bram Moolenaarc8fe6452020-10-03 17:04:37 +02001743 call mkdir(dirname, 'p')
1744
1745 new
1746 redir => msg
1747 exe 'edit' dirname
1748 redir END
1749 call assert_match("is a directory$", split(msg, "\n")[0])
1750 bwipe!
1751
1752 let dirname .= '/'
1753
1754 new
1755 redir => msg
1756 exe 'edit' dirname
1757 redir END
1758 call assert_match("is a directory$", split(msg, "\n")[0])
1759 bwipe!
1760
1761 call delete(dirname, 'rf')
1762endfunc
1763
Bram Moolenaarb340bae2020-06-15 19:51:56 +02001764" Test for editing a file using invalid file encoding
1765func Test_edit_invalid_encoding()
1766 CheckEnglish
Bram Moolenaar14f91762022-09-21 15:13:52 +01001767 call writefile([], 'Xinvfile', 'D')
Bram Moolenaarb340bae2020-06-15 19:51:56 +02001768 redir => msg
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001769 new ++enc=axbyc Xinvfile
Bram Moolenaarb340bae2020-06-15 19:51:56 +02001770 redir END
1771 call assert_match('\[NOT converted\]', msg)
Bram Moolenaarb340bae2020-06-15 19:51:56 +02001772 close!
1773endfunc
1774
1775" Test for the "charconvert" option
1776func Test_edit_charconvert()
1777 CheckEnglish
Bram Moolenaar14f91762022-09-21 15:13:52 +01001778 call writefile(['one', 'two'], 'Xccfile', 'D')
Bram Moolenaarb340bae2020-06-15 19:51:56 +02001779
1780 " set 'charconvert' to a non-existing function
1781 set charconvert=NonExitingFunc()
1782 new
1783 let caught_e117 = v:false
1784 try
1785 redir => msg
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001786 edit ++enc=axbyc Xccfile
Bram Moolenaarb340bae2020-06-15 19:51:56 +02001787 catch /E117:/
1788 let caught_e117 = v:true
1789 finally
1790 redir END
1791 endtry
1792 call assert_true(caught_e117)
1793 call assert_equal(['one', 'two'], getline(1, '$'))
1794 call assert_match("Conversion with 'charconvert' failed", msg)
1795 close!
1796 set charconvert&
1797
Christian Brabandtee17b6f2023-09-09 11:23:50 +02001798 " 'charconvert' function doesn't create an output file
Bram Moolenaarb340bae2020-06-15 19:51:56 +02001799 func Cconv1()
1800 endfunc
1801 set charconvert=Cconv1()
1802 new
1803 redir => msg
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001804 edit ++enc=axbyc Xccfile
Bram Moolenaarb340bae2020-06-15 19:51:56 +02001805 redir END
1806 call assert_equal(['one', 'two'], getline(1, '$'))
1807 call assert_match("can't read output of 'charconvert'", msg)
1808 close!
1809 delfunc Cconv1
1810 set charconvert&
1811
1812 " 'charconvert' function to convert to upper case
1813 func Cconv2()
1814 let data = readfile(v:fname_in)
1815 call map(data, 'toupper(v:val)')
1816 call writefile(data, v:fname_out)
1817 endfunc
1818 set charconvert=Cconv2()
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001819 new Xccfile
1820 write ++enc=ucase Xccfile1
1821 call assert_equal(['ONE', 'TWO'], readfile('Xccfile1'))
1822 call delete('Xccfile1')
Bram Moolenaarb340bae2020-06-15 19:51:56 +02001823 close!
1824 delfunc Cconv2
1825 set charconvert&
1826
1827 " 'charconvert' function removes the input file
1828 func Cconv3()
1829 call delete(v:fname_in)
1830 endfunc
1831 set charconvert=Cconv3()
1832 new
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001833 call assert_fails('edit ++enc=lcase Xccfile', 'E202:')
Bram Moolenaarb340bae2020-06-15 19:51:56 +02001834 call assert_equal([''], getline(1, '$'))
1835 close!
1836 delfunc Cconv3
1837 set charconvert&
Bram Moolenaarb340bae2020-06-15 19:51:56 +02001838endfunc
1839
1840" Test for editing a file without read permission
1841func Test_edit_file_no_read_perm()
1842 CheckUnix
Bram Moolenaar17709e22021-03-19 14:38:12 +01001843 CheckNotRoot
1844
Bram Moolenaar14f91762022-09-21 15:13:52 +01001845 call writefile(['one', 'two'], 'Xnrpfile', 'D')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001846 call setfperm('Xnrpfile', '-w-------')
Bram Moolenaarb340bae2020-06-15 19:51:56 +02001847 new
1848 redir => msg
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001849 edit Xnrpfile
Bram Moolenaarb340bae2020-06-15 19:51:56 +02001850 redir END
1851 call assert_equal(1, &readonly)
1852 call assert_equal([''], getline(1, '$'))
1853 call assert_match('\[Permission Denied\]', msg)
1854 close!
Bram Moolenaarb340bae2020-06-15 19:51:56 +02001855endfunc
1856
zeertzjq3a56b6d2022-04-08 11:56:14 +01001857" Using :edit without leaving 'insertmode' should not cause Insert mode to be
1858" re-entered immediately after <C-L>
1859func Test_edit_insertmode_ex_edit()
1860 CheckRunVimInTerminal
1861
1862 let lines =<< trim END
1863 set insertmode noruler
1864 inoremap <C-B> <Cmd>edit Xfoo<CR>
1865 END
Bram Moolenaar14f91762022-09-21 15:13:52 +01001866 call writefile(lines, 'Xtest_edit_insertmode_ex_edit', 'D')
zeertzjq3a56b6d2022-04-08 11:56:14 +01001867
Bram Moolenaar14f91762022-09-21 15:13:52 +01001868 let buf = RunVimInTerminal('-S Xtest_edit_insertmode_ex_edit', #{rows: 6, wait_for_ruler: 0})
1869 " Somehow when using valgrind "INSERT" does not show up unless we send
1870 " something to the terminal.
1871 for i in range(30)
1872 if term_getline(buf, 6) =~ 'INSERT'
1873 break
1874 endif
1875 call term_sendkeys(buf, "-")
1876 sleep 100m
1877 endfor
Bram Moolenaarc5382b62022-06-19 15:22:36 +01001878 call WaitForAssert({-> assert_match('^-- INSERT --\s*$', term_getline(buf, 6))})
zeertzjq3a56b6d2022-04-08 11:56:14 +01001879 call term_sendkeys(buf, "\<C-B>\<C-L>")
Bram Moolenaarc5382b62022-06-19 15:22:36 +01001880 call WaitForAssert({-> assert_notmatch('^-- INSERT --\s*$', term_getline(buf, 6))})
zeertzjq3a56b6d2022-04-08 11:56:14 +01001881
1882 " clean up
1883 call StopVimInTerminal(buf)
zeertzjq3a56b6d2022-04-08 11:56:14 +01001884endfunc
1885
Bram Moolenaar845e0ee2020-06-20 16:05:32 +02001886" Pressing escape in 'insertmode' should beep
Bram Moolenaarc5382b62022-06-19 15:22:36 +01001887" FIXME: Execute this later, when using valgrind it makes the next test
1888" Test_edit_insertmode_ex_edit() fail.
1889func Test_z_edit_insertmode_esc_beeps()
Bram Moolenaar845e0ee2020-06-20 16:05:32 +02001890 new
1891 set insertmode
1892 call assert_beeps("call feedkeys(\"one\<Esc>\", 'xt')")
1893 set insertmode&
Bram Moolenaarc5382b62022-06-19 15:22:36 +01001894 " unsupported "CTRL-G l" command should beep in insert mode.
Bram Moolenaar845e0ee2020-06-20 16:05:32 +02001895 call assert_beeps("normal i\<C-G>l")
Bram Moolenaarc5382b62022-06-19 15:22:36 +01001896 bwipe!
Bram Moolenaar845e0ee2020-06-20 16:05:32 +02001897endfunc
1898
1899" Test for 'hkmap' and 'hkmapp'
1900func Test_edit_hkmap()
1901 CheckFeature rightleft
1902 if has('win32') && !has('gui')
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001903 throw 'Skipped: fails on the MS-Windows terminal version'
Bram Moolenaar845e0ee2020-06-20 16:05:32 +02001904 endif
1905 new
1906
1907 set revins hkmap
1908 let str = 'abcdefghijklmnopqrstuvwxyz'
1909 let str ..= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
1910 let str ..= '`/'',.;'
1911 call feedkeys('i' .. str, 'xt')
1912 let expected = "óõú,.;"
1913 let expected ..= "ZYXWVUTSRQPONMLKJIHGFEDCBA"
1914 let expected ..= "æèñ'äåàãø/ôíîöêìçïéòë÷âáðù"
1915 call assert_equal(expected, getline(1))
1916
1917 %d
1918 set revins hkmap hkmapp
1919 let str = 'abcdefghijklmnopqrstuvwxyz'
1920 let str ..= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
1921 call feedkeys('i' .. str, 'xt')
1922 let expected = "õYXWVUTSRQóOïíLKJIHGFEDêBA"
1923 let expected ..= "öòXùåèúæø'ôñðîì÷çéäâóǟãëáà"
1924 call assert_equal(expected, getline(1))
1925
1926 set revins& hkmap& hkmapp&
1927 close!
1928endfunc
1929
1930" Test for 'allowrevins' and using CTRL-_ in insert mode
1931func Test_edit_allowrevins()
1932 CheckFeature rightleft
1933 new
1934 set allowrevins
1935 call feedkeys("iABC\<C-_>DEF\<C-_>GHI", 'xt')
1936 call assert_equal('ABCFEDGHI', getline(1))
1937 set allowrevins&
1938 close!
1939endfunc
1940
1941" Test for inserting a register in insert mode using CTRL-R
1942func Test_edit_insert_reg()
1943 new
1944 let g:Line = ''
1945 func SaveFirstLine()
1946 let g:Line = Screenline(1)
1947 return 'r'
1948 endfunc
1949 inoremap <expr> <buffer> <F2> SaveFirstLine()
1950 call test_override('redraw_flag', 1)
1951 call test_override('char_avail', 1)
1952 let @r = 'sample'
1953 call feedkeys("a\<C-R>=SaveFirstLine()\<CR>", "xt")
1954 call assert_equal('"', g:Line)
1955 call test_override('ALL', 0)
1956 close!
1957endfunc
1958
Bram Moolenaarc174c2e2023-03-25 20:06:49 +00001959" Test for positioning cursor after CTRL-R expression failed
1960func Test_edit_ctrl_r_failed()
1961 CheckRunVimInTerminal
1962
1963 let buf = RunVimInTerminal('', #{rows: 6, cols: 60})
1964
Yegappan Lakshmananf01493c2024-04-14 23:21:02 +02001965 " trying to insert a blob produces an error
1966 call term_sendkeys(buf, "i\<C-R>=0z\<CR>")
Bram Moolenaarc174c2e2023-03-25 20:06:49 +00001967
1968 " ending Insert mode should put the cursor back on the ':'
1969 call term_sendkeys(buf, ":\<Esc>")
1970 call VerifyScreenDump(buf, 'Test_edit_ctlr_r_failed_1', {})
1971
1972 call StopVimInTerminal(buf)
1973endfunc
1974
Bram Moolenaar845e0ee2020-06-20 16:05:32 +02001975" When a character is inserted at the last position of the last line in a
1976" window, the window contents should be scrolled one line up. If the top line
1977" is part of a fold, then the entire fold should be scrolled up.
1978func Test_edit_lastline_scroll()
1979 new
1980 let h = winheight(0)
1981 let lines = ['one', 'two', 'three']
1982 let lines += repeat(['vim'], h - 4)
1983 call setline(1, lines)
1984 call setline(h, repeat('x', winwidth(0) - 1))
1985 call feedkeys("GAx", 'xt')
1986 redraw!
1987 call assert_equal(h - 1, winline())
1988 call assert_equal(2, line('w0'))
1989
1990 " scroll with a fold
1991 1,2fold
1992 normal gg
1993 call setline(h + 1, repeat('x', winwidth(0) - 1))
1994 call feedkeys("GAx", 'xt')
1995 redraw!
1996 call assert_equal(h - 1, winline())
1997 call assert_equal(3, line('w0'))
1998
1999 close!
2000endfunc
2001
Bram Moolenaar21cbe172020-10-13 19:08:24 +02002002func Test_edit_browse()
2003 " in the GUI this opens a file picker, we only test the terminal behavior
2004 CheckNotGui
2005
2006 " ":browse xxx" checks for the FileExplorer augroup and assumes editing "."
2007 " works then.
2008 augroup FileExplorer
2009 au!
2010 augroup END
2011
2012 " When the USE_FNAME_CASE is defined this used to cause a crash.
2013 browse enew
2014 bwipe!
2015
2016 browse split
2017 bwipe!
2018endfunc
2019
Bram Moolenaarcaf73dc2020-10-26 21:39:13 +01002020func Test_read_invalid()
2021 set encoding=latin1
2022 " This was not properly checking for going past the end.
2023 call assert_fails('r`=', 'E484')
2024 set encoding=utf-8
2025endfunc
2026
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02002027" Test for the 'revins' option
2028func Test_edit_revins()
2029 CheckFeature rightleft
2030 new
2031 set revins
2032 exe "normal! ione\ttwo three"
2033 call assert_equal("eerht owt\teno", getline(1))
2034 call setline(1, "one\ttwo three")
2035 normal! gg$bi a
2036 call assert_equal("one\ttwo a three", getline(1))
2037 exe "normal! $bi\<BS>\<BS>"
2038 call assert_equal("one\ttwo a ree", getline(1))
2039 exe "normal! 0wi\<C-W>"
2040 call assert_equal("one\t a ree", getline(1))
2041 exe "normal! 0wi\<C-U>"
2042 call assert_equal("one\t ", getline(1))
2043 " newline in insert mode starts at the end of the line
2044 call setline(1, 'one two three')
2045 exe "normal! wi\nfour"
2046 call assert_equal(['one two three', 'ruof'], getline(1, '$'))
zeertzjq8ede7a02024-03-28 10:30:08 +01002047 set backspace=indent,eol,start
2048 exe "normal! ggA\<BS>:"
2049 call assert_equal(['one two three:ruof'], getline(1, '$'))
2050 set revins& backspace&
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02002051 bw!
2052endfunc
2053
Bram Moolenaar35a9a002021-09-11 21:14:20 +02002054" Test for getting the character of the line below after "p"
2055func Test_edit_put_CTRL_E()
2056 set encoding=latin1
2057 new
2058 let @" = ''
2059 sil! norm orggRx
2060 sil! norm pr
2061 call assert_equal(['r', 'r'], getline(1, 2))
2062 bwipe!
2063 set encoding=utf-8
2064endfunc
2065
Dominique Pelle9cd063e2021-10-28 21:06:05 +01002066" Test toggling of input method. See :help i_CTRL-^
2067func Test_edit_CTRL_hat()
2068 CheckFeature xim
Dominique Pelle8753c1d2021-10-31 20:19:17 +00002069
Bram Moolenaar0b962e52022-04-03 18:02:37 +01002070 " FIXME: test fails with Motif GUI.
Dominique Pelle8753c1d2021-10-31 20:19:17 +00002071 " test also fails when running in the GUI.
2072 CheckFeature gui_gtk
2073 CheckNotGui
Dominique Pelle9cd063e2021-10-28 21:06:05 +01002074
2075 new
2076
2077 call assert_equal(0, &iminsert)
2078 call feedkeys("i\<C-^>", 'xt')
2079 call assert_equal(2, &iminsert)
2080 call feedkeys("i\<C-^>", 'xt')
2081 call assert_equal(0, &iminsert)
2082
2083 bwipe!
2084endfunc
2085
Bram Moolenaarde05bb22022-01-13 13:08:14 +00002086" Weird long file name was going over the end of NameBuff
2087func Test_edit_overlong_file_name()
2088 CheckUnix
2089
2090 file 0000000000000000000000000000
2091 file %%%%%%%%%%%%%%%%%%%%%%%%%%
2092 file %%%%%%
2093 set readonly
Bram Moolenaar94722c52023-01-28 19:19:03 +00002094 set ls=2
Bram Moolenaarde05bb22022-01-13 13:08:14 +00002095
2096 redraw!
2097 set noreadonly ls&
2098 bwipe!
2099endfunc
2100
Christian Brabandtdfbdadc2022-05-05 20:46:47 +01002101func Test_edit_shift_bs()
2102 CheckMSWindows
2103
2104 " FIXME: this works interactively, but the test fails
2105 throw 'Skipped: Shift-Backspace Test not working correctly :('
2106
2107 " Need to run this in Win32 Terminal, do not use CheckRunVimInTerminal
2108 if !has("terminal")
2109 return
2110 endif
2111
2112 " Shift Backspace should work like Backspace in insert mode
2113 let lines =<< trim END
2114 call setline(1, ['abc'])
2115 END
Bram Moolenaar14f91762022-09-21 15:13:52 +01002116 call writefile(lines, 'Xtest_edit_shift_bs', 'D')
Christian Brabandtdfbdadc2022-05-05 20:46:47 +01002117
2118 let buf = RunVimInTerminal('-S Xtest_edit_shift_bs', #{rows: 3})
2119 call term_sendkeys(buf, "A\<S-BS>-\<esc>")
2120 call TermWait(buf, 50)
2121 call assert_equal('ab-', term_getline(buf, 1))
2122
2123 " clean up
2124 call StopVimInTerminal(buf)
Christian Brabandtdfbdadc2022-05-05 20:46:47 +01002125endfunc
Dominique Pelle9cd063e2021-10-28 21:06:05 +01002126
altermo7d711fe2024-01-16 17:25:17 +01002127func Test_edit_Ctrl_RSB()
2128 new
2129 let g:triggered = []
2130 autocmd InsertCharPre <buffer> let g:triggered += [v:char]
2131
2132 " i_CTRL-] should not trigger InsertCharPre
2133 exe "normal! A\<C-]>"
2134 call assert_equal([], g:triggered)
2135
2136 " i_CTRL-] should expand abbreviations but not trigger InsertCharPre
2137 inoreabbr <buffer> f foo
2138 exe "normal! Af\<C-]>a"
2139 call assert_equal(['f', 'f', 'o', 'o', 'a'], g:triggered)
2140 call assert_equal('fooa', getline(1))
2141
2142 " CTRL-] followed by i_CTRL-V should not expand abbreviations
2143 " i_CTRL-V doesn't trigger InsertCharPre
2144 call setline(1, '')
2145 exe "normal! Af\<C-V>\<C-]>"
2146 call assert_equal("f\<C-]>", getline(1))
2147
2148 let g:triggered = []
2149 call setline(1, '')
2150
2151 " Also test assigning to v:char
2152 autocmd InsertCharPre <buffer> let v:char = 'f'
2153 exe "normal! Ag\<C-]>h"
2154 call assert_equal(['g', 'f', 'o', 'o', 'h'], g:triggered)
2155 call assert_equal('ffff', getline(1))
2156
2157 autocmd! InsertCharPre
2158 unlet g:triggered
2159 bwipe!
2160endfunc
2161
zeertzjq0185c772024-03-25 16:34:51 +01002162func s:check_backspace(expected)
2163 let g:actual = []
2164 inoremap <buffer> <F2> <Cmd>let g:actual += [getline('.')]<CR>
2165 set backspace=indent,eol,start
2166
zeertzjq8ede7a02024-03-28 10:30:08 +01002167 exe "normal i" .. repeat("\<BS>\<F2>", len(a:expected))
zeertzjq0185c772024-03-25 16:34:51 +01002168 call assert_equal(a:expected, g:actual)
2169
2170 set backspace&
2171 iunmap <buffer> <F2>
2172 unlet g:actual
2173endfunc
2174
2175" Test that backspace works with 'smarttab' and mixed Tabs and spaces.
2176func Test_edit_backspace_smarttab_mixed()
zeertzjq8ede7a02024-03-28 10:30:08 +01002177 set smarttab
zeertzjq0185c772024-03-25 16:34:51 +01002178 call NewWindow(1, 30)
zeertzjq8ede7a02024-03-28 10:30:08 +01002179 setlocal tabstop=4 shiftwidth=4
2180
zeertzjq0185c772024-03-25 16:34:51 +01002181 call setline(1, "\t \t \t a")
zeertzjq8ede7a02024-03-28 10:30:08 +01002182 normal! $
zeertzjq0185c772024-03-25 16:34:51 +01002183 call s:check_backspace([
2184 \ "\t \t \ta",
2185 \ "\t \t a",
2186 \ "\t \t a",
2187 \ "\t \ta",
2188 \ "\t a",
2189 \ "\ta",
2190 \ "a",
2191 \ ])
2192
2193 call CloseWindow()
zeertzjq8ede7a02024-03-28 10:30:08 +01002194 set smarttab&
zeertzjq0185c772024-03-25 16:34:51 +01002195endfunc
2196
2197" Test that backspace works with 'smarttab' and 'varsofttabstop'.
2198func Test_edit_backspace_smarttab_varsofttabstop()
2199 CheckFeature vartabs
2200
zeertzjq8ede7a02024-03-28 10:30:08 +01002201 set smarttab
zeertzjq0185c772024-03-25 16:34:51 +01002202 call NewWindow(1, 30)
zeertzjq8ede7a02024-03-28 10:30:08 +01002203 setlocal tabstop=8 varsofttabstop=6,2,5,3
2204
zeertzjq0185c772024-03-25 16:34:51 +01002205 call setline(1, "a\t \t a")
zeertzjq8ede7a02024-03-28 10:30:08 +01002206 normal! $
zeertzjq0185c772024-03-25 16:34:51 +01002207 call s:check_backspace([
2208 \ "a\t \ta",
2209 \ "a\t a",
2210 \ "a\ta",
2211 \ "a a",
2212 \ "aa",
2213 \ "a",
2214 \ ])
2215
2216 call CloseWindow()
zeertzjq8ede7a02024-03-28 10:30:08 +01002217 set smarttab&
zeertzjq0185c772024-03-25 16:34:51 +01002218endfunc
2219
2220" Test that backspace works with 'smarttab' when a Tab is shown as "^I".
2221func Test_edit_backspace_smarttab_list()
zeertzjq8ede7a02024-03-28 10:30:08 +01002222 set smarttab
zeertzjq0185c772024-03-25 16:34:51 +01002223 call NewWindow(1, 30)
zeertzjq8ede7a02024-03-28 10:30:08 +01002224 setlocal tabstop=4 shiftwidth=4 list listchars=
2225
zeertzjq0185c772024-03-25 16:34:51 +01002226 call setline(1, "\t \t \t a")
zeertzjq8ede7a02024-03-28 10:30:08 +01002227 normal! $
zeertzjq0185c772024-03-25 16:34:51 +01002228 call s:check_backspace([
2229 \ "\t \t a",
2230 \ "\t \t a",
2231 \ "\t \ta",
2232 \ "\t a",
2233 \ "a",
2234 \ ])
2235
2236 call CloseWindow()
zeertzjq8ede7a02024-03-28 10:30:08 +01002237 set smarttab&
zeertzjq0185c772024-03-25 16:34:51 +01002238endfunc
2239
2240" Test that backspace works with 'smarttab' and 'breakindent'.
2241func Test_edit_backspace_smarttab_breakindent()
2242 CheckFeature linebreak
2243
zeertzjq8ede7a02024-03-28 10:30:08 +01002244 set smarttab
zeertzjq0185c772024-03-25 16:34:51 +01002245 call NewWindow(3, 17)
zeertzjq8ede7a02024-03-28 10:30:08 +01002246 setlocal tabstop=4 shiftwidth=4 breakindent breakindentopt=min:5
2247
zeertzjq0185c772024-03-25 16:34:51 +01002248 call setline(1, "\t \t \t a")
zeertzjq8ede7a02024-03-28 10:30:08 +01002249 normal! $
zeertzjq0185c772024-03-25 16:34:51 +01002250 call s:check_backspace([
2251 \ "\t \t \ta",
2252 \ "\t \t a",
2253 \ "\t \t a",
2254 \ "\t \ta",
2255 \ "\t a",
2256 \ "\ta",
2257 \ "a",
2258 \ ])
2259
2260 call CloseWindow()
zeertzjq8ede7a02024-03-28 10:30:08 +01002261 set smarttab&
zeertzjq0185c772024-03-25 16:34:51 +01002262endfunc
2263
2264" Test that backspace works with 'smarttab' and virtual text.
2265func Test_edit_backspace_smarttab_virtual_text()
2266 CheckFeature textprop
2267
zeertzjq8ede7a02024-03-28 10:30:08 +01002268 set smarttab
zeertzjq0185c772024-03-25 16:34:51 +01002269 call NewWindow(1, 50)
zeertzjq8ede7a02024-03-28 10:30:08 +01002270 setlocal tabstop=4 shiftwidth=4
2271
zeertzjq0185c772024-03-25 16:34:51 +01002272 call setline(1, "\t \t \t a")
2273 call prop_type_add('theprop', {})
2274 call prop_add(1, 3, {'type': 'theprop', 'text': 'text'})
zeertzjq8ede7a02024-03-28 10:30:08 +01002275 normal! $
zeertzjq0185c772024-03-25 16:34:51 +01002276 call s:check_backspace([
2277 \ "\t \t \ta",
2278 \ "\t \t a",
2279 \ "\t \t a",
2280 \ "\t \ta",
2281 \ "\t a",
2282 \ "\ta",
2283 \ "a",
2284 \ ])
2285
2286 call CloseWindow()
2287 call prop_type_delete('theprop')
zeertzjq8ede7a02024-03-28 10:30:08 +01002288 set smarttab&
zeertzjq0185c772024-03-25 16:34:51 +01002289endfunc
2290
Bram Moolenaarbc2b71d2020-02-17 21:33:30 +01002291" vim: shiftwidth=2 sts=2 expandtab