blob: d2f1fab5732040494c87150be21371b603a2799b [file] [log] [blame]
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001" Test for various Normal mode commands
2
Bram Moolenaara84a3dd2019-03-25 22:21:24 +01003source shared.vim
Bram Moolenaar5a4c3082019-12-01 15:23:11 +01004source check.vim
Bram Moolenaarca68ae12020-03-30 19:32:53 +02005source view_util.vim
Bram Moolenaara84a3dd2019-03-25 22:21:24 +01006
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01007func Setup_NewWindow()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02008 10new
9 call setline(1, range(1,100))
10endfunc
11
Bram Moolenaar1bbb6192018-11-10 16:02:01 +010012func MyFormatExpr()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020013 " Adds '->$' at lines having numbers followed by trailing whitespace
14 for ln in range(v:lnum, v:lnum+v:count-1)
15 let line = getline(ln)
16 if getline(ln) =~# '\d\s\+$'
17 call setline(ln, substitute(line, '\s\+$', '', '') . '->$')
18 endif
19 endfor
Bram Moolenaar2931f2a2016-09-09 16:59:08 +020020endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020021
Bram Moolenaar1bbb6192018-11-10 16:02:01 +010022func CountSpaces(type, ...)
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020023 " for testing operatorfunc
24 " will count the number of spaces
25 " and return the result in g:a
26 let sel_save = &selection
27 let &selection = "inclusive"
28 let reg_save = @@
29
30 if a:0 " Invoked from Visual mode, use gv command.
31 silent exe "normal! gvy"
32 elseif a:type == 'line'
33 silent exe "normal! '[V']y"
34 else
35 silent exe "normal! `[v`]y"
36 endif
37 let g:a=strlen(substitute(@@, '[^ ]', '', 'g'))
38 let &selection = sel_save
39 let @@ = reg_save
Bram Moolenaar2931f2a2016-09-09 16:59:08 +020040endfunc
41
Bram Moolenaar1bbb6192018-11-10 16:02:01 +010042func OpfuncDummy(type, ...)
Bram Moolenaar4a08b0d2016-11-05 21:55:13 +010043 " for testing operatorfunc
44 let g:opt=&linebreak
45
46 if a:0 " Invoked from Visual mode, use gv command.
47 silent exe "normal! gvy"
48 elseif a:type == 'line'
49 silent exe "normal! '[V']y"
50 else
51 silent exe "normal! `[v`]y"
52 endif
53 " Create a new dummy window
54 new
55 let g:bufnr=bufnr('%')
Bram Moolenaar2931f2a2016-09-09 16:59:08 +020056endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020057
Bram Moolenaar1671f442020-03-10 07:48:13 +010058func Test_normal00_optrans()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020059 new
60 call append(0, ['1 This is a simple test: abcd', '2 This is the second line', '3 this is the third line'])
61 1
62 exe "norm! Sfoobar\<esc>"
63 call assert_equal(['foobar', '2 This is the second line', '3 this is the third line', ''], getline(1,'$'))
64 2
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020065 exe "norm! $vbsone"
66 call assert_equal(['foobar', '2 This is the second one', '3 this is the third line', ''], getline(1,'$'))
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020067 norm! VS Second line here
68 call assert_equal(['foobar', ' Second line here', '3 this is the third line', ''], getline(1, '$'))
69 %d
70 call append(0, ['4 This is a simple test: abcd', '5 This is the second line', '6 this is the third line'])
71 call append(0, ['1 This is a simple test: abcd', '2 This is the second line', '3 this is the third line'])
72
73 1
74 norm! 2D
75 call assert_equal(['3 this is the third line', '4 This is a simple test: abcd', '5 This is the second line', '6 this is the third line', ''], getline(1,'$'))
76 set cpo+=#
77 norm! 4D
78 call assert_equal(['', '4 This is a simple test: abcd', '5 This is the second line', '6 this is the third line', ''], getline(1,'$'))
79
80 " clean up
81 set cpo-=#
82 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +020083endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020084
Bram Moolenaar1bbb6192018-11-10 16:02:01 +010085func Test_normal01_keymodel()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020086 call Setup_NewWindow()
87 " Test 1: depending on 'keymodel' <s-down> does something different
Bram Moolenaar2931f2a2016-09-09 16:59:08 +020088 50
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020089 call feedkeys("V\<S-Up>y", 'tx')
90 call assert_equal(['47', '48', '49', '50'], getline("'<", "'>"))
Bram Moolenaar2931f2a2016-09-09 16:59:08 +020091 set keymodel=startsel
92 50
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020093 call feedkeys("V\<S-Up>y", 'tx')
94 call assert_equal(['49', '50'], getline("'<", "'>"))
95 " Start visual mode when keymodel = startsel
Bram Moolenaar2931f2a2016-09-09 16:59:08 +020096 50
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020097 call feedkeys("\<S-Up>y", 'tx')
98 call assert_equal(['49', '5'], getreg(0, 0, 1))
Bram Moolenaar1671f442020-03-10 07:48:13 +010099 " Use the different Shift special keys
100 50
101 call feedkeys("\<S-Right>\<S-Left>\<S-Up>\<S-Down>\<S-Home>\<S-End>y", 'tx')
102 call assert_equal(['50'], getline("'<", "'>"))
103 call assert_equal(['50', ''], getreg(0, 0, 1))
104
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200105 " Do not start visual mode when keymodel=
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200106 set keymodel=
107 50
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200108 call feedkeys("\<S-Up>y$", 'tx')
109 call assert_equal(['42'], getreg(0, 0, 1))
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200110 " Stop visual mode when keymodel=stopsel
111 set keymodel=stopsel
112 50
113 call feedkeys("Vkk\<Up>yy", 'tx')
114 call assert_equal(['47'], getreg(0, 0, 1))
115
116 set keymodel=
117 50
118 call feedkeys("Vkk\<Up>yy", 'tx')
119 call assert_equal(['47', '48', '49', '50'], getreg(0, 0, 1))
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200120
Bram Moolenaard7e5e942020-10-07 16:54:52 +0200121 " Test for using special keys to start visual selection
122 %d
123 call setline(1, ['red fox tail', 'red fox tail', 'red fox tail'])
124 set keymodel=startsel
125 " Test for <S-PageUp> and <S-PageDown>
126 call cursor(1, 1)
127 call feedkeys("\<S-PageDown>y", 'xt')
128 call assert_equal([0, 1, 1, 0], getpos("'<"))
129 call assert_equal([0, 3, 1, 0], getpos("'>"))
130 call feedkeys("Gz\<CR>8|\<S-PageUp>y", 'xt')
131 call assert_equal([0, 2, 1, 0], getpos("'<"))
132 call assert_equal([0, 3, 8, 0], getpos("'>"))
133 " Test for <S-C-Home> and <S-C-End>
134 call cursor(2, 12)
135 call feedkeys("\<S-C-Home>y", 'xt')
136 call assert_equal([0, 1, 1, 0], getpos("'<"))
137 call assert_equal([0, 2, 12, 0], getpos("'>"))
138 call cursor(1, 4)
139 call feedkeys("\<S-C-End>y", 'xt')
140 call assert_equal([0, 1, 4, 0], getpos("'<"))
141 call assert_equal([0, 3, 13, 0], getpos("'>"))
142 " Test for <S-C-Left> and <S-C-Right>
143 call cursor(2, 5)
144 call feedkeys("\<S-C-Right>y", 'xt')
145 call assert_equal([0, 2, 5, 0], getpos("'<"))
146 call assert_equal([0, 2, 9, 0], getpos("'>"))
147 call cursor(2, 9)
148 call feedkeys("\<S-C-Left>y", 'xt')
149 call assert_equal([0, 2, 5, 0], getpos("'<"))
150 call assert_equal([0, 2, 9, 0], getpos("'>"))
151
152 set keymodel&
153
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200154 " clean up
155 bw!
156endfunc
157
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100158func Test_normal03_join()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200159 " basic join test
160 call Setup_NewWindow()
161 50
162 norm! VJ
163 call assert_equal('50 51', getline('.'))
164 $
165 norm! J
166 call assert_equal('100', getline('.'))
167 $
168 norm! V9-gJ
169 call assert_equal('919293949596979899100', getline('.'))
170 call setline(1, range(1,100))
171 $
172 :j 10
173 call assert_equal('100', getline('.'))
Bram Moolenaar004a6782020-04-11 17:09:31 +0200174 call assert_beeps('normal GVJ')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200175 " clean up
176 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200177endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200178
Bram Moolenaar004a6782020-04-11 17:09:31 +0200179" basic filter test
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100180func Test_normal04_filter()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200181 " only test on non windows platform
Bram Moolenaar004a6782020-04-11 17:09:31 +0200182 CheckNotMSWindows
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200183 call Setup_NewWindow()
184 1
185 call feedkeys("!!sed -e 's/^/| /'\n", 'tx')
186 call assert_equal('| 1', getline('.'))
187 90
188 :sil :!echo one
189 call feedkeys('.', 'tx')
190 call assert_equal('| 90', getline('.'))
191 95
192 set cpo+=!
193 " 2 <CR>, 1: for executing the command,
194 " 2: clear hit-enter-prompt
195 call feedkeys("!!\n", 'tx')
196 call feedkeys(":!echo one\n\n", 'tx')
197 call feedkeys(".", 'tx')
198 call assert_equal('one', getline('.'))
199 set cpo-=!
200 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200201endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200202
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100203func Test_normal05_formatexpr()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200204 " basic formatexpr test
205 call Setup_NewWindow()
206 %d_
207 call setline(1, ['here: 1 ', '2', 'here: 3 ', '4', 'not here: '])
208 1
209 set formatexpr=MyFormatExpr()
210 norm! gqG
211 call assert_equal(['here: 1->$', '2', 'here: 3->$', '4', 'not here: '], getline(1,'$'))
212 set formatexpr=
213 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200214endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200215
Bram Moolenaard77f9d52016-09-04 15:13:39 +0200216func Test_normal05_formatexpr_newbuf()
217 " Edit another buffer in the 'formatexpr' function
218 new
219 func! Format()
220 edit another
221 endfunc
222 set formatexpr=Format()
223 norm gqG
224 bw!
225 set formatexpr=
226endfunc
227
228func Test_normal05_formatexpr_setopt()
229 " Change the 'formatexpr' value in the function
230 new
231 func! Format()
232 set formatexpr=
233 endfunc
234 set formatexpr=Format()
235 norm gqG
236 bw!
237 set formatexpr=
238endfunc
239
Bram Moolenaar2eaeaf32020-05-03 16:04:43 +0200240" When 'formatexpr' returns non-zero, internal formatting is used.
241func Test_normal_formatexpr_returns_nonzero()
242 new
243 call setline(1, ['one', 'two'])
244 func! Format()
245 return 1
246 endfunc
247 setlocal formatexpr=Format()
248 normal VGgq
249 call assert_equal(['one two'], getline(1, '$'))
250 setlocal formatexpr=
251 delfunc Format
252 close!
253endfunc
254
Bram Moolenaar004a6782020-04-11 17:09:31 +0200255" basic test for formatprg
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100256func Test_normal06_formatprg()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200257 " only test on non windows platform
Bram Moolenaar004a6782020-04-11 17:09:31 +0200258 CheckNotMSWindows
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100259
260 " uses sed to number non-empty lines
261 call writefile(['#!/bin/sh', 'sed ''/./=''|sed ''/./{', 'N', 's/\n/ /', '}'''], 'Xsed_format.sh')
262 call system('chmod +x ./Xsed_format.sh')
263 let text = ['a', '', 'c', '', ' ', 'd', 'e']
264 let expected = ['1 a', '', '3 c', '', '5 ', '6 d', '7 e']
265
266 10new
267 call setline(1, text)
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200268 set formatprg=./Xsed_format.sh
269 norm! gggqG
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100270 call assert_equal(expected, getline(1, '$'))
Bram Moolenaar004a6782020-04-11 17:09:31 +0200271 %d
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100272
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100273 call setline(1, text)
274 set formatprg=donothing
275 setlocal formatprg=./Xsed_format.sh
276 norm! gggqG
277 call assert_equal(expected, getline(1, '$'))
Bram Moolenaar004a6782020-04-11 17:09:31 +0200278 %d
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100279
Bram Moolenaar004a6782020-04-11 17:09:31 +0200280 " Check for the command-line ranges added to 'formatprg'
281 set formatprg=cat
282 call setline(1, ['one', 'two', 'three', 'four', 'five'])
283 call feedkeys('gggqG', 'xt')
284 call assert_equal('.,$!cat', @:)
285 call feedkeys('2Ggq2j', 'xt')
286 call assert_equal('.,.+2!cat', @:)
287
288 bw!
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200289 " clean up
290 set formatprg=
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100291 setlocal formatprg=
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200292 call delete('Xsed_format.sh')
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200293endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200294
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100295func Test_normal07_internalfmt()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200296 " basic test for internal formmatter to textwidth of 12
297 let list=range(1,11)
298 call map(list, 'v:val." "')
299 10new
300 call setline(1, list)
301 set tw=12
Bram Moolenaar004a6782020-04-11 17:09:31 +0200302 norm! ggVGgq
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200303 call assert_equal(['1 2 3', '4 5 6', '7 8 9', '10 11 '], getline(1, '$'))
304 " clean up
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100305 set tw=0
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200306 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200307endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200308
Bram Moolenaar004a6782020-04-11 17:09:31 +0200309" basic tests for foldopen/folddelete
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100310func Test_normal08_fold()
Bram Moolenaar004a6782020-04-11 17:09:31 +0200311 CheckFeature folding
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200312 call Setup_NewWindow()
313 50
314 setl foldenable fdm=marker
315 " First fold
316 norm! V4jzf
317 " check that folds have been created
318 call assert_equal(['50/*{{{*/', '51', '52', '53', '54/*}}}*/'], getline(50,54))
319 " Second fold
320 46
321 norm! V10jzf
322 " check that folds have been created
323 call assert_equal('46/*{{{*/', getline(46))
324 call assert_equal('60/*}}}*/', getline(60))
325 norm! k
326 call assert_equal('45', getline('.'))
327 norm! j
328 call assert_equal('46/*{{{*/', getline('.'))
329 norm! j
330 call assert_equal('61', getline('.'))
331 norm! k
332 " open a fold
333 norm! Vzo
334 norm! k
335 call assert_equal('45', getline('.'))
336 norm! j
337 call assert_equal('46/*{{{*/', getline('.'))
338 norm! j
339 call assert_equal('47', getline('.'))
340 norm! k
341 norm! zcVzO
342 call assert_equal('46/*{{{*/', getline('.'))
343 norm! j
344 call assert_equal('47', getline('.'))
345 norm! j
346 call assert_equal('48', getline('.'))
347 norm! j
348 call assert_equal('49', getline('.'))
349 norm! j
350 call assert_equal('50/*{{{*/', getline('.'))
351 norm! j
352 call assert_equal('51', getline('.'))
353 " delete folds
354 :46
355 " collapse fold
356 norm! V14jzC
357 " delete all folds recursively
358 norm! VzD
359 call assert_equal(['46', '47', '48', '49', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '60'], getline(46,60))
360
361 " clean up
362 setl nofoldenable fdm=marker
363 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200364endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200365
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100366func Test_normal09_operatorfunc()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200367 " Test operatorfunc
368 call Setup_NewWindow()
369 " Add some spaces for counting
370 50,60s/$/ /
371 unlet! g:a
372 let g:a=0
373 nmap <buffer><silent> ,, :set opfunc=CountSpaces<CR>g@
374 vmap <buffer><silent> ,, :<C-U>call CountSpaces(visualmode(), 1)<CR>
375 50
376 norm V2j,,
377 call assert_equal(6, g:a)
378 norm V,,
379 call assert_equal(2, g:a)
380 norm ,,l
381 call assert_equal(0, g:a)
382 50
383 exe "norm 0\<c-v>10j2l,,"
384 call assert_equal(11, g:a)
385 50
386 norm V10j,,
387 call assert_equal(22, g:a)
388
389 " clean up
390 unmap <buffer> ,,
391 set opfunc=
Bram Moolenaar4a08b0d2016-11-05 21:55:13 +0100392 unlet! g:a
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200393 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200394endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200395
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100396func Test_normal09a_operatorfunc()
Bram Moolenaar4a08b0d2016-11-05 21:55:13 +0100397 " Test operatorfunc
398 call Setup_NewWindow()
399 " Add some spaces for counting
400 50,60s/$/ /
401 unlet! g:opt
402 set linebreak
403 nmap <buffer><silent> ,, :set opfunc=OpfuncDummy<CR>g@
404 50
405 norm ,,j
406 exe "bd!" g:bufnr
407 call assert_true(&linebreak)
408 call assert_equal(g:opt, &linebreak)
409 set nolinebreak
410 norm ,,j
411 exe "bd!" g:bufnr
412 call assert_false(&linebreak)
413 call assert_equal(g:opt, &linebreak)
414
415 " clean up
416 unmap <buffer> ,,
417 set opfunc=
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200418 call assert_fails('normal Vg@', 'E774:')
Bram Moolenaar4a08b0d2016-11-05 21:55:13 +0100419 bw!
420 unlet! g:opt
421endfunc
422
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100423func Test_normal10_expand()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200424 " Test for expand()
425 10new
426 call setline(1, ['1', 'ifooar,,cbar'])
427 2
428 norm! $
Bram Moolenaar65f08472017-09-10 18:16:20 +0200429 call assert_equal('cbar', expand('<cword>'))
430 call assert_equal('ifooar,,cbar', expand('<cWORD>'))
431
432 call setline(1, ['prx = list[idx];'])
433 1
434 let expected = ['', 'prx', 'prx', 'prx',
435 \ 'list', 'list', 'list', 'list', 'list', 'list', 'list',
436 \ 'idx', 'idx', 'idx', 'idx',
437 \ 'list[idx]',
438 \ '];',
439 \ ]
440 for i in range(1, 16)
441 exe 'norm ' . i . '|'
442 call assert_equal(expected[i], expand('<cexpr>'), 'i == ' . i)
443 endfor
444
Bram Moolenaard7e5e942020-10-07 16:54:52 +0200445 " Test for <cexpr> in state.val and ptr->val
446 call setline(1, 'x = state.val;')
447 call cursor(1, 10)
448 call assert_equal('state.val', expand('<cexpr>'))
449 call setline(1, 'x = ptr->val;')
450 call cursor(1, 9)
451 call assert_equal('ptr->val', expand('<cexpr>'))
452
Bram Moolenaarae6f8652017-12-20 22:32:20 +0100453 if executable('echo')
454 " Test expand(`...`) i.e. backticks command expansion.
Bram Moolenaar077ff432019-10-28 00:42:21 +0100455 call assert_equal('abcde', expand('`echo abcde`'))
Bram Moolenaarae6f8652017-12-20 22:32:20 +0100456 endif
457
458 " Test expand(`=...`) i.e. backticks expression expansion
459 call assert_equal('5', expand('`=2+3`'))
Bram Moolenaar8b633132020-03-20 18:20:51 +0100460 call assert_equal('3.14', expand('`=3.14`'))
Bram Moolenaarae6f8652017-12-20 22:32:20 +0100461
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200462 " clean up
463 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200464endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200465
Bram Moolenaard7e5e942020-10-07 16:54:52 +0200466" Test for expand() in latin1 encoding
467func Test_normal_expand_latin1()
468 new
469 let save_enc = &encoding
470 set encoding=latin1
471 call setline(1, 'val = item->color;')
472 call cursor(1, 11)
473 call assert_equal('color', expand("<cword>"))
474 call assert_equal('item->color', expand("<cexpr>"))
475 let &encoding = save_enc
476 bw!
477endfunc
478
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100479func Test_normal11_showcmd()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200480 " test for 'showcmd'
481 10new
482 exe "norm! ofoobar\<esc>"
483 call assert_equal(2, line('$'))
484 set showcmd
485 exe "norm! ofoobar2\<esc>"
486 call assert_equal(3, line('$'))
487 exe "norm! VAfoobar3\<esc>"
488 call assert_equal(3, line('$'))
489 exe "norm! 0d3\<del>2l"
490 call assert_equal('obar2foobar3', getline('.'))
Bram Moolenaard1ad99b2020-10-04 16:16:54 +0200491 " test for the visual block size displayed in the status line
492 call setline(1, ['aaaaa', 'bbbbb', 'ccccc'])
493 call feedkeys("ggl\<C-V>lljj", 'xt')
494 redraw!
495 call assert_match('3x3$', Screenline(&lines))
496 call feedkeys("\<C-V>", 'xt')
497 " test for visually selecting a multi-byte character
498 call setline(1, ["\U2206"])
499 call feedkeys("ggv", 'xt')
500 redraw!
501 call assert_match('1-3$', Screenline(&lines))
502 call feedkeys("v", 'xt')
Bram Moolenaard7e5e942020-10-07 16:54:52 +0200503 " test for visually selecting the end of line
504 call setline(1, ["foobar"])
505 call feedkeys("$vl", 'xt')
506 redraw!
507 call assert_match('2$', Screenline(&lines))
508 call feedkeys("y", 'xt')
509 call assert_equal("r\n", @")
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200510 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200511endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200512
Bram Moolenaar1671f442020-03-10 07:48:13 +0100513" Test for nv_error and normal command errors
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100514func Test_normal12_nv_error()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200515 10new
516 call setline(1, range(1,5))
517 " should not do anything, just beep
Bram Moolenaarf5f1e102020-03-08 05:13:15 +0100518 call assert_beeps('exe "norm! <c-k>"')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200519 call assert_equal(map(range(1,5), 'string(v:val)'), getline(1,'$'))
Bram Moolenaarf5f1e102020-03-08 05:13:15 +0100520 call assert_beeps('normal! G2dd')
521 call assert_beeps("normal! g\<C-A>")
522 call assert_beeps("normal! g\<C-X>")
523 call assert_beeps("normal! g\<C-B>")
Bram Moolenaar1671f442020-03-10 07:48:13 +0100524 call assert_beeps("normal! vQ\<Esc>")
525 call assert_beeps("normal! 2[[")
526 call assert_beeps("normal! 2]]")
527 call assert_beeps("normal! 2[]")
528 call assert_beeps("normal! 2][")
529 call assert_beeps("normal! 4[z")
530 call assert_beeps("normal! 4]z")
531 call assert_beeps("normal! 4[c")
532 call assert_beeps("normal! 4]c")
533 call assert_beeps("normal! 200%")
534 call assert_beeps("normal! %")
535 call assert_beeps("normal! 2{")
536 call assert_beeps("normal! 2}")
537 call assert_beeps("normal! r\<Right>")
538 call assert_beeps("normal! 8ry")
539 call assert_beeps('normal! "@')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200540 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200541endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200542
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100543func Test_normal13_help()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200544 " Test for F1
545 call assert_equal(1, winnr())
546 call feedkeys("\<f1>", 'txi')
547 call assert_match('help\.txt', bufname('%'))
548 call assert_equal(2, winnr('$'))
549 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200550endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200551
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100552func Test_normal14_page()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200553 " basic test for Ctrl-F and Ctrl-B
554 call Setup_NewWindow()
555 exe "norm! \<c-f>"
556 call assert_equal('9', getline('.'))
557 exe "norm! 2\<c-f>"
558 call assert_equal('25', getline('.'))
559 exe "norm! 2\<c-b>"
560 call assert_equal('18', getline('.'))
561 1
562 set scrolloff=5
563 exe "norm! 2\<c-f>"
564 call assert_equal('21', getline('.'))
565 exe "norm! \<c-b>"
566 call assert_equal('13', getline('.'))
567 1
568 set scrolloff=99
569 exe "norm! \<c-f>"
570 call assert_equal('13', getline('.'))
571 set scrolloff=0
572 100
573 exe "norm! $\<c-b>"
574 call assert_equal('92', getline('.'))
575 call assert_equal([0, 92, 1, 0, 1], getcurpos())
576 100
577 set nostartofline
578 exe "norm! $\<c-b>"
579 call assert_equal('92', getline('.'))
580 call assert_equal([0, 92, 2, 0, 2147483647], getcurpos())
581 " cleanup
582 set startofline
583 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200584endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200585
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100586func Test_normal14_page_eol()
Bram Moolenaarbc54f3f2016-09-04 14:34:28 +0200587 10new
588 norm oxxxxxxx
589 exe "norm 2\<c-f>"
590 " check with valgrind that cursor is put back in column 1
591 exe "norm 2\<c-b>"
592 bw!
593endfunc
594
Bram Moolenaar1671f442020-03-10 07:48:13 +0100595" Test for errors with z command
596func Test_normal_z_error()
597 call assert_beeps('normal! z2p')
598 call assert_beeps('normal! zp')
599endfunc
600
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100601func Test_normal15_z_scroll_vert()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200602 " basic test for z commands that scroll the window
603 call Setup_NewWindow()
604 100
605 norm! >>
606 " Test for z<cr>
607 exe "norm! z\<cr>"
608 call assert_equal(' 100', getline('.'))
609 call assert_equal(100, winsaveview()['topline'])
610 call assert_equal([0, 100, 2, 0, 9], getcurpos())
611
612 " Test for zt
613 21
614 norm! >>0zt
615 call assert_equal(' 21', getline('.'))
616 call assert_equal(21, winsaveview()['topline'])
617 call assert_equal([0, 21, 1, 0, 8], getcurpos())
618
619 " Test for zb
620 30
621 norm! >>$ztzb
622 call assert_equal(' 30', getline('.'))
623 call assert_equal(30, winsaveview()['topline']+winheight(0)-1)
624 call assert_equal([0, 30, 3, 0, 2147483647], getcurpos())
625
626 " Test for z-
627 1
628 30
629 norm! 0z-
630 call assert_equal(' 30', getline('.'))
631 call assert_equal(30, winsaveview()['topline']+winheight(0)-1)
632 call assert_equal([0, 30, 2, 0, 9], getcurpos())
633
634 " Test for z{height}<cr>
635 call assert_equal(10, winheight(0))
636 exe "norm! z12\<cr>"
637 call assert_equal(12, winheight(0))
638 exe "norm! z10\<cr>"
639 call assert_equal(10, winheight(0))
640
641 " Test for z.
642 1
643 21
644 norm! 0z.
645 call assert_equal(' 21', getline('.'))
646 call assert_equal(17, winsaveview()['topline'])
647 call assert_equal([0, 21, 2, 0, 9], getcurpos())
648
649 " Test for zz
650 1
651 21
652 norm! 0zz
653 call assert_equal(' 21', getline('.'))
654 call assert_equal(17, winsaveview()['topline'])
655 call assert_equal([0, 21, 1, 0, 8], getcurpos())
656
657 " Test for z+
658 11
659 norm! zt
660 norm! z+
661 call assert_equal(' 21', getline('.'))
662 call assert_equal(21, winsaveview()['topline'])
663 call assert_equal([0, 21, 2, 0, 9], getcurpos())
664
665 " Test for [count]z+
666 1
667 norm! 21z+
668 call assert_equal(' 21', getline('.'))
669 call assert_equal(21, winsaveview()['topline'])
670 call assert_equal([0, 21, 2, 0, 9], getcurpos())
671
Bram Moolenaar8a9bc952020-10-02 18:48:07 +0200672 " Test for z+ with [count] greater than buffer size
673 1
674 norm! 1000z+
675 call assert_equal(' 100', getline('.'))
676 call assert_equal(100, winsaveview()['topline'])
677 call assert_equal([0, 100, 2, 0, 9], getcurpos())
678
679 " Test for z+ from the last buffer line
680 norm! Gz.z+
681 call assert_equal(' 100', getline('.'))
682 call assert_equal(100, winsaveview()['topline'])
683 call assert_equal([0, 100, 2, 0, 9], getcurpos())
684
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200685 " Test for z^
686 norm! 22z+0
687 norm! z^
688 call assert_equal(' 21', getline('.'))
689 call assert_equal(12, winsaveview()['topline'])
690 call assert_equal([0, 21, 2, 0, 9], getcurpos())
691
Bram Moolenaar8a9bc952020-10-02 18:48:07 +0200692 " Test for z^ from first buffer line
693 norm! ggz^
694 call assert_equal('1', getline('.'))
695 call assert_equal(1, winsaveview()['topline'])
696 call assert_equal([0, 1, 1, 0, 1], getcurpos())
697
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200698 " Test for [count]z^
699 1
700 norm! 30z^
701 call assert_equal(' 21', getline('.'))
702 call assert_equal(12, winsaveview()['topline'])
703 call assert_equal([0, 21, 2, 0, 9], getcurpos())
704
705 " cleanup
706 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200707endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200708
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100709func Test_normal16_z_scroll_hor()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200710 " basic test for z commands that scroll the window
711 10new
712 15vsp
713 set nowrap listchars=
714 let lineA='abcdefghijklmnopqrstuvwxyz'
715 let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
716 $put =lineA
717 $put =lineB
718 1d
719
Bram Moolenaar1671f442020-03-10 07:48:13 +0100720 " Test for zl and zh with a count
721 norm! 0z10l
722 call assert_equal([11, 1], [col('.'), wincol()])
723 norm! z4h
724 call assert_equal([11, 5], [col('.'), wincol()])
725 normal! 2gg
726
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200727 " Test for zl
728 1
729 norm! 5zl
730 call assert_equal(lineA, getline('.'))
731 call assert_equal(6, col('.'))
732 call assert_equal(5, winsaveview()['leftcol'])
733 norm! yl
734 call assert_equal('f', @0)
735
736 " Test for zh
737 norm! 2zh
738 call assert_equal(lineA, getline('.'))
739 call assert_equal(6, col('.'))
740 norm! yl
741 call assert_equal('f', @0)
742 call assert_equal(3, winsaveview()['leftcol'])
743
744 " Test for zL
745 norm! zL
746 call assert_equal(11, col('.'))
747 norm! yl
748 call assert_equal('k', @0)
749 call assert_equal(10, winsaveview()['leftcol'])
750 norm! 2zL
751 call assert_equal(25, col('.'))
752 norm! yl
753 call assert_equal('y', @0)
754 call assert_equal(24, winsaveview()['leftcol'])
755
756 " Test for zH
757 norm! 2zH
758 call assert_equal(25, col('.'))
759 call assert_equal(10, winsaveview()['leftcol'])
760 norm! yl
761 call assert_equal('y', @0)
762
763 " Test for zs
764 norm! $zs
765 call assert_equal(26, col('.'))
766 call assert_equal(25, winsaveview()['leftcol'])
767 norm! yl
768 call assert_equal('z', @0)
769
770 " Test for ze
771 norm! ze
772 call assert_equal(26, col('.'))
773 call assert_equal(11, winsaveview()['leftcol'])
774 norm! yl
775 call assert_equal('z', @0)
776
Bram Moolenaar8a9bc952020-10-02 18:48:07 +0200777 " Test for zs and ze with folds
778 %fold
779 norm! $zs
780 call assert_equal(26, col('.'))
781 call assert_equal(0, winsaveview()['leftcol'])
782 norm! yl
783 call assert_equal('z', @0)
784 norm! ze
785 call assert_equal(26, col('.'))
786 call assert_equal(0, winsaveview()['leftcol'])
787 norm! yl
788 call assert_equal('z', @0)
789
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200790 " cleanup
791 set wrap listchars=eol:$
792 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200793endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200794
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100795func Test_normal17_z_scroll_hor2()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200796 " basic test for z commands that scroll the window
797 " using 'sidescrolloff' setting
798 10new
799 20vsp
800 set nowrap listchars= sidescrolloff=5
801 let lineA='abcdefghijklmnopqrstuvwxyz'
802 let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
803 $put =lineA
804 $put =lineB
805 1d
806
807 " Test for zl
808 1
809 norm! 5zl
810 call assert_equal(lineA, getline('.'))
811 call assert_equal(11, col('.'))
812 call assert_equal(5, winsaveview()['leftcol'])
813 norm! yl
814 call assert_equal('k', @0)
815
816 " Test for zh
817 norm! 2zh
818 call assert_equal(lineA, getline('.'))
819 call assert_equal(11, col('.'))
820 norm! yl
821 call assert_equal('k', @0)
822 call assert_equal(3, winsaveview()['leftcol'])
823
824 " Test for zL
825 norm! 0zL
826 call assert_equal(16, col('.'))
827 norm! yl
828 call assert_equal('p', @0)
829 call assert_equal(10, winsaveview()['leftcol'])
830 norm! 2zL
831 call assert_equal(26, col('.'))
832 norm! yl
833 call assert_equal('z', @0)
834 call assert_equal(15, winsaveview()['leftcol'])
835
836 " Test for zH
837 norm! 2zH
838 call assert_equal(15, col('.'))
839 call assert_equal(0, winsaveview()['leftcol'])
840 norm! yl
841 call assert_equal('o', @0)
842
843 " Test for zs
844 norm! $zs
845 call assert_equal(26, col('.'))
846 call assert_equal(20, winsaveview()['leftcol'])
847 norm! yl
848 call assert_equal('z', @0)
849
850 " Test for ze
851 norm! ze
852 call assert_equal(26, col('.'))
853 call assert_equal(11, winsaveview()['leftcol'])
854 norm! yl
855 call assert_equal('z', @0)
856
857 " cleanup
858 set wrap listchars=eol:$ sidescrolloff=0
859 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200860endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200861
Bram Moolenaarbdd2c292020-06-22 21:34:30 +0200862" Test for commands that scroll the window horizontally. Test with folds.
863" H, M, L, CTRL-E, CTRL-Y, CTRL-U, CTRL-D, PageUp, PageDown commands
864func Test_vert_scroll_cmds()
Bram Moolenaar1671f442020-03-10 07:48:13 +0100865 15new
866 call setline(1, range(1, 100))
867 exe "normal! 30ggz\<CR>"
868 set foldenable
869 33,36fold
870 40,43fold
871 46,49fold
872 let h = winheight(0)
Bram Moolenaarbdd2c292020-06-22 21:34:30 +0200873
874 " Test for H, M and L commands
Bram Moolenaar1671f442020-03-10 07:48:13 +0100875 " Top of the screen = 30
876 " Folded lines = 9
877 " Bottom of the screen = 30 + h + 9 - 1
878 normal! 4L
879 call assert_equal(35 + h, line('.'))
880 normal! 4H
881 call assert_equal(33, line('.'))
Bram Moolenaarbdd2c292020-06-22 21:34:30 +0200882
Bram Moolenaar8a9bc952020-10-02 18:48:07 +0200883 " Test for using a large count value
884 %d
885 call setline(1, range(1, 4))
886 norm! 6H
887 call assert_equal(4, line('.'))
888
889 " Test for 'M' with folded lines
890 %d
891 call setline(1, range(1, 20))
892 1,5fold
893 norm! LM
894 call assert_equal(12, line('.'))
895
Bram Moolenaarbdd2c292020-06-22 21:34:30 +0200896 " Test for the CTRL-E and CTRL-Y commands with folds
897 %d
898 call setline(1, range(1, 10))
899 3,5fold
900 exe "normal 6G3\<C-E>"
901 call assert_equal(6, line('w0'))
902 exe "normal 2\<C-Y>"
903 call assert_equal(2, line('w0'))
904
905 " Test for CTRL-Y on a folded line
906 %d
907 call setline(1, range(1, 100))
908 exe (h + 2) .. "," .. (h + 4) .. "fold"
909 exe h + 5
910 normal z-
911 exe "normal \<C-Y>\<C-Y>"
912 call assert_equal(h + 1, line('w$'))
913
Bram Moolenaard1ad99b2020-10-04 16:16:54 +0200914 " Test for CTRL-Y from the first line and CTRL-E from the last line
915 %d
916 set scrolloff=2
917 call setline(1, range(1, 4))
918 exe "normal gg\<C-Y>"
919 call assert_equal(1, line('w0'))
920 call assert_equal(1, line('.'))
921 exe "normal G4\<C-E>\<C-E>"
922 call assert_equal(4, line('w$'))
923 call assert_equal(4, line('.'))
924 set scrolloff&
925
Bram Moolenaarbdd2c292020-06-22 21:34:30 +0200926 " Using <PageUp> and <PageDown> in an empty buffer should beep
927 %d
928 call assert_beeps('exe "normal \<PageUp>"')
929 call assert_beeps('exe "normal \<C-B>"')
930 call assert_beeps('exe "normal \<PageDown>"')
931 call assert_beeps('exe "normal \<C-F>"')
932
933 " Test for <C-U> and <C-D> with fold
934 %d
935 call setline(1, range(1, 100))
936 10,35fold
937 set scroll=10
938 exe "normal \<C-D>"
939 call assert_equal(36, line('.'))
940 exe "normal \<C-D>"
941 call assert_equal(46, line('.'))
942 exe "normal \<C-U>"
943 call assert_equal(36, line('.'))
944 exe "normal \<C-U>"
945 call assert_equal(10, line('.'))
946 exe "normal \<C-U>"
947 call assert_equal(1, line('.'))
948 set scroll&
949
950 " Test for scrolling to the top of the file with <C-U> and a fold
951 10
952 normal ztL
953 exe "normal \<C-U>\<C-U>"
954 call assert_equal(1, line('w0'))
955
956 " Test for CTRL-D on a folded line
957 %d
958 call setline(1, range(1, 100))
959 50,100fold
960 75
961 normal z-
962 exe "normal \<C-D>"
963 call assert_equal(50, line('.'))
964 call assert_equal(100, line('w$'))
965 normal z.
966 let lnum = winline()
967 exe "normal \<C-D>"
968 call assert_equal(lnum, winline())
969 call assert_equal(50, line('.'))
970 normal zt
971 exe "normal \<C-D>"
972 call assert_equal(50, line('w0'))
973
Bram Moolenaard1ad99b2020-10-04 16:16:54 +0200974 " Test for <S-CR>. Page down.
975 %d
976 call setline(1, range(1, 100))
977 call feedkeys("\<S-CR>", 'xt')
978 call assert_equal(14, line('w0'))
979 call assert_equal(28, line('w$'))
980
981 " Test for <S-->. Page up.
982 call feedkeys("\<S-->", 'xt')
983 call assert_equal(1, line('w0'))
984 call assert_equal(15, line('w$'))
985
Bram Moolenaar1671f442020-03-10 07:48:13 +0100986 set foldenable&
987 close!
988endfunc
989
Bram Moolenaarbdd2c292020-06-22 21:34:30 +0200990" Test for the 'sidescroll' option
991func Test_sidescroll_opt()
992 new
993 20vnew
994
995 " scroll by 2 characters horizontally
996 set sidescroll=2 nowrap
997 call setline(1, repeat('a', 40))
998 normal g$l
999 call assert_equal(19, screenpos(0, 1, 21).col)
1000 normal l
1001 call assert_equal(20, screenpos(0, 1, 22).col)
1002 normal g0h
1003 call assert_equal(2, screenpos(0, 1, 2).col)
1004 call assert_equal(20, screenpos(0, 1, 20).col)
1005
1006 " when 'sidescroll' is 0, cursor positioned at the center
1007 set sidescroll=0
1008 normal g$l
1009 call assert_equal(11, screenpos(0, 1, 21).col)
1010 normal g0h
1011 call assert_equal(10, screenpos(0, 1, 10).col)
1012
1013 %bw!
1014 set wrap& sidescroll&
1015endfunc
1016
Bram Moolenaar004a6782020-04-11 17:09:31 +02001017" basic tests for foldopen/folddelete
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001018func Test_normal18_z_fold()
Bram Moolenaar004a6782020-04-11 17:09:31 +02001019 CheckFeature folding
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001020 call Setup_NewWindow()
1021 50
1022 setl foldenable fdm=marker foldlevel=5
1023
Bram Moolenaar1671f442020-03-10 07:48:13 +01001024 call assert_beeps('normal! zj')
1025 call assert_beeps('normal! zk')
1026
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001027 " Test for zF
1028 " First fold
1029 norm! 4zF
1030 " check that folds have been created
1031 call assert_equal(['50/*{{{*/', '51', '52', '53/*}}}*/'], getline(50,53))
1032
1033 " Test for zd
1034 51
1035 norm! 2zF
1036 call assert_equal(2, foldlevel('.'))
1037 norm! kzd
1038 call assert_equal(['50', '51/*{{{*/', '52/*}}}*/', '53'], getline(50,53))
1039 norm! j
1040 call assert_equal(1, foldlevel('.'))
1041
1042 " Test for zD
1043 " also deletes partially selected folds recursively
1044 51
1045 norm! zF
1046 call assert_equal(2, foldlevel('.'))
1047 norm! kV2jzD
1048 call assert_equal(['50', '51', '52', '53'], getline(50,53))
1049
1050 " Test for zE
1051 85
1052 norm! 4zF
1053 86
1054 norm! 2zF
1055 90
1056 norm! 4zF
1057 call assert_equal(['85/*{{{*/', '86/*{{{*/', '87/*}}}*/', '88/*}}}*/', '89', '90/*{{{*/', '91', '92', '93/*}}}*/'], getline(85,93))
1058 norm! zE
1059 call assert_equal(['85', '86', '87', '88', '89', '90', '91', '92', '93'], getline(85,93))
1060
1061 " Test for zn
1062 50
1063 set foldlevel=0
1064 norm! 2zF
1065 norm! zn
1066 norm! k
1067 call assert_equal('49', getline('.'))
1068 norm! j
1069 call assert_equal('50/*{{{*/', getline('.'))
1070 norm! j
1071 call assert_equal('51/*}}}*/', getline('.'))
1072 norm! j
1073 call assert_equal('52', getline('.'))
1074 call assert_equal(0, &foldenable)
1075
1076 " Test for zN
1077 49
1078 norm! zN
1079 call assert_equal('49', getline('.'))
1080 norm! j
1081 call assert_equal('50/*{{{*/', getline('.'))
1082 norm! j
1083 call assert_equal('52', getline('.'))
1084 call assert_equal(1, &foldenable)
1085
1086 " Test for zi
1087 norm! zi
1088 call assert_equal(0, &foldenable)
1089 norm! zi
1090 call assert_equal(1, &foldenable)
1091 norm! zi
1092 call assert_equal(0, &foldenable)
1093 norm! zi
1094 call assert_equal(1, &foldenable)
1095
1096 " Test for za
1097 50
1098 norm! za
1099 norm! k
1100 call assert_equal('49', getline('.'))
1101 norm! j
1102 call assert_equal('50/*{{{*/', getline('.'))
1103 norm! j
1104 call assert_equal('51/*}}}*/', getline('.'))
1105 norm! j
1106 call assert_equal('52', getline('.'))
1107 50
1108 norm! za
1109 norm! k
1110 call assert_equal('49', getline('.'))
1111 norm! j
1112 call assert_equal('50/*{{{*/', getline('.'))
1113 norm! j
1114 call assert_equal('52', getline('.'))
1115
1116 49
1117 norm! 5zF
1118 norm! k
1119 call assert_equal('48', getline('.'))
1120 norm! j
1121 call assert_equal('49/*{{{*/', getline('.'))
1122 norm! j
1123 call assert_equal('55', getline('.'))
1124 49
1125 norm! za
1126 call assert_equal('49/*{{{*/', getline('.'))
1127 norm! j
1128 call assert_equal('50/*{{{*/', getline('.'))
1129 norm! j
1130 call assert_equal('52', getline('.'))
1131 set nofoldenable
1132 " close fold and set foldenable
1133 norm! za
1134 call assert_equal(1, &foldenable)
1135
1136 50
1137 " have to use {count}za to open all folds and make the cursor visible
1138 norm! 2za
1139 norm! 2k
1140 call assert_equal('48', getline('.'))
1141 norm! j
1142 call assert_equal('49/*{{{*/', getline('.'))
1143 norm! j
1144 call assert_equal('50/*{{{*/', getline('.'))
1145 norm! j
1146 call assert_equal('51/*}}}*/', getline('.'))
1147 norm! j
1148 call assert_equal('52', getline('.'))
1149
1150 " Test for zA
1151 49
1152 set foldlevel=0
1153 50
1154 norm! zA
1155 norm! 2k
1156 call assert_equal('48', getline('.'))
1157 norm! j
1158 call assert_equal('49/*{{{*/', getline('.'))
1159 norm! j
1160 call assert_equal('50/*{{{*/', getline('.'))
1161 norm! j
1162 call assert_equal('51/*}}}*/', getline('.'))
1163 norm! j
1164 call assert_equal('52', getline('.'))
1165
Bram Moolenaar395b6ba2017-04-07 20:09:51 +02001166 " zA on a opened fold when foldenable is not set
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001167 50
1168 set nofoldenable
1169 norm! zA
1170 call assert_equal(1, &foldenable)
1171 norm! k
1172 call assert_equal('48', getline('.'))
1173 norm! j
1174 call assert_equal('49/*{{{*/', getline('.'))
1175 norm! j
1176 call assert_equal('55', getline('.'))
1177
1178 " Test for zc
1179 norm! zE
1180 50
1181 norm! 2zF
1182 49
1183 norm! 5zF
1184 set nofoldenable
1185 50
1186 " There most likely is a bug somewhere:
1187 " https://groups.google.com/d/msg/vim_dev/v2EkfJ_KQjI/u-Cvv94uCAAJ
1188 " TODO: Should this only close the inner most fold or both folds?
1189 norm! zc
1190 call assert_equal(1, &foldenable)
1191 norm! k
1192 call assert_equal('48', getline('.'))
1193 norm! j
1194 call assert_equal('49/*{{{*/', getline('.'))
1195 norm! j
1196 call assert_equal('55', getline('.'))
1197 set nofoldenable
1198 50
1199 norm! Vjzc
1200 norm! k
1201 call assert_equal('48', getline('.'))
1202 norm! j
1203 call assert_equal('49/*{{{*/', getline('.'))
1204 norm! j
1205 call assert_equal('55', getline('.'))
1206
1207 " Test for zC
1208 set nofoldenable
1209 50
1210 norm! zCk
1211 call assert_equal('48', getline('.'))
1212 norm! j
1213 call assert_equal('49/*{{{*/', getline('.'))
1214 norm! j
1215 call assert_equal('55', getline('.'))
1216
1217 " Test for zx
1218 " 1) close folds at line 49-54
1219 set nofoldenable
1220 48
1221 norm! zx
1222 call assert_equal(1, &foldenable)
1223 norm! j
1224 call assert_equal('49/*{{{*/', getline('.'))
1225 norm! j
1226 call assert_equal('55', getline('.'))
1227
Bram Moolenaar395b6ba2017-04-07 20:09:51 +02001228 " 2) do not close fold under cursor
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001229 51
1230 set nofoldenable
1231 norm! zx
1232 call assert_equal(1, &foldenable)
1233 norm! 3k
1234 call assert_equal('48', getline('.'))
1235 norm! j
1236 call assert_equal('49/*{{{*/', getline('.'))
1237 norm! j
1238 call assert_equal('50/*{{{*/', getline('.'))
1239 norm! j
1240 call assert_equal('51/*}}}*/', getline('.'))
1241 norm! j
1242 call assert_equal('52', getline('.'))
1243 norm! j
1244 call assert_equal('53', getline('.'))
1245 norm! j
1246 call assert_equal('54/*}}}*/', getline('.'))
1247 norm! j
1248 call assert_equal('55', getline('.'))
1249
1250 " 3) close one level of folds
1251 48
1252 set nofoldenable
1253 set foldlevel=1
1254 norm! zx
1255 call assert_equal(1, &foldenable)
1256 call assert_equal('48', getline('.'))
1257 norm! j
1258 call assert_equal('49/*{{{*/', getline('.'))
1259 norm! j
1260 call assert_equal('50/*{{{*/', getline('.'))
1261 norm! j
1262 call assert_equal('52', getline('.'))
1263 norm! j
1264 call assert_equal('53', getline('.'))
1265 norm! j
1266 call assert_equal('54/*}}}*/', getline('.'))
1267 norm! j
1268 call assert_equal('55', getline('.'))
1269
1270 " Test for zX
1271 " Close all folds
1272 set foldlevel=0 nofoldenable
1273 50
1274 norm! zX
1275 call assert_equal(1, &foldenable)
1276 norm! k
1277 call assert_equal('48', getline('.'))
1278 norm! j
1279 call assert_equal('49/*{{{*/', getline('.'))
1280 norm! j
1281 call assert_equal('55', getline('.'))
1282
1283 " Test for zm
1284 50
1285 set nofoldenable foldlevel=2
1286 norm! zm
1287 call assert_equal(1, &foldenable)
1288 call assert_equal(1, &foldlevel)
1289 norm! zm
1290 call assert_equal(0, &foldlevel)
1291 norm! zm
1292 call assert_equal(0, &foldlevel)
1293 norm! k
1294 call assert_equal('48', getline('.'))
1295 norm! j
1296 call assert_equal('49/*{{{*/', getline('.'))
1297 norm! j
1298 call assert_equal('55', getline('.'))
1299
Bram Moolenaar8a9bc952020-10-02 18:48:07 +02001300 " Test for zm with a count
1301 50
1302 set foldlevel=2
1303 norm! 3zm
1304 call assert_equal(0, &foldlevel)
1305 call assert_equal(49, foldclosed(line('.')))
1306
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001307 " Test for zM
1308 48
1309 set nofoldenable foldlevel=99
1310 norm! zM
1311 call assert_equal(1, &foldenable)
1312 call assert_equal(0, &foldlevel)
1313 call assert_equal('48', getline('.'))
1314 norm! j
1315 call assert_equal('49/*{{{*/', getline('.'))
1316 norm! j
1317 call assert_equal('55', getline('.'))
1318
1319 " Test for zr
1320 48
1321 set nofoldenable foldlevel=0
1322 norm! zr
1323 call assert_equal(0, &foldenable)
1324 call assert_equal(1, &foldlevel)
1325 set foldlevel=0 foldenable
1326 norm! zr
1327 call assert_equal(1, &foldenable)
1328 call assert_equal(1, &foldlevel)
1329 norm! zr
1330 call assert_equal(2, &foldlevel)
1331 call assert_equal('48', getline('.'))
1332 norm! j
1333 call assert_equal('49/*{{{*/', getline('.'))
1334 norm! j
1335 call assert_equal('50/*{{{*/', getline('.'))
1336 norm! j
1337 call assert_equal('51/*}}}*/', getline('.'))
1338 norm! j
1339 call assert_equal('52', getline('.'))
1340
1341 " Test for zR
1342 48
1343 set nofoldenable foldlevel=0
1344 norm! zR
1345 call assert_equal(0, &foldenable)
1346 call assert_equal(2, &foldlevel)
1347 set foldenable foldlevel=0
1348 norm! zR
1349 call assert_equal(1, &foldenable)
1350 call assert_equal(2, &foldlevel)
1351 call assert_equal('48', getline('.'))
1352 norm! j
1353 call assert_equal('49/*{{{*/', getline('.'))
1354 norm! j
1355 call assert_equal('50/*{{{*/', getline('.'))
1356 norm! j
1357 call assert_equal('51/*}}}*/', getline('.'))
1358 norm! j
1359 call assert_equal('52', getline('.'))
1360 call append(50, ['a /*{{{*/', 'b /*}}}*/'])
1361 48
1362 call assert_equal('48', getline('.'))
1363 norm! j
1364 call assert_equal('49/*{{{*/', getline('.'))
1365 norm! j
1366 call assert_equal('50/*{{{*/', getline('.'))
1367 norm! j
1368 call assert_equal('a /*{{{*/', getline('.'))
1369 norm! j
1370 call assert_equal('51/*}}}*/', getline('.'))
1371 norm! j
1372 call assert_equal('52', getline('.'))
1373 48
1374 norm! zR
1375 call assert_equal(1, &foldenable)
1376 call assert_equal(3, &foldlevel)
1377 call assert_equal('48', getline('.'))
1378 norm! j
1379 call assert_equal('49/*{{{*/', getline('.'))
1380 norm! j
1381 call assert_equal('50/*{{{*/', getline('.'))
1382 norm! j
1383 call assert_equal('a /*{{{*/', getline('.'))
1384 norm! j
1385 call assert_equal('b /*}}}*/', getline('.'))
1386 norm! j
1387 call assert_equal('51/*}}}*/', getline('.'))
1388 norm! j
1389 call assert_equal('52', getline('.'))
1390
1391 " clean up
1392 setl nofoldenable fdm=marker foldlevel=0
1393 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001394endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001395
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001396func Test_normal20_exmode()
Bram Moolenaar004a6782020-04-11 17:09:31 +02001397 " Reading from redirected file doesn't work on MS-Windows
1398 CheckNotMSWindows
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001399 call writefile(['1a', 'foo', 'bar', '.', 'w! Xfile2', 'q!'], 'Xscript')
1400 call writefile(['1', '2'], 'Xfile')
Bram Moolenaar93344c22019-08-14 21:12:05 +02001401 call system(GetVimCommand() .. ' -e -s < Xscript Xfile')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001402 let a=readfile('Xfile2')
1403 call assert_equal(['1', 'foo', 'bar', '2'], a)
1404
1405 " clean up
1406 for file in ['Xfile', 'Xfile2', 'Xscript']
1407 call delete(file)
1408 endfor
1409 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001410endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001411
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001412func Test_normal21_nv_hat()
1413
1414 " Edit a fresh file and wipe the buffer list so that there is no alternate
1415 " file present. Next, check for the expected command failures.
1416 edit Xfoo | %bw
Bram Moolenaare2e40752020-09-04 21:18:46 +02001417 call assert_fails(':buffer #', 'E86:')
1418 call assert_fails(':execute "normal! \<C-^>"', 'E23:')
Bram Moolenaarb7e24832020-06-24 13:37:35 +02001419 call assert_fails("normal i\<C-R>#", 'E23:')
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001420
1421 " Test for the expected behavior when switching between two named buffers.
1422 edit Xfoo | edit Xbar
1423 call feedkeys("\<C-^>", 'tx')
1424 call assert_equal('Xfoo', fnamemodify(bufname('%'), ':t'))
1425 call feedkeys("\<C-^>", 'tx')
1426 call assert_equal('Xbar', fnamemodify(bufname('%'), ':t'))
1427
1428 " Test for the expected behavior when only one buffer is named.
1429 enew | let l:nr = bufnr('%')
1430 call feedkeys("\<C-^>", 'tx')
1431 call assert_equal('Xbar', fnamemodify(bufname('%'), ':t'))
1432 call feedkeys("\<C-^>", 'tx')
1433 call assert_equal('', bufname('%'))
1434 call assert_equal(l:nr, bufnr('%'))
1435
1436 " Test that no action is taken by "<C-^>" when an operator is pending.
1437 edit Xfoo
1438 call feedkeys("ci\<C-^>", 'tx')
1439 call assert_equal('Xfoo', fnamemodify(bufname('%'), ':t'))
1440
1441 %bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001442endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001443
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001444func Test_normal22_zet()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001445 " Test for ZZ
Bram Moolenaar0913a102016-09-03 19:11:59 +02001446 " let shell = &shell
1447 " let &shell = 'sh'
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001448 call writefile(['1', '2'], 'Xfile')
Bram Moolenaar93344c22019-08-14 21:12:05 +02001449 let args = ' -N -i NONE --noplugins -X --not-a-term'
1450 call system(GetVimCommand() .. args .. ' -c "%d" -c ":norm! ZZ" Xfile')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001451 let a = readfile('Xfile')
1452 call assert_equal([], a)
1453 " Test for ZQ
1454 call writefile(['1', '2'], 'Xfile')
Bram Moolenaar93344c22019-08-14 21:12:05 +02001455 call system(GetVimCommand() . args . ' -c "%d" -c ":norm! ZQ" Xfile')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001456 let a = readfile('Xfile')
1457 call assert_equal(['1', '2'], a)
1458
Bram Moolenaar1671f442020-03-10 07:48:13 +01001459 " Unsupported Z command
1460 call assert_beeps('normal! ZW')
1461
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001462 " clean up
1463 for file in ['Xfile']
1464 call delete(file)
1465 endfor
Bram Moolenaar0913a102016-09-03 19:11:59 +02001466 " let &shell = shell
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001467endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001468
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001469func Test_normal23_K()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001470 " Test for K command
1471 new
Bram Moolenaar426f3752016-11-04 21:22:37 +01001472 call append(0, ['version8.txt', 'man', 'aa%bb', 'cc|dd'])
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001473 let k = &keywordprg
1474 set keywordprg=:help
1475 1
1476 norm! VK
1477 call assert_equal('version8.txt', fnamemodify(bufname('%'), ':t'))
1478 call assert_equal('help', &ft)
1479 call assert_match('\*version8.txt\*', getline('.'))
1480 helpclose
1481 norm! 0K
1482 call assert_equal('version8.txt', fnamemodify(bufname('%'), ':t'))
1483 call assert_equal('help', &ft)
Bram Moolenaarb1c91982018-05-17 17:04:55 +02001484 call assert_match('\*version8\.\d\*', getline('.'))
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001485 helpclose
1486
Bram Moolenaar426f3752016-11-04 21:22:37 +01001487 set keywordprg=:new
1488 set iskeyword+=%
1489 set iskeyword+=\|
1490 2
1491 norm! K
1492 call assert_equal('man', fnamemodify(bufname('%'), ':t'))
1493 bwipe!
1494 3
1495 norm! K
1496 call assert_equal('aa%bb', fnamemodify(bufname('%'), ':t'))
1497 bwipe!
Bram Moolenaareb828d02016-11-05 19:54:01 +01001498 if !has('win32')
1499 4
1500 norm! K
1501 call assert_equal('cc|dd', fnamemodify(bufname('%'), ':t'))
1502 bwipe!
1503 endif
Bram Moolenaar426f3752016-11-04 21:22:37 +01001504 set iskeyword-=%
1505 set iskeyword-=\|
1506
Bram Moolenaar8a9bc952020-10-02 18:48:07 +02001507 " Test for specifying a count to K
1508 1
1509 com! -nargs=* Kprog let g:Kprog_Args = <q-args>
1510 set keywordprg=:Kprog
1511 norm! 3K
1512 call assert_equal('3 version8', g:Kprog_Args)
1513 delcom Kprog
1514
Bram Moolenaar0913a102016-09-03 19:11:59 +02001515 " Only expect "man" to work on Unix
1516 if !has("unix")
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001517 let &keywordprg = k
1518 bw!
1519 return
1520 endif
Bram Moolenaarc6b37db2019-04-27 18:00:34 +02001521
Bram Moolenaar9134f1e2019-11-29 20:26:13 +01001522 let not_gnu_man = has('mac') || has('bsd')
1523 if not_gnu_man
Bram Moolenaarc7d2a572019-11-28 21:16:06 +01001524 " In MacOS and BSD, the option for specifying a pager is different
Bram Moolenaarc6b37db2019-04-27 18:00:34 +02001525 set keywordprg=man\ -P\ cat
1526 else
1527 set keywordprg=man\ --pager=cat
1528 endif
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001529 " Test for using man
1530 2
1531 let a = execute('unsilent norm! K')
Bram Moolenaar9134f1e2019-11-29 20:26:13 +01001532 if not_gnu_man
Bram Moolenaarc6b37db2019-04-27 18:00:34 +02001533 call assert_match("man -P cat 'man'", a)
1534 else
1535 call assert_match("man --pager=cat 'man'", a)
1536 endif
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001537
Bram Moolenaar1671f442020-03-10 07:48:13 +01001538 " Error cases
1539 call setline(1, '#$#')
1540 call assert_fails('normal! ggK', 'E349:')
1541 call setline(1, '---')
1542 call assert_fails('normal! ggv2lK', 'E349:')
1543 call setline(1, ['abc', 'xyz'])
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001544 call assert_fails("normal! gg2lv2h\<C-]>", 'E433:')
Bram Moolenaar1671f442020-03-10 07:48:13 +01001545 call assert_beeps("normal! ggVjK")
Bram Moolenaar8a9bc952020-10-02 18:48:07 +02001546 norm! V
1547 call assert_beeps("norm! cK")
Bram Moolenaar1671f442020-03-10 07:48:13 +01001548
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001549 " clean up
1550 let &keywordprg = k
1551 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001552endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001553
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001554func Test_normal24_rot13()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001555 " Testing for g?? g?g?
1556 new
1557 call append(0, 'abcdefghijklmnopqrstuvwxyzäüö')
1558 1
1559 norm! g??
1560 call assert_equal('nopqrstuvwxyzabcdefghijklmäüö', getline('.'))
1561 norm! g?g?
1562 call assert_equal('abcdefghijklmnopqrstuvwxyzäüö', getline('.'))
1563
1564 " clean up
1565 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001566endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001567
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001568func Test_normal25_tag()
Bram Moolenaar5a4c3082019-12-01 15:23:11 +01001569 CheckFeature quickfix
1570
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001571 " Testing for CTRL-] g CTRL-] g]
1572 " CTRL-W g] CTRL-W CTRL-] CTRL-W g CTRL-]
1573 h
1574 " Test for CTRL-]
1575 call search('\<x\>$')
1576 exe "norm! \<c-]>"
1577 call assert_equal("change.txt", fnamemodify(bufname('%'), ':t'))
1578 norm! yiW
1579 call assert_equal("*x*", @0)
1580 exe ":norm \<c-o>"
1581
1582 " Test for g_CTRL-]
1583 call search('\<v_u\>$')
1584 exe "norm! g\<c-]>"
1585 call assert_equal("change.txt", fnamemodify(bufname('%'), ':t'))
1586 norm! yiW
1587 call assert_equal("*v_u*", @0)
1588 exe ":norm \<c-o>"
1589
1590 " Test for g]
1591 call search('\<i_<Esc>$')
1592 let a = execute(":norm! g]")
1593 call assert_match('i_<Esc>.*insert.txt', a)
1594
1595 if !empty(exepath('cscope')) && has('cscope')
1596 " setting cscopetag changes how g] works
1597 set cst
1598 exe "norm! g]"
1599 call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t'))
1600 norm! yiW
1601 call assert_equal("*i_<Esc>*", @0)
1602 exe ":norm \<c-o>"
1603 " Test for CTRL-W g]
1604 exe "norm! \<C-W>g]"
1605 call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t'))
1606 norm! yiW
1607 call assert_equal("*i_<Esc>*", @0)
1608 call assert_equal(3, winnr('$'))
1609 helpclose
1610 set nocst
1611 endif
1612
1613 " Test for CTRL-W g]
1614 let a = execute("norm! \<C-W>g]")
1615 call assert_match('i_<Esc>.*insert.txt', a)
1616
1617 " Test for CTRL-W CTRL-]
1618 exe "norm! \<C-W>\<C-]>"
1619 call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t'))
1620 norm! yiW
1621 call assert_equal("*i_<Esc>*", @0)
1622 call assert_equal(3, winnr('$'))
1623 helpclose
1624
1625 " Test for CTRL-W g CTRL-]
1626 exe "norm! \<C-W>g\<C-]>"
1627 call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t'))
1628 norm! yiW
1629 call assert_equal("*i_<Esc>*", @0)
1630 call assert_equal(3, winnr('$'))
1631 helpclose
1632
1633 " clean up
1634 helpclose
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001635endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001636
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001637func Test_normal26_put()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001638 " Test for ]p ]P [p and [P
1639 new
1640 call append(0, ['while read LINE', 'do', ' ((count++))', ' if [ $? -ne 0 ]; then', " echo 'Error writing file'", ' fi', 'done'])
1641 1
1642 /Error/y a
1643 2
1644 norm! "a]pj"a[p
1645 call assert_equal(['do', "echo 'Error writing file'", " echo 'Error writing file'", ' ((count++))'], getline(2,5))
1646 1
1647 /^\s\{4}/
1648 exe "norm! \"a]P3Eldt'"
1649 exe "norm! j\"a[P2Eldt'"
1650 call assert_equal([' if [ $? -ne 0 ]; then', " echo 'Error writing'", " echo 'Error'", " echo 'Error writing file'", ' fi'], getline(6,10))
1651
1652 " clean up
1653 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001654endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001655
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001656func Test_normal27_bracket()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001657 " Test for [' [` ]' ]`
1658 call Setup_NewWindow()
1659 1,21s/.\+/ & b/
1660 1
1661 norm! $ma
1662 5
1663 norm! $mb
1664 10
1665 norm! $mc
1666 15
1667 norm! $md
1668 20
1669 norm! $me
1670
1671 " Test for ['
1672 9
1673 norm! 2['
1674 call assert_equal(' 1 b', getline('.'))
1675 call assert_equal(1, line('.'))
1676 call assert_equal(3, col('.'))
1677
1678 " Test for ]'
1679 norm! ]'
1680 call assert_equal(' 5 b', getline('.'))
1681 call assert_equal(5, line('.'))
1682 call assert_equal(3, col('.'))
1683
1684 " No mark after line 21, cursor moves to first non blank on current line
1685 21
1686 norm! $]'
1687 call assert_equal(' 21 b', getline('.'))
1688 call assert_equal(21, line('.'))
1689 call assert_equal(3, col('.'))
1690
1691 " Test for [`
1692 norm! 2[`
1693 call assert_equal(' 15 b', getline('.'))
1694 call assert_equal(15, line('.'))
1695 call assert_equal(8, col('.'))
1696
1697 " Test for ]`
1698 norm! ]`
1699 call assert_equal(' 20 b', getline('.'))
1700 call assert_equal(20, line('.'))
1701 call assert_equal(8, col('.'))
1702
1703 " clean up
1704 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001705endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001706
Bram Moolenaar1671f442020-03-10 07:48:13 +01001707" Test for ( and ) sentence movements
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001708func Test_normal28_parenthesis()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001709 new
1710 call append(0, ['This is a test. With some sentences!', '', 'Even with a question? And one more. And no sentence here'])
1711
1712 $
1713 norm! d(
1714 call assert_equal(['This is a test. With some sentences!', '', 'Even with a question? And one more. ', ''], getline(1, '$'))
1715 norm! 2d(
1716 call assert_equal(['This is a test. With some sentences!', '', ' ', ''], getline(1, '$'))
1717 1
1718 norm! 0d)
1719 call assert_equal(['With some sentences!', '', ' ', ''], getline(1, '$'))
1720
1721 call append('$', ['This is a long sentence', '', 'spanning', 'over several lines. '])
1722 $
1723 norm! $d(
1724 call assert_equal(['With some sentences!', '', ' ', '', 'This is a long sentence', ''], getline(1, '$'))
1725
Bram Moolenaar224a5f12020-04-28 20:29:07 +02001726 " Move to the next sentence from a paragraph macro
1727 %d
1728 call setline(1, ['.LP', 'blue sky!. blue sky.', 'blue sky. blue sky.'])
1729 call cursor(1, 1)
1730 normal )
1731 call assert_equal([2, 1], [line('.'), col('.')])
1732 normal )
1733 call assert_equal([2, 12], [line('.'), col('.')])
1734 normal ((
1735 call assert_equal([1, 1], [line('.'), col('.')])
1736
Bram Moolenaar1671f442020-03-10 07:48:13 +01001737 " It is an error if a next sentence is not found
1738 %d
1739 call setline(1, '.SH')
1740 call assert_beeps('normal )')
1741
Bram Moolenaar224a5f12020-04-28 20:29:07 +02001742 " If only dot is present, don't treat that as a sentence
1743 call setline(1, '. This is a sentence.')
1744 normal $((
1745 call assert_equal(3, col('.'))
1746
Bram Moolenaar1671f442020-03-10 07:48:13 +01001747 " Jumping to a fold should open the fold
1748 call setline(1, ['', '', 'one', 'two', 'three'])
1749 set foldenable
1750 2,$fold
1751 call feedkeys(')', 'xt')
1752 call assert_equal(3, line('.'))
1753 call assert_equal(1, foldlevel('.'))
1754 call assert_equal(-1, foldclosed('.'))
1755 set foldenable&
1756
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001757 " clean up
1758 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001759endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001760
Bram Moolenaar1671f442020-03-10 07:48:13 +01001761" Test for { and } paragraph movements
1762func Test_normal29_brace()
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001763 let text =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001764 A paragraph begins after each empty line, and also at each of a set of
1765 paragraph macros, specified by the pairs of characters in the 'paragraphs'
1766 option. The default is "IPLPPPQPP TPHPLIPpLpItpplpipbp", which corresponds to
1767 the macros ".IP", ".LP", etc. (These are nroff macros, so the dot must be in
1768 the first column). A section boundary is also a paragraph boundary.
1769 Note that a blank line (only containing white space) is NOT a paragraph
1770 boundary.
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001771
1772
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001773 Also note that this does not include a '{' or '}' in the first column. When
1774 the '{' flag is in 'cpoptions' then '{' in the first column is used as a
1775 paragraph boundary |posix|.
1776 {
1777 This is no paragraph
1778 unless the '{' is set
1779 in 'cpoptions'
1780 }
1781 .IP
1782 The nroff macros IP separates a paragraph
1783 That means, it must be a '.'
1784 followed by IP
1785 .LPIt does not matter, if afterwards some
1786 more characters follow.
1787 .SHAlso section boundaries from the nroff
1788 macros terminate a paragraph. That means
1789 a character like this:
1790 .NH
1791 End of text here
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001792 [DATA]
1793
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001794 new
1795 call append(0, text)
1796 1
1797 norm! 0d2}
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001798
1799 let expected =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001800 .IP
1801 The nroff macros IP separates a paragraph
1802 That means, it must be a '.'
1803 followed by IP
1804 .LPIt does not matter, if afterwards some
1805 more characters follow.
1806 .SHAlso section boundaries from the nroff
1807 macros terminate a paragraph. That means
1808 a character like this:
1809 .NH
1810 End of text here
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001811
1812 [DATA]
1813 call assert_equal(expected, getline(1, '$'))
1814
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001815 norm! 0d}
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001816
1817 let expected =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001818 .LPIt does not matter, if afterwards some
1819 more characters follow.
1820 .SHAlso section boundaries from the nroff
1821 macros terminate a paragraph. That means
1822 a character like this:
1823 .NH
1824 End of text here
1825
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001826 [DATA]
1827 call assert_equal(expected, getline(1, '$'))
1828
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001829 $
1830 norm! d{
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001831
1832 let expected =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001833 .LPIt does not matter, if afterwards some
1834 more characters follow.
1835 .SHAlso section boundaries from the nroff
1836 macros terminate a paragraph. That means
1837 a character like this:
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001838
1839 [DATA]
1840 call assert_equal(expected, getline(1, '$'))
1841
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001842 norm! d{
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001843
1844 let expected =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001845 .LPIt does not matter, if afterwards some
1846 more characters follow.
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001847
1848 [DATA]
1849 call assert_equal(expected, getline(1, '$'))
1850
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001851 " Test with { in cpooptions
1852 %d
1853 call append(0, text)
1854 set cpo+={
1855 1
1856 norm! 0d2}
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001857
1858 let expected =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001859 {
1860 This is no paragraph
1861 unless the '{' is set
1862 in 'cpoptions'
1863 }
1864 .IP
1865 The nroff macros IP separates a paragraph
1866 That means, it must be a '.'
1867 followed by IP
1868 .LPIt does not matter, if afterwards some
1869 more characters follow.
1870 .SHAlso section boundaries from the nroff
1871 macros terminate a paragraph. That means
1872 a character like this:
1873 .NH
1874 End of text here
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001875
1876 [DATA]
1877 call assert_equal(expected, getline(1, '$'))
1878
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001879 $
1880 norm! d}
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001881
1882 let expected =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001883 {
1884 This is no paragraph
1885 unless the '{' is set
1886 in 'cpoptions'
1887 }
1888 .IP
1889 The nroff macros IP separates a paragraph
1890 That means, it must be a '.'
1891 followed by IP
1892 .LPIt does not matter, if afterwards some
1893 more characters follow.
1894 .SHAlso section boundaries from the nroff
1895 macros terminate a paragraph. That means
1896 a character like this:
1897 .NH
1898 End of text here
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001899
1900 [DATA]
1901 call assert_equal(expected, getline(1, '$'))
1902
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001903 norm! gg}
1904 norm! d5}
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001905
1906 let expected =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001907 {
1908 This is no paragraph
1909 unless the '{' is set
1910 in 'cpoptions'
1911 }
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001912
1913 [DATA]
1914 call assert_equal(expected, getline(1, '$'))
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001915
Bram Moolenaar1671f442020-03-10 07:48:13 +01001916 " Jumping to a fold should open the fold
1917 %d
1918 call setline(1, ['', 'one', 'two', ''])
1919 set foldenable
1920 2,$fold
1921 call feedkeys('}', 'xt')
1922 call assert_equal(4, line('.'))
1923 call assert_equal(1, foldlevel('.'))
1924 call assert_equal(-1, foldclosed('.'))
1925 set foldenable&
1926
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001927 " clean up
1928 set cpo-={
1929 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001930endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001931
Bram Moolenaar8a9bc952020-10-02 18:48:07 +02001932" Test for section movements
1933func Test_normal_section()
1934 new
1935 let lines =<< trim [END]
1936 int foo()
1937 {
1938 if (1)
1939 {
1940 a = 1;
1941 }
1942 }
1943 [END]
1944 call setline(1, lines)
1945
1946 " jumping to a folded line using [[ should open the fold
1947 2,3fold
1948 call cursor(5, 1)
1949 call feedkeys("[[", 'xt')
1950 call assert_equal(2, line('.'))
1951 call assert_equal(-1, foldclosedend(line('.')))
1952
1953 close!
1954endfunc
1955
Bram Moolenaard1ad99b2020-10-04 16:16:54 +02001956" Test for changing case using u, U, gu, gU and ~ (tilde) commands
Bram Moolenaar1671f442020-03-10 07:48:13 +01001957func Test_normal30_changecase()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001958 new
1959 call append(0, 'This is a simple test: äüöß')
1960 norm! 1ggVu
1961 call assert_equal('this is a simple test: äüöß', getline('.'))
1962 norm! VU
1963 call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖSS', getline('.'))
1964 norm! guu
1965 call assert_equal('this is a simple test: äüöss', getline('.'))
1966 norm! gUgU
1967 call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖSS', getline('.'))
1968 norm! gugu
1969 call assert_equal('this is a simple test: äüöss', getline('.'))
1970 norm! gUU
1971 call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖSS', getline('.'))
1972 norm! 010~
1973 call assert_equal('this is a SIMPLE TEST: ÄÜÖSS', getline('.'))
1974 norm! V~
1975 call assert_equal('THIS IS A simple test: äüöss', getline('.'))
Bram Moolenaard1ad99b2020-10-04 16:16:54 +02001976 call assert_beeps('norm! c~')
1977 %d
1978 call assert_beeps('norm! ~')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001979
Bram Moolenaar1671f442020-03-10 07:48:13 +01001980 " Test for changing case across lines using 'whichwrap'
1981 call setline(1, ['aaaaaa', 'aaaaaa'])
1982 normal! gg10~
1983 call assert_equal(['AAAAAA', 'aaaaaa'], getline(1, 2))
1984 set whichwrap+=~
1985 normal! gg10~
1986 call assert_equal(['aaaaaa', 'AAAAaa'], getline(1, 2))
1987 set whichwrap&
1988
1989 " clean up
1990 bw!
1991endfunc
1992
1993" Turkish ASCII turns to multi-byte. On some systems Turkish locale
1994" is available but toupper()/tolower() don't do the right thing.
1995func Test_normal_changecase_turkish()
1996 new
Bram Moolenaarf1c118b2018-09-03 22:08:10 +02001997 try
1998 lang tr_TR.UTF-8
1999 set casemap=
2000 let iupper = toupper('i')
2001 if iupper == "\u0130"
Bram Moolenaar9f4de1f2017-04-08 19:39:43 +02002002 call setline(1, 'iI')
2003 1normal gUU
2004 call assert_equal("\u0130I", getline(1))
2005 call assert_equal("\u0130I", toupper("iI"))
Bram Moolenaar3317d5e2017-04-08 19:12:06 +02002006
Bram Moolenaar9f4de1f2017-04-08 19:39:43 +02002007 call setline(1, 'iI')
2008 1normal guu
2009 call assert_equal("i\u0131", getline(1))
2010 call assert_equal("i\u0131", tolower("iI"))
Bram Moolenaarf1c118b2018-09-03 22:08:10 +02002011 elseif iupper == "I"
Bram Moolenaar1cc48202017-04-09 13:41:59 +02002012 call setline(1, 'iI')
2013 1normal gUU
2014 call assert_equal("II", getline(1))
2015 call assert_equal("II", toupper("iI"))
2016
2017 call setline(1, 'iI')
2018 1normal guu
2019 call assert_equal("ii", getline(1))
2020 call assert_equal("ii", tolower("iI"))
Bram Moolenaarf1c118b2018-09-03 22:08:10 +02002021 else
2022 call assert_true(false, "expected toupper('i') to be either 'I' or '\u0130'")
2023 endif
2024 set casemap&
2025 call setline(1, 'iI')
2026 1normal gUU
2027 call assert_equal("II", getline(1))
2028 call assert_equal("II", toupper("iI"))
Bram Moolenaar1cc48202017-04-09 13:41:59 +02002029
Bram Moolenaarf1c118b2018-09-03 22:08:10 +02002030 call setline(1, 'iI')
2031 1normal guu
2032 call assert_equal("ii", getline(1))
2033 call assert_equal("ii", tolower("iI"))
2034
2035 lang en_US.UTF-8
2036 catch /E197:/
2037 " can't use Turkish locale
2038 throw 'Skipped: Turkish locale not available'
2039 endtry
Bram Moolenaar1671f442020-03-10 07:48:13 +01002040 close!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002041endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002042
Bram Moolenaar1671f442020-03-10 07:48:13 +01002043" Test for r (replace) command
2044func Test_normal31_r_cmd()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002045 new
2046 call append(0, 'This is a simple test: abcd')
2047 exe "norm! 1gg$r\<cr>"
2048 call assert_equal(['This is a simple test: abc', '', ''], getline(1,'$'))
2049 exe "norm! 1gg2wlr\<cr>"
2050 call assert_equal(['This is a', 'simple test: abc', '', ''], getline(1,'$'))
2051 exe "norm! 2gg0W5r\<cr>"
2052 call assert_equal(['This is a', 'simple ', ' abc', '', ''], getline('1', '$'))
2053 set autoindent
2054 call setline(2, ['simple test: abc', ''])
2055 exe "norm! 2gg0W5r\<cr>"
2056 call assert_equal(['This is a', 'simple ', 'abc', '', '', ''], getline('1', '$'))
2057 exe "norm! 1ggVr\<cr>"
2058 call assert_equal('^M^M^M^M^M^M^M^M^M', strtrans(getline(1)))
2059 call setline(1, 'This is a')
2060 exe "norm! 1gg05rf"
2061 call assert_equal('fffffis a', getline(1))
2062
Bram Moolenaar1671f442020-03-10 07:48:13 +01002063 " When replacing characters, copy characters from above and below lines
2064 " using CTRL-Y and CTRL-E.
2065 " Different code paths are used for utf-8 and latin1 encodings
2066 set showmatch
2067 for enc in ['latin1', 'utf-8']
2068 enew!
2069 let &encoding = enc
2070 call setline(1, [' {a}', 'xxxxxxxxxx', ' [b]'])
2071 exe "norm! 2gg5r\<C-Y>l5r\<C-E>"
2072 call assert_equal(' {a}x [b]x', getline(2))
2073 endfor
2074 set showmatch&
2075
2076 " r command should fail in operator pending mode
2077 call assert_beeps('normal! cr')
2078
Bram Moolenaar004a6782020-04-11 17:09:31 +02002079 " replace a tab character in visual mode
2080 %d
2081 call setline(1, ["a\tb", "c\td", "e\tf"])
2082 normal gglvjjrx
2083 call assert_equal(['axx', 'xxx', 'xxf'], getline(1, '$'))
2084
Bram Moolenaard7e5e942020-10-07 16:54:52 +02002085 " replace with a multibyte character (with multiple composing characters)
2086 %d
2087 new
2088 call setline(1, 'aaa')
2089 exe "normal $ra\u0328\u0301"
2090 call assert_equal("aaa\u0328\u0301", getline(1))
2091
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002092 " clean up
2093 set noautoindent
2094 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002095endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002096
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002097" Test for g*, g#
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002098func Test_normal32_g_cmd1()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002099 new
2100 call append(0, ['abc.x_foo', 'x_foobar.abc'])
2101 1
2102 norm! $g*
2103 call assert_equal('x_foo', @/)
2104 call assert_equal('x_foobar.abc', getline('.'))
2105 norm! $g#
2106 call assert_equal('abc', @/)
2107 call assert_equal('abc.x_foo', getline('.'))
2108
2109 " clean up
2110 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002111endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002112
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002113" Test for g`, g;, g,, g&, gv, gk, gj, gJ, g0, g^, g_, gm, g$, gM, g CTRL-G,
2114" gi and gI commands
Bram Moolenaar1671f442020-03-10 07:48:13 +01002115func Test_normal33_g_cmd2()
Bram Moolenaar004a6782020-04-11 17:09:31 +02002116 CheckFeature jumplist
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002117 call Setup_NewWindow()
2118 " Test for g`
2119 clearjumps
2120 norm! ma10j
2121 let a=execute(':jumps')
2122 " empty jumplist
2123 call assert_equal('>', a[-1:])
2124 norm! g`a
2125 call assert_equal('>', a[-1:])
2126 call assert_equal(1, line('.'))
2127 call assert_equal('1', getline('.'))
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002128 call cursor(10, 1)
2129 norm! g'a
2130 call assert_equal('>', a[-1:])
2131 call assert_equal(1, line('.'))
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002132
2133 " Test for g; and g,
2134 norm! g;
2135 " there is only one change in the changelist
2136 " currently, when we setup the window
2137 call assert_equal(2, line('.'))
Bram Moolenaare2e40752020-09-04 21:18:46 +02002138 call assert_fails(':norm! g;', 'E662:')
2139 call assert_fails(':norm! g,', 'E663:')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002140 let &ul=&ul
2141 call append('$', ['a', 'b', 'c', 'd'])
2142 let &ul=&ul
2143 call append('$', ['Z', 'Y', 'X', 'W'])
2144 let a = execute(':changes')
2145 call assert_match('2\s\+0\s\+2', a)
2146 call assert_match('101\s\+0\s\+a', a)
2147 call assert_match('105\s\+0\s\+Z', a)
2148 norm! 3g;
2149 call assert_equal(2, line('.'))
2150 norm! 2g,
2151 call assert_equal(105, line('.'))
2152
2153 " Test for g& - global substitute
2154 %d
2155 call setline(1, range(1,10))
2156 call append('$', ['a', 'b', 'c', 'd'])
2157 $s/\w/&&/g
2158 exe "norm! /[1-8]\<cr>"
2159 norm! g&
2160 call assert_equal(['11', '22', '33', '44', '55', '66', '77', '88', '9', '110', 'a', 'b', 'c', 'dd'], getline(1, '$'))
2161
Bram Moolenaar1671f442020-03-10 07:48:13 +01002162 " Jumping to a fold using gg should open the fold
2163 set foldenable
2164 set foldopen+=jump
2165 5,8fold
2166 call feedkeys('6gg', 'xt')
2167 call assert_equal(1, foldlevel('.'))
2168 call assert_equal(-1, foldclosed('.'))
2169 set foldopen-=jump
2170 set foldenable&
2171
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002172 " Test for gv
2173 %d
2174 call append('$', repeat(['abcdefgh'], 8))
2175 exe "norm! 2gg02l\<c-v>2j2ly"
2176 call assert_equal(['cde', 'cde', 'cde'], getreg(0, 1, 1))
2177 " in visual mode, gv swaps current and last selected region
2178 exe "norm! G0\<c-v>4k4lgvd"
2179 call assert_equal(['', 'abfgh', 'abfgh', 'abfgh', 'abcdefgh', 'abcdefgh', 'abcdefgh', 'abcdefgh', 'abcdefgh'], getline(1,'$'))
2180 exe "norm! G0\<c-v>4k4ly"
2181 exe "norm! gvood"
2182 call assert_equal(['', 'abfgh', 'abfgh', 'abfgh', 'fgh', 'fgh', 'fgh', 'fgh', 'fgh'], getline(1,'$'))
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002183 " gv cannot be used in operator pending mode
2184 call assert_beeps('normal! cgv')
2185 " gv should beep without a previously selected visual area
2186 new
2187 call assert_beeps('normal! gv')
2188 close
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002189
2190 " Test for gk/gj
2191 %d
2192 15vsp
2193 set wrap listchars= sbr=
2194 let lineA='abcdefghijklmnopqrstuvwxyz'
2195 let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
Bram Moolenaar8b530c12019-10-28 02:13:05 +01002196 let lineC='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002197 $put =lineA
2198 $put =lineB
2199
2200 norm! 3gg0dgk
2201 call assert_equal(['', 'abcdefghijklmno', '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'], getline(1, '$'))
2202 set nu
2203 norm! 3gg0gjdgj
2204 call assert_equal(['', 'abcdefghijklmno', '0123456789AMNOPQRSTUVWXYZ'], getline(1,'$'))
2205
2206 " Test for gJ
2207 norm! 2gggJ
2208 call assert_equal(['', 'abcdefghijklmno0123456789AMNOPQRSTUVWXYZ'], getline(1,'$'))
2209 call assert_equal(16, col('.'))
2210 " shouldn't do anything
2211 norm! 10gJ
2212 call assert_equal(1, col('.'))
2213
2214 " Test for g0 g^ gm g$
2215 exe "norm! 2gg0gji "
2216 call assert_equal(['', 'abcdefghijk lmno0123456789AMNOPQRSTUVWXYZ'], getline(1,'$'))
2217 norm! g0yl
2218 call assert_equal(12, col('.'))
2219 call assert_equal(' ', getreg(0))
2220 norm! g$yl
2221 call assert_equal(22, col('.'))
2222 call assert_equal('3', getreg(0))
2223 norm! gmyl
2224 call assert_equal(17, col('.'))
2225 call assert_equal('n', getreg(0))
2226 norm! g^yl
2227 call assert_equal(15, col('.'))
2228 call assert_equal('l', getreg(0))
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002229 call assert_beeps('normal 5g$')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002230
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002231 " Test for g_
2232 call assert_beeps('normal! 100g_')
2233 call setline(2, [' foo ', ' foobar '])
2234 normal! 2ggg_
2235 call assert_equal(5, col('.'))
2236 normal! 2g_
2237 call assert_equal(8, col('.'))
2238
2239 norm! 2ggdG
Bram Moolenaar8b530c12019-10-28 02:13:05 +01002240 $put =lineC
2241
2242 " Test for gM
2243 norm! gMyl
2244 call assert_equal(73, col('.'))
2245 call assert_equal('0', getreg(0))
2246 " Test for 20gM
2247 norm! 20gMyl
2248 call assert_equal(29, col('.'))
2249 call assert_equal('S', getreg(0))
2250 " Test for 60gM
2251 norm! 60gMyl
2252 call assert_equal(87, col('.'))
2253 call assert_equal('E', getreg(0))
2254
2255 " Test for g Ctrl-G
2256 set ff=unix
2257 let a=execute(":norm! g\<c-g>")
2258 call assert_match('Col 87 of 144; Line 2 of 2; Word 1 of 1; Byte 88 of 146', a)
2259
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002260 " Test for gI
2261 norm! gIfoo
Bram Moolenaar8b530c12019-10-28 02:13:05 +01002262 call assert_equal(['', 'foo0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'], getline(1,'$'))
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002263
2264 " Test for gi
2265 wincmd c
2266 %d
2267 set tw=0
2268 call setline(1, ['foobar', 'new line'])
2269 norm! A next word
2270 $put ='third line'
2271 norm! gi another word
2272 call assert_equal(['foobar next word another word', 'new line', 'third line'], getline(1,'$'))
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002273 call setline(1, 'foobar')
2274 normal! Ggifirst line
2275 call assert_equal('foobarfirst line', getline(1))
2276 " Test gi in 'virtualedit' mode with cursor after the end of the line
2277 set virtualedit=all
2278 call setline(1, 'foo')
2279 exe "normal! Abar\<Right>\<Right>\<Right>\<Right>"
2280 call setline(1, 'foo')
2281 normal! Ggifirst line
2282 call assert_equal('foo first line', getline(1))
2283 set virtualedit&
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002284
Bram Moolenaar1671f442020-03-10 07:48:13 +01002285 " Test for aboring a g command using CTRL-\ CTRL-G
2286 exe "normal! g\<C-\>\<C-G>"
2287 call assert_equal('foo first line', getline('.'))
2288
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002289 " clean up
2290 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002291endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002292
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002293" Test for g CTRL-G
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002294func Test_g_ctrl_g()
Bram Moolenaar05295832018-08-24 22:07:58 +02002295 new
2296
2297 let a = execute(":norm! g\<c-g>")
2298 call assert_equal("\n--No lines in buffer--", a)
2299
Bram Moolenaar1671f442020-03-10 07:48:13 +01002300 " Test for CTRL-G (same as :file)
2301 let a = execute(":norm! \<c-g>")
2302 call assert_equal("\n\n\"[No Name]\" --No lines in buffer--", a)
2303
Bram Moolenaar05295832018-08-24 22:07:58 +02002304 call setline(1, ['first line', 'second line'])
2305
2306 " Test g CTRL-g with dos, mac and unix file type.
2307 norm! gojll
2308 set ff=dos
2309 let a = execute(":norm! g\<c-g>")
2310 call assert_equal("\nCol 3 of 11; Line 2 of 2; Word 3 of 4; Byte 15 of 25", a)
2311
2312 set ff=mac
2313 let a = execute(":norm! g\<c-g>")
2314 call assert_equal("\nCol 3 of 11; Line 2 of 2; Word 3 of 4; Byte 14 of 23", a)
2315
2316 set ff=unix
2317 let a = execute(":norm! g\<c-g>")
2318 call assert_equal("\nCol 3 of 11; Line 2 of 2; Word 3 of 4; Byte 14 of 23", a)
2319
2320 " Test g CTRL-g in visual mode (v)
2321 let a = execute(":norm! gojllvlg\<c-g>")
2322 call assert_equal("\nSelected 1 of 2 Lines; 1 of 4 Words; 2 of 23 Bytes", a)
2323
2324 " Test g CTRL-g in visual mode (CTRL-V) with end col > start col
2325 let a = execute(":norm! \<Esc>gojll\<C-V>kllg\<c-g>")
2326 call assert_equal("\nSelected 3 Cols; 2 of 2 Lines; 2 of 4 Words; 6 of 23 Bytes", a)
2327
2328 " Test g_CTRL-g in visual mode (CTRL-V) with end col < start col
2329 let a = execute(":norm! \<Esc>goll\<C-V>jhhg\<c-g>")
2330 call assert_equal("\nSelected 3 Cols; 2 of 2 Lines; 2 of 4 Words; 6 of 23 Bytes", a)
2331
2332 " Test g CTRL-g in visual mode (CTRL-V) with end_vcol being MAXCOL
2333 let a = execute(":norm! \<Esc>gojll\<C-V>k$g\<c-g>")
2334 call assert_equal("\nSelected 2 of 2 Lines; 4 of 4 Words; 17 of 23 Bytes", a)
2335
2336 " There should be one byte less with noeol
2337 set bin noeol
2338 let a = execute(":norm! \<Esc>gog\<c-g>")
2339 call assert_equal("\nCol 1 of 10; Line 1 of 2; Word 1 of 4; Char 1 of 23; Byte 1 of 22", a)
2340 set bin & eol&
2341
Bram Moolenaar30276f22019-01-24 17:59:39 +01002342 call setline(1, ['Français', '日本語'])
Bram Moolenaar05295832018-08-24 22:07:58 +02002343
Bram Moolenaar30276f22019-01-24 17:59:39 +01002344 let a = execute(":norm! \<Esc>gojlg\<c-g>")
2345 call assert_equal("\nCol 4-3 of 9-6; Line 2 of 2; Word 2 of 2; Char 11 of 13; Byte 16 of 20", a)
Bram Moolenaar05295832018-08-24 22:07:58 +02002346
Bram Moolenaar30276f22019-01-24 17:59:39 +01002347 let a = execute(":norm! \<Esc>gojvlg\<c-g>")
2348 call assert_equal("\nSelected 1 of 2 Lines; 1 of 2 Words; 2 of 13 Chars; 6 of 20 Bytes", a)
Bram Moolenaar05295832018-08-24 22:07:58 +02002349
Bram Moolenaar30276f22019-01-24 17:59:39 +01002350 let a = execute(":norm! \<Esc>goll\<c-v>jlg\<c-g>")
2351 call assert_equal("\nSelected 4 Cols; 2 of 2 Lines; 2 of 2 Words; 6 of 13 Chars; 11 of 20 Bytes", a)
Bram Moolenaar05295832018-08-24 22:07:58 +02002352
Bram Moolenaar30276f22019-01-24 17:59:39 +01002353 set fenc=utf8 bomb
2354 let a = execute(":norm! \<Esc>gojlg\<c-g>")
2355 call assert_equal("\nCol 4-3 of 9-6; Line 2 of 2; Word 2 of 2; Char 11 of 13; Byte 16 of 20(+3 for BOM)", a)
Bram Moolenaar05295832018-08-24 22:07:58 +02002356
Bram Moolenaar30276f22019-01-24 17:59:39 +01002357 set fenc=utf16 bomb
2358 let a = execute(":norm! g\<c-g>")
2359 call assert_equal("\nCol 4-3 of 9-6; Line 2 of 2; Word 2 of 2; Char 11 of 13; Byte 16 of 20(+2 for BOM)", a)
Bram Moolenaar05295832018-08-24 22:07:58 +02002360
Bram Moolenaar30276f22019-01-24 17:59:39 +01002361 set fenc=utf32 bomb
2362 let a = execute(":norm! g\<c-g>")
2363 call assert_equal("\nCol 4-3 of 9-6; Line 2 of 2; Word 2 of 2; Char 11 of 13; Byte 16 of 20(+4 for BOM)", a)
Bram Moolenaar05295832018-08-24 22:07:58 +02002364
Bram Moolenaar30276f22019-01-24 17:59:39 +01002365 set fenc& bomb&
Bram Moolenaar05295832018-08-24 22:07:58 +02002366
2367 set ff&
2368 bwipe!
2369endfunc
2370
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002371" Test for g8
Bram Moolenaar1671f442020-03-10 07:48:13 +01002372func Test_normal34_g_cmd3()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002373 new
Bram Moolenaar395b6ba2017-04-07 20:09:51 +02002374 let a=execute(':norm! 1G0g8')
2375 call assert_equal("\nNUL", a)
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002376
Bram Moolenaar395b6ba2017-04-07 20:09:51 +02002377 call setline(1, 'abcdefghijklmnopqrstuvwxyzäüö')
2378 let a=execute(':norm! 1G$g8')
2379 call assert_equal("\nc3 b6 ", a)
2380
2381 call setline(1, "a\u0302")
2382 let a=execute(':norm! 1G0g8')
2383 call assert_equal("\n61 + cc 82 ", a)
2384
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002385 " clean up
2386 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002387endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002388
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002389" Test 8g8 which finds invalid utf8 at or after the cursor.
Bram Moolenaar395b6ba2017-04-07 20:09:51 +02002390func Test_normal_8g8()
Bram Moolenaar395b6ba2017-04-07 20:09:51 +02002391 new
2392
Bram Moolenaar395b6ba2017-04-07 20:09:51 +02002393 " With invalid byte.
2394 call setline(1, "___\xff___")
2395 norm! 1G08g8g
2396 call assert_equal([0, 1, 4, 0, 1], getcurpos())
2397
2398 " With invalid byte before the cursor.
2399 call setline(1, "___\xff___")
2400 norm! 1G$h8g8g
2401 call assert_equal([0, 1, 6, 0, 9], getcurpos())
2402
2403 " With truncated sequence.
2404 call setline(1, "___\xE2\x82___")
2405 norm! 1G08g8g
2406 call assert_equal([0, 1, 4, 0, 1], getcurpos())
2407
2408 " With overlong sequence.
2409 call setline(1, "___\xF0\x82\x82\xAC___")
2410 norm! 1G08g8g
2411 call assert_equal([0, 1, 4, 0, 1], getcurpos())
2412
2413 " With valid utf8.
2414 call setline(1, "café")
2415 norm! 1G08g8
2416 call assert_equal([0, 1, 1, 0, 1], getcurpos())
2417
2418 bw!
2419endfunc
2420
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002421" Test for g<
Bram Moolenaar1671f442020-03-10 07:48:13 +01002422func Test_normal35_g_cmd4()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002423 " Cannot capture its output,
2424 " probably a bug, therefore, test disabled:
Bram Moolenaar31845092016-09-05 22:58:31 +02002425 throw "Skipped: output of g< can't be tested currently"
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002426 echo "a\nb\nc\nd"
2427 let b=execute(':norm! g<')
2428 call assert_true(!empty(b), 'failed `execute(g<)`')
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002429endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002430
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002431" Test for gp gP go
Bram Moolenaar1671f442020-03-10 07:48:13 +01002432func Test_normal36_g_cmd5()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002433 new
2434 call append(0, 'abcdefghijklmnopqrstuvwxyz')
Bram Moolenaar0913a102016-09-03 19:11:59 +02002435 set ff=unix
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002436 " Test for gp gP
2437 call append(1, range(1,10))
2438 1
2439 norm! 1yy
2440 3
2441 norm! gp
2442 call assert_equal([0, 5, 1, 0, 1], getcurpos())
2443 $
2444 norm! gP
2445 call assert_equal([0, 14, 1, 0, 1], getcurpos())
2446
2447 " Test for go
2448 norm! 26go
2449 call assert_equal([0, 1, 26, 0, 26], getcurpos())
2450 norm! 27go
2451 call assert_equal([0, 1, 26, 0, 26], getcurpos())
2452 norm! 28go
2453 call assert_equal([0, 2, 1, 0, 1], getcurpos())
2454 set ff=dos
2455 norm! 29go
2456 call assert_equal([0, 2, 1, 0, 1], getcurpos())
2457 set ff=unix
2458 norm! gg0
2459 norm! 101go
2460 call assert_equal([0, 13, 26, 0, 26], getcurpos())
2461 norm! 103go
2462 call assert_equal([0, 14, 1, 0, 1], getcurpos())
2463 " count > buffer content
2464 norm! 120go
2465 call assert_equal([0, 14, 1, 0, 2147483647], getcurpos())
2466 " clean up
2467 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002468endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002469
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002470" Test for gt and gT
Bram Moolenaar1671f442020-03-10 07:48:13 +01002471func Test_normal37_g_cmd6()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002472 tabnew 1.txt
2473 tabnew 2.txt
2474 tabnew 3.txt
2475 norm! 1gt
2476 call assert_equal(1, tabpagenr())
2477 norm! 3gt
2478 call assert_equal(3, tabpagenr())
2479 norm! 1gT
2480 " count gT goes not to the absolute tabpagenumber
2481 " but, but goes to the count previous tabpagenumber
2482 call assert_equal(2, tabpagenr())
2483 " wrap around
2484 norm! 3gT
2485 call assert_equal(3, tabpagenr())
2486 " gt does not wrap around
2487 norm! 5gt
2488 call assert_equal(3, tabpagenr())
2489
2490 for i in range(3)
2491 tabclose
2492 endfor
2493 " clean up
Bram Moolenaarbc2b71d2020-02-17 21:33:30 +01002494 call assert_fails(':tabclose', 'E784:')
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002495endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002496
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002497" Test for <Home> and <C-Home> key
Bram Moolenaar1671f442020-03-10 07:48:13 +01002498func Test_normal38_nvhome()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002499 new
2500 call setline(1, range(10))
2501 $
2502 setl et sw=2
2503 norm! V10>$
2504 " count is ignored
2505 exe "norm! 10\<home>"
2506 call assert_equal(1, col('.'))
2507 exe "norm! \<home>"
2508 call assert_equal([0, 10, 1, 0, 1], getcurpos())
2509 exe "norm! 5\<c-home>"
2510 call assert_equal([0, 5, 1, 0, 1], getcurpos())
2511 exe "norm! \<c-home>"
2512 call assert_equal([0, 1, 1, 0, 1], getcurpos())
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002513 exe "norm! G\<c-kHome>"
2514 call assert_equal([0, 1, 1, 0, 1], getcurpos())
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002515
2516 " clean up
2517 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002518endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002519
Bram Moolenaar1671f442020-03-10 07:48:13 +01002520" Test for <End> and <C-End> keys
2521func Test_normal_nvend()
2522 new
2523 call setline(1, map(range(1, 10), '"line" .. v:val'))
2524 exe "normal! \<End>"
2525 call assert_equal(5, col('.'))
2526 exe "normal! 4\<End>"
2527 call assert_equal([4, 5], [line('.'), col('.')])
2528 exe "normal! \<C-End>"
2529 call assert_equal([10, 6], [line('.'), col('.')])
2530 close!
2531endfunc
2532
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002533" Test for cw cW ce
Bram Moolenaar1671f442020-03-10 07:48:13 +01002534func Test_normal39_cw()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002535 " Test for cw and cW on whitespace
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002536 new
2537 set tw=0
2538 call append(0, 'here are some words')
2539 norm! 1gg0elcwZZZ
2540 call assert_equal('hereZZZare some words', getline('.'))
2541 norm! 1gg0elcWYYY
2542 call assert_equal('hereZZZareYYYsome words', getline('.'))
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002543 norm! 2gg0cwfoo
2544 call assert_equal('foo', getline('.'))
2545
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002546 call setline(1, 'one; two')
2547 call cursor(1, 1)
2548 call feedkeys('cwvim', 'xt')
2549 call assert_equal('vim; two', getline(1))
2550 call feedkeys('0cWone', 'xt')
2551 call assert_equal('one two', getline(1))
2552 "When cursor is at the end of a word 'ce' will change until the end of the
2553 "next word, but 'cw' will change only one character
2554 call setline(1, 'one two')
2555 call feedkeys('0ecwce', 'xt')
2556 call assert_equal('once two', getline(1))
2557 call setline(1, 'one two')
2558 call feedkeys('0ecely', 'xt')
2559 call assert_equal('only', getline(1))
2560
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002561 " clean up
2562 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002563endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002564
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002565" Test for CTRL-\ commands
Bram Moolenaar1671f442020-03-10 07:48:13 +01002566func Test_normal40_ctrl_bsl()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002567 new
2568 call append(0, 'here are some words')
2569 exe "norm! 1gg0a\<C-\>\<C-N>"
2570 call assert_equal('n', mode())
2571 call assert_equal(1, col('.'))
2572 call assert_equal('', visualmode())
2573 exe "norm! 1gg0viw\<C-\>\<C-N>"
2574 call assert_equal('n', mode())
2575 call assert_equal(4, col('.'))
2576 exe "norm! 1gg0a\<C-\>\<C-G>"
2577 call assert_equal('n', mode())
2578 call assert_equal(1, col('.'))
2579 "imap <buffer> , <c-\><c-n>
2580 set im
2581 exe ":norm! \<c-\>\<c-n>dw"
2582 set noim
2583 call assert_equal('are some words', getline(1))
2584 call assert_false(&insertmode)
Bram Moolenaar1671f442020-03-10 07:48:13 +01002585 call assert_beeps("normal! \<C-\>\<C-A>", 'xt')
2586
2587 " Using CTRL-\ CTRL-N in cmd window should close the window
2588 call feedkeys("q:\<C-\>\<C-N>", 'xt')
2589 call assert_equal('', getcmdwintype())
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002590
2591 " clean up
2592 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002593endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002594
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002595" Test for <c-r>=, <c-r><c-r>= and <c-r><c-o>= in insert mode
Bram Moolenaar1671f442020-03-10 07:48:13 +01002596func Test_normal41_insert_reg()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002597 new
2598 set sts=2 sw=2 ts=8 tw=0
2599 call append(0, ["aaa\tbbb\tccc", '', '', ''])
2600 let a=getline(1)
2601 norm! 2gg0
2602 exe "norm! a\<c-r>=a\<cr>"
2603 norm! 3gg0
2604 exe "norm! a\<c-r>\<c-r>=a\<cr>"
2605 norm! 4gg0
2606 exe "norm! a\<c-r>\<c-o>=a\<cr>"
2607 call assert_equal(['aaa bbb ccc', 'aaa bbb ccc', 'aaa bbb ccc', 'aaa bbb ccc', ''], getline(1, '$'))
2608
2609 " clean up
2610 set sts=0 sw=8 ts=8
Bram Moolenaar31845092016-09-05 22:58:31 +02002611 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002612endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002613
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002614" Test for Ctrl-D and Ctrl-U
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002615func Test_normal42_halfpage()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002616 call Setup_NewWindow()
2617 call assert_equal(5, &scroll)
2618 exe "norm! \<c-d>"
2619 call assert_equal('6', getline('.'))
2620 exe "norm! 2\<c-d>"
2621 call assert_equal('8', getline('.'))
2622 call assert_equal(2, &scroll)
2623 set scroll=5
2624 exe "norm! \<c-u>"
2625 call assert_equal('3', getline('.'))
2626 1
2627 set scrolloff=5
2628 exe "norm! \<c-d>"
2629 call assert_equal('10', getline('.'))
2630 exe "norm! \<c-u>"
2631 call assert_equal('5', getline('.'))
2632 1
2633 set scrolloff=99
2634 exe "norm! \<c-d>"
2635 call assert_equal('10', getline('.'))
2636 set scrolloff=0
2637 100
2638 exe "norm! $\<c-u>"
2639 call assert_equal('95', getline('.'))
2640 call assert_equal([0, 95, 1, 0, 1], getcurpos())
2641 100
2642 set nostartofline
2643 exe "norm! $\<c-u>"
2644 call assert_equal('95', getline('.'))
2645 call assert_equal([0, 95, 2, 0, 2147483647], getcurpos())
2646 " cleanup
2647 set startofline
2648 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002649endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002650
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002651func Test_normal45_drop()
Bram Moolenaar29495952018-02-12 22:49:00 +01002652 if !has('dnd')
Bram Moolenaarb48e96f2018-02-13 12:26:14 +01002653 " The ~ register does not exist
2654 call assert_beeps('norm! "~')
Bram Moolenaar29495952018-02-12 22:49:00 +01002655 return
2656 endif
2657
2658 " basic test for drag-n-drop
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002659 " unfortunately, without a gui, we can't really test much here,
2660 " so simply test that ~p fails (which uses the drop register)
2661 new
Bram Moolenaare2e40752020-09-04 21:18:46 +02002662 call assert_fails(':norm! "~p', 'E353:')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002663 call assert_equal([], getreg('~', 1, 1))
2664 " the ~ register is read only
Bram Moolenaare2e40752020-09-04 21:18:46 +02002665 call assert_fails(':let @~="1"', 'E354:')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002666 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002667endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002668
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002669func Test_normal46_ignore()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002670 new
2671 " How to test this?
2672 " let's just for now test, that the buffer
2673 " does not change
2674 call feedkeys("\<c-s>", 't')
2675 call assert_equal([''], getline(1,'$'))
2676
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002677 " no valid commands
2678 exe "norm! \<char-0x100>"
2679 call assert_equal([''], getline(1,'$'))
2680
2681 exe "norm! ä"
2682 call assert_equal([''], getline(1,'$'))
2683
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002684 " clean up
2685 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002686endfunc
Bram Moolenaarc4a908e2016-09-08 23:35:30 +02002687
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002688func Test_normal47_visual_buf_wipe()
Bram Moolenaarc4a908e2016-09-08 23:35:30 +02002689 " This was causing a crash or ml_get error.
2690 enew!
2691 call setline(1,'xxx')
2692 normal $
2693 new
2694 call setline(1, range(1,2))
2695 2
2696 exe "norm \<C-V>$"
2697 bw!
2698 norm yp
2699 set nomodified
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002700endfunc
2701
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002702func Test_normal48_wincmd()
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002703 new
2704 exe "norm! \<c-w>c"
2705 call assert_equal(1, winnr('$'))
Bram Moolenaare2e40752020-09-04 21:18:46 +02002706 call assert_fails(":norm! \<c-w>c", 'E444:')
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002707endfunc
2708
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002709func Test_normal49_counts()
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002710 new
2711 call setline(1, 'one two three four five six seven eight nine ten')
2712 1
2713 norm! 3d2w
2714 call assert_equal('seven eight nine ten', getline(1))
2715 bw!
2716endfunc
2717
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002718func Test_normal50_commandline()
Bram Moolenaar004a6782020-04-11 17:09:31 +02002719 CheckFeature timers
2720 CheckFeature cmdline_hist
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002721 func! DoTimerWork(id)
2722 call assert_equal('[Command Line]', bufname(''))
2723 " should fail, with E11, but does fail with E23?
2724 "call feedkeys("\<c-^>", 'tm')
2725
2726 " should also fail with E11
Bram Moolenaare2e40752020-09-04 21:18:46 +02002727 call assert_fails(":wincmd p", 'E11:')
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002728 " return from commandline window
2729 call feedkeys("\<cr>")
2730 endfunc
2731
2732 let oldlang=v:lang
2733 lang C
2734 set updatetime=20
2735 call timer_start(100, 'DoTimerWork')
2736 try
2737 " throws E23, for whatever reason...
2738 call feedkeys('q:', 'x!')
2739 catch /E23/
2740 " no-op
2741 endtry
2742 " clean up
2743 set updatetime=4000
2744 exe "lang" oldlang
2745 bw!
2746endfunc
2747
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002748func Test_normal51_FileChangedRO()
Bram Moolenaar004a6782020-04-11 17:09:31 +02002749 CheckFeature autocmd
Bram Moolenaare5f2a072017-02-01 22:31:49 +01002750 " Don't sleep after the warning message.
2751 call test_settime(1)
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002752 call writefile(['foo'], 'Xreadonly.log')
2753 new Xreadonly.log
2754 setl ro
2755 au FileChangedRO <buffer> :call feedkeys("\<c-^>", 'tix')
Bram Moolenaare2e40752020-09-04 21:18:46 +02002756 call assert_fails(":norm! Af", 'E788:')
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002757 call assert_equal(['foo'], getline(1,'$'))
2758 call assert_equal('Xreadonly.log', bufname(''))
2759
2760 " cleanup
Bram Moolenaare5f2a072017-02-01 22:31:49 +01002761 call test_settime(0)
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002762 bw!
2763 call delete("Xreadonly.log")
2764endfunc
2765
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002766func Test_normal52_rl()
Bram Moolenaar004a6782020-04-11 17:09:31 +02002767 CheckFeature rightleft
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002768 new
2769 call setline(1, 'abcde fghij klmnopq')
2770 norm! 1gg$
2771 set rl
2772 call assert_equal(19, col('.'))
2773 call feedkeys('l', 'tx')
2774 call assert_equal(18, col('.'))
2775 call feedkeys('h', 'tx')
2776 call assert_equal(19, col('.'))
2777 call feedkeys("\<right>", 'tx')
2778 call assert_equal(18, col('.'))
Bram Moolenaar1671f442020-03-10 07:48:13 +01002779 call feedkeys("\<left>", 'tx')
2780 call assert_equal(19, col('.'))
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002781 call feedkeys("\<s-right>", 'tx')
2782 call assert_equal(13, col('.'))
2783 call feedkeys("\<c-right>", 'tx')
2784 call assert_equal(7, col('.'))
2785 call feedkeys("\<c-left>", 'tx')
2786 call assert_equal(13, col('.'))
2787 call feedkeys("\<s-left>", 'tx')
2788 call assert_equal(19, col('.'))
2789 call feedkeys("<<", 'tx')
2790 call assert_equal(' abcde fghij klmnopq',getline(1))
2791 call feedkeys(">>", 'tx')
2792 call assert_equal('abcde fghij klmnopq',getline(1))
2793
2794 " cleanup
2795 set norl
2796 bw!
2797endfunc
2798
Bram Moolenaarb1e04fc2017-03-29 13:08:35 +02002799func Test_normal54_Ctrl_bsl()
2800 new
2801 call setline(1, 'abcdefghijklmn')
2802 exe "norm! df\<c-\>\<c-n>"
2803 call assert_equal(['abcdefghijklmn'], getline(1,'$'))
2804 exe "norm! df\<c-\>\<c-g>"
2805 call assert_equal(['abcdefghijklmn'], getline(1,'$'))
2806 exe "norm! df\<c-\>m"
2807 call assert_equal(['abcdefghijklmn'], getline(1,'$'))
Bram Moolenaar30276f22019-01-24 17:59:39 +01002808
Bram Moolenaarb1e04fc2017-03-29 13:08:35 +02002809 call setline(2, 'abcdefghijklmnāf')
2810 norm! 2gg0
2811 exe "norm! df\<Char-0x101>"
2812 call assert_equal(['abcdefghijklmn', 'f'], getline(1,'$'))
2813 norm! 1gg0
2814 exe "norm! df\<esc>"
2815 call assert_equal(['abcdefghijklmn', 'f'], getline(1,'$'))
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002816
Bram Moolenaarb1e04fc2017-03-29 13:08:35 +02002817 " clean up
2818 bw!
2819endfunc
2820
2821func Test_normal_large_count()
2822 " This may fail with 32bit long, how do we detect that?
2823 new
2824 normal o
2825 normal 6666666666dL
2826 bwipe!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002827endfunc
Bram Moolenaarbf3d5802017-03-29 19:48:11 +02002828
2829func Test_delete_until_paragraph()
Bram Moolenaarbf3d5802017-03-29 19:48:11 +02002830 new
2831 normal grádv}
2832 call assert_equal('á', getline(1))
2833 normal grád}
2834 call assert_equal('', getline(1))
2835 bwipe!
2836endfunc
Bram Moolenaarfb094e12017-11-05 20:59:28 +01002837
2838" Test for the gr (virtual replace) command
2839" Test for the bug fixed by 7.4.387
2840func Test_gr_command()
2841 enew!
2842 let save_cpo = &cpo
2843 call append(0, ['First line', 'Second line', 'Third line'])
2844 exe "normal i\<C-G>u"
2845 call cursor(2, 1)
2846 set cpo-=X
2847 normal 4gro
2848 call assert_equal('oooond line', getline(2))
2849 undo
2850 set cpo+=X
2851 normal 4gro
2852 call assert_equal('ooooecond line', getline(2))
2853 let &cpo = save_cpo
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002854 normal! ggvegrx
2855 call assert_equal('xxxxx line', getline(1))
2856 exe "normal! gggr\<C-V>122"
2857 call assert_equal('zxxxx line', getline(1))
2858 set virtualedit=all
2859 normal! 15|grl
2860 call assert_equal('zxxxx line l', getline(1))
2861 set virtualedit&
2862 set nomodifiable
2863 call assert_fails('normal! grx', 'E21:')
2864 call assert_fails('normal! gRx', 'E21:')
2865 set modifiable&
Bram Moolenaarfb094e12017-11-05 20:59:28 +01002866 enew!
2867endfunc
2868
2869" When splitting a window the changelist position is wrong.
2870" Test the changelist position after splitting a window.
2871" Test for the bug fixed by 7.4.386
2872func Test_changelist()
2873 let save_ul = &ul
2874 enew!
2875 call append('$', ['1', '2'])
2876 exe "normal i\<C-G>u"
2877 exe "normal Gkylpa\<C-G>u"
2878 set ul=100
2879 exe "normal Gylpa\<C-G>u"
2880 set ul=100
2881 normal gg
2882 vsplit
2883 normal g;
2884 call assert_equal([3, 2], [line('.'), col('.')])
2885 normal g;
2886 call assert_equal([2, 2], [line('.'), col('.')])
2887 call assert_fails('normal g;', 'E662:')
Bram Moolenaar1671f442020-03-10 07:48:13 +01002888 new
2889 call assert_fails('normal g;', 'E664:')
Bram Moolenaarfb094e12017-11-05 20:59:28 +01002890 %bwipe!
2891 let &ul = save_ul
2892endfunc
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002893
2894func Test_nv_hat_count()
2895 %bwipeout!
2896 let l:nr = bufnr('%') + 1
Bram Moolenaare2e40752020-09-04 21:18:46 +02002897 call assert_fails(':execute "normal! ' . l:nr . '\<C-^>"', 'E92:')
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002898
2899 edit Xfoo
2900 let l:foo_nr = bufnr('Xfoo')
2901
2902 edit Xbar
2903 let l:bar_nr = bufnr('Xbar')
2904
2905 " Make sure we are not just using the alternate file.
2906 edit Xbaz
2907
2908 call feedkeys(l:foo_nr . "\<C-^>", 'tx')
2909 call assert_equal('Xfoo', fnamemodify(bufname('%'), ':t'))
2910
2911 call feedkeys(l:bar_nr . "\<C-^>", 'tx')
2912 call assert_equal('Xbar', fnamemodify(bufname('%'), ':t'))
2913
2914 %bwipeout!
2915endfunc
Bram Moolenaara84a3dd2019-03-25 22:21:24 +01002916
2917func Test_message_when_using_ctrl_c()
Bram Moolenaar553e5a52019-03-25 23:16:34 +01002918 " Make sure no buffers are changed.
2919 %bwipe!
2920
Bram Moolenaara84a3dd2019-03-25 22:21:24 +01002921 exe "normal \<C-C>"
2922 call assert_match("Type :qa and press <Enter> to exit Vim", Screenline(&lines))
Bram Moolenaar553e5a52019-03-25 23:16:34 +01002923
Bram Moolenaara84a3dd2019-03-25 22:21:24 +01002924 new
2925 cal setline(1, 'hi!')
2926 exe "normal \<C-C>"
2927 call assert_match("Type :qa! and press <Enter> to abandon all changes and exit Vim", Screenline(&lines))
Bram Moolenaar553e5a52019-03-25 23:16:34 +01002928
Bram Moolenaara84a3dd2019-03-25 22:21:24 +01002929 bwipe!
2930endfunc
Bram Moolenaarc6b37db2019-04-27 18:00:34 +02002931
2932" Test for '[m', ']m', '[M' and ']M'
2933" Jumping to beginning and end of methods in Java-like languages
2934func Test_java_motion()
2935 new
Bram Moolenaar1671f442020-03-10 07:48:13 +01002936 call assert_beeps('normal! [m')
2937 call assert_beeps('normal! ]m')
2938 call assert_beeps('normal! [M')
2939 call assert_beeps('normal! ]M')
Bram Moolenaar8a9bc952020-10-02 18:48:07 +02002940 let lines =<< trim [CODE]
2941 Piece of Java
2942 {
2943 tt m1 {
2944 t1;
2945 } e1
Bram Moolenaarc6b37db2019-04-27 18:00:34 +02002946
Bram Moolenaar8a9bc952020-10-02 18:48:07 +02002947 tt m2 {
2948 t2;
2949 } e2
Bram Moolenaarc6b37db2019-04-27 18:00:34 +02002950
Bram Moolenaar8a9bc952020-10-02 18:48:07 +02002951 tt m3 {
2952 if (x)
2953 {
2954 t3;
2955 }
2956 } e3
2957 }
2958 [CODE]
2959 call setline(1, lines)
Bram Moolenaarc6b37db2019-04-27 18:00:34 +02002960
2961 normal gg
2962
2963 normal 2]maA
2964 call assert_equal("\ttt m1 {A", getline('.'))
2965 call assert_equal([3, 9, 16], [line('.'), col('.'), virtcol('.')])
2966
2967 normal j]maB
2968 call assert_equal("\ttt m2 {B", getline('.'))
2969 call assert_equal([7, 9, 16], [line('.'), col('.'), virtcol('.')])
2970
2971 normal ]maC
2972 call assert_equal("\ttt m3 {C", getline('.'))
2973 call assert_equal([11, 9, 16], [line('.'), col('.'), virtcol('.')])
2974
2975 normal [maD
2976 call assert_equal("\ttt m3 {DC", getline('.'))
2977 call assert_equal([11, 9, 16], [line('.'), col('.'), virtcol('.')])
2978
2979 normal k2[maE
2980 call assert_equal("\ttt m1 {EA", getline('.'))
2981 call assert_equal([3, 9, 16], [line('.'), col('.'), virtcol('.')])
2982
2983 normal 3[maF
2984 call assert_equal("{F", getline('.'))
2985 call assert_equal([2, 2, 2], [line('.'), col('.'), virtcol('.')])
2986
2987 normal ]MaG
2988 call assert_equal("\t}G e1", getline('.'))
2989 call assert_equal([5, 3, 10], [line('.'), col('.'), virtcol('.')])
2990
2991 normal j2]MaH
2992 call assert_equal("\t}H e3", getline('.'))
2993 call assert_equal([16, 3, 10], [line('.'), col('.'), virtcol('.')])
2994
2995 normal ]M]M
2996 normal aI
2997 call assert_equal("}I", getline('.'))
2998 call assert_equal([17, 2, 2], [line('.'), col('.'), virtcol('.')])
2999
3000 normal 2[MaJ
3001 call assert_equal("\t}JH e3", getline('.'))
3002 call assert_equal([16, 3, 10], [line('.'), col('.'), virtcol('.')])
3003
3004 normal k[MaK
3005 call assert_equal("\t}K e2", getline('.'))
3006 call assert_equal([9, 3, 10], [line('.'), col('.'), virtcol('.')])
3007
3008 normal 3[MaL
3009 call assert_equal("{LF", getline('.'))
3010 call assert_equal([2, 2, 2], [line('.'), col('.'), virtcol('.')])
3011
Bram Moolenaar8a9bc952020-10-02 18:48:07 +02003012 call cursor(2, 1)
3013 call assert_beeps('norm! 5]m')
3014
3015 " jumping to a method in a fold should open the fold
3016 6,10fold
3017 call feedkeys("gg3]m", 'xt')
3018 call assert_equal([7, 8, 15], [line('.'), col('.'), virtcol('.')])
3019 call assert_equal(-1, foldclosedend(7))
3020
Bram Moolenaarc6b37db2019-04-27 18:00:34 +02003021 close!
3022endfunc
Bram Moolenaard5c82342019-07-27 18:44:57 +02003023
Bram Moolenaar004a6782020-04-11 17:09:31 +02003024" Tests for g cmds
Bram Moolenaar1671f442020-03-10 07:48:13 +01003025func Test_normal_gdollar_cmd()
Bram Moolenaar004a6782020-04-11 17:09:31 +02003026 CheckFeature jumplist
Bram Moolenaard5c82342019-07-27 18:44:57 +02003027 call Setup_NewWindow()
3028 " Make long lines that will wrap
3029 %s/$/\=repeat(' foobar', 10)/
3030 20vsp
3031 set wrap
3032 " Test for g$ with count
3033 norm! gg
3034 norm! 0vg$y
3035 call assert_equal(20, col("'>"))
3036 call assert_equal('1 foobar foobar foob', getreg(0))
3037 norm! gg
3038 norm! 0v4g$y
3039 call assert_equal(72, col("'>"))
3040 call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.."\n", getreg(0))
3041 norm! gg
3042 norm! 0v6g$y
3043 call assert_equal(40, col("'>"))
3044 call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
3045 \ '2 foobar foobar foobar foobar foobar foo', getreg(0))
3046 set nowrap
3047 " clean up
3048 norm! gg
3049 norm! 0vg$y
3050 call assert_equal(20, col("'>"))
3051 call assert_equal('1 foobar foobar foob', getreg(0))
3052 norm! gg
3053 norm! 0v4g$y
3054 call assert_equal(20, col("'>"))
3055 call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
3056 \ '2 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
3057 \ '3 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
3058 \ '4 foobar foobar foob', getreg(0))
3059 norm! gg
3060 norm! 0v6g$y
3061 call assert_equal(20, col("'>"))
3062 call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
3063 \ '2 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
3064 \ '3 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
3065 \ '4 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
3066 \ '5 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
3067 \ '6 foobar foobar foob', getreg(0))
3068 " Move to last line, also down movement is not possible, should still move
3069 " the cursor to the last visible char
3070 norm! G
3071 norm! 0v6g$y
3072 call assert_equal(20, col("'>"))
3073 call assert_equal('100 foobar foobar fo', getreg(0))
3074 bw!
3075endfunc
Bram Moolenaar03ac52f2019-09-24 22:47:46 +02003076
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01003077func Test_normal_gk_gj()
Bram Moolenaar03ac52f2019-09-24 22:47:46 +02003078 " needs 80 column new window
3079 new
3080 vert 80new
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01003081 call assert_beeps('normal gk')
Bram Moolenaar03ac52f2019-09-24 22:47:46 +02003082 put =[repeat('x',90)..' {{{1', 'x {{{1']
3083 norm! gk
3084 " In a 80 column wide terminal the window will be only 78 char
3085 " (because Vim will leave space for the other window),
3086 " but if the terminal is larger, it will be 80 chars, so verify the
3087 " cursor column correctly.
3088 call assert_equal(winwidth(0)+1, col('.'))
3089 call assert_equal(winwidth(0)+1, virtcol('.'))
3090 norm! j
3091 call assert_equal(6, col('.'))
3092 call assert_equal(6, virtcol('.'))
3093 norm! gk
3094 call assert_equal(95, col('.'))
3095 call assert_equal(95, virtcol('.'))
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01003096 %bw!
Bram Moolenaarceba3dd2019-10-12 16:12:54 +02003097
3098 " needs 80 column new window
3099 new
3100 vert 80new
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01003101 call assert_beeps('normal gj')
Bram Moolenaarceba3dd2019-10-12 16:12:54 +02003102 set number
3103 set numberwidth=10
3104 set cpoptions+=n
3105 put =[repeat('0',90), repeat('1',90)]
3106 norm! 075l
3107 call assert_equal(76, col('.'))
3108 norm! gk
3109 call assert_equal(1, col('.'))
3110 norm! gk
3111 call assert_equal(76, col('.'))
3112 norm! gk
3113 call assert_equal(1, col('.'))
3114 norm! gj
3115 call assert_equal(76, col('.'))
3116 norm! gj
3117 call assert_equal(1, col('.'))
3118 norm! gj
3119 call assert_equal(76, col('.'))
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01003120 " When 'nowrap' is set, gk and gj behave like k and j
3121 set nowrap
3122 normal! gk
3123 call assert_equal([2, 76], [line('.'), col('.')])
3124 normal! gj
3125 call assert_equal([3, 76], [line('.'), col('.')])
3126 %bw!
3127 set cpoptions& number& numberwidth& wrap&
Bram Moolenaar03ac52f2019-09-24 22:47:46 +02003128endfunc
Bram Moolenaarf0cee192020-02-16 13:33:56 +01003129
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01003130" Test for using : to run a multi-line Ex command in operator pending mode
3131func Test_normal_yank_with_excmd()
3132 new
3133 call setline(1, ['foo', 'bar', 'baz'])
3134 let @a = ''
3135 call feedkeys("\"ay:if v:true\<CR>normal l\<CR>endif\<CR>", 'xt')
3136 call assert_equal('f', @a)
3137 close!
3138endfunc
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01003139
3140" Test for supplying a count to a normal-mode command across a cursorhold call
3141func Test_normal_cursorhold_with_count()
3142 func s:cHold()
3143 let g:cHold_Called += 1
3144 endfunc
3145 new
3146 augroup normalcHoldTest
3147 au!
3148 au CursorHold <buffer> call s:cHold()
3149 augroup END
3150 let g:cHold_Called = 0
3151 call feedkeys("3\<CursorHold>2ix", 'xt')
3152 call assert_equal(1, g:cHold_Called)
3153 call assert_equal(repeat('x', 32), getline(1))
3154 augroup normalcHoldTest
3155 au!
3156 augroup END
3157 au! normalcHoldTest
3158 close!
3159 delfunc s:cHold
3160endfunc
3161
3162" Test for using a count and a command with CTRL-W
3163func Test_wincmd_with_count()
3164 call feedkeys("\<C-W>12n", 'xt')
3165 call assert_equal(12, winheight(0))
3166endfunc
3167
3168" Test for 'b', 'B' 'ge' and 'gE' commands
Bram Moolenaar1671f442020-03-10 07:48:13 +01003169func Test_horiz_motion()
3170 new
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01003171 normal! gg
3172 call assert_beeps('normal! b')
3173 call assert_beeps('normal! B')
3174 call assert_beeps('normal! gE')
3175 call assert_beeps('normal! ge')
Bram Moolenaar1671f442020-03-10 07:48:13 +01003176 " <S-Backspace> moves one word left and <C-Backspace> moves one WORD left
3177 call setline(1, 'one ,two ,three')
3178 exe "normal! $\<S-BS>"
3179 call assert_equal(11, col('.'))
3180 exe "normal! $\<C-BS>"
3181 call assert_equal(10, col('.'))
3182 close!
3183endfunc
3184
3185" Test for using a : command in operator pending mode
3186func Test_normal_colon_op()
3187 new
3188 call setline(1, ['one', 'two'])
3189 call assert_beeps("normal! Gc:d\<CR>")
3190 close!
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01003191endfunc
3192
Bram Moolenaar004a6782020-04-11 17:09:31 +02003193" Test for d and D commands
3194func Test_normal_delete_cmd()
3195 new
3196 " D in an empty line
3197 call setline(1, '')
3198 normal D
3199 call assert_equal('', getline(1))
3200 " D in an empty line in virtualedit mode
3201 set virtualedit=all
3202 normal D
3203 call assert_equal('', getline(1))
3204 set virtualedit&
3205 " delete to a readonly register
3206 call setline(1, ['abcd'])
3207 call assert_beeps('normal ":d2l')
3208 close!
3209endfunc
3210
Bram Moolenaar8a9bc952020-10-02 18:48:07 +02003211" Test for deleting or changing characters across lines with 'whichwrap'
3212" containing 's'. Should count <EOL> as one character.
3213func Test_normal_op_across_lines()
3214 new
3215 set whichwrap&
3216 call setline(1, ['one two', 'three four'])
3217 exe "norm! $3d\<Space>"
3218 call assert_equal(['one twhree four'], getline(1, '$'))
3219
3220 call setline(1, ['one two', 'three four'])
3221 exe "norm! $3c\<Space>x"
3222 call assert_equal(['one twxhree four'], getline(1, '$'))
3223
3224 set whichwrap+=l
3225 call setline(1, ['one two', 'three four'])
3226 exe "norm! $3x"
3227 call assert_equal(['one twhree four'], getline(1, '$'))
3228 close!
3229 set whichwrap&
3230endfunc
3231
Bram Moolenaar224a5f12020-04-28 20:29:07 +02003232" Test for 'w' and 'b' commands
3233func Test_normal_word_move()
3234 new
3235 call setline(1, ['foo bar a', '', 'foo bar b'])
3236 " copy a single character word at the end of a line
3237 normal 1G$yw
3238 call assert_equal('a', @")
3239 " copy a single character word at the end of a file
3240 normal G$yw
3241 call assert_equal('b', @")
3242 " check for a word movement handling an empty line properly
3243 normal 1G$vwy
3244 call assert_equal("a\n\n", @")
3245
3246 " copy using 'b' command
3247 %d
3248 " non-empty blank line at the start of file
3249 call setline(1, [' ', 'foo bar'])
3250 normal 2Gyb
3251 call assert_equal(" \n", @")
3252 " try to copy backwards from the start of the file
3253 call setline(1, ['one two', 'foo bar'])
3254 call assert_beeps('normal ggyb')
3255 " 'b' command should stop at an empty line
3256 call setline(1, ['one two', '', 'foo bar'])
3257 normal 3Gyb
3258 call assert_equal("\n", @")
3259 normal 3Gy2b
3260 call assert_equal("two\n", @")
3261 " 'b' command should not stop at a non-empty blank line
3262 call setline(1, ['one two', ' ', 'foo bar'])
3263 normal 3Gyb
3264 call assert_equal("two\n ", @")
3265
3266 close!
3267endfunc
3268
Bram Moolenaarbdd2c292020-06-22 21:34:30 +02003269" Test for 'scrolloff' with a long line that doesn't fit in the screen
3270func Test_normal_scroloff()
3271 10new
3272 80vnew
3273 call setline(1, repeat('a', 1000))
3274 set scrolloff=10
3275 normal gg10gj
3276 call assert_equal(8, winline())
3277 normal 10gj
3278 call assert_equal(10, winline())
3279 normal 10gk
3280 call assert_equal(3, winline())
3281 set scrolloff&
3282 close!
3283endfunc
3284
3285" Test for vertical scrolling with CTRL-F and CTRL-B with a long line
3286func Test_normal_vert_scroll_longline()
3287 10new
3288 80vnew
3289 call setline(1, range(1, 10))
3290 call append(5, repeat('a', 1000))
3291 exe "normal gg\<C-F>"
3292 call assert_equal(6, line('.'))
3293 exe "normal \<C-F>\<C-F>"
3294 call assert_equal(11, line('.'))
3295 call assert_equal(1, winline())
3296 exe "normal \<C-B>"
3297 call assert_equal(10, line('.'))
3298 call assert_equal(3, winline())
3299 exe "normal \<C-B>\<C-B>"
3300 call assert_equal(5, line('.'))
3301 call assert_equal(5, winline())
3302 close!
3303endfunc
3304
Bram Moolenaar8a9bc952020-10-02 18:48:07 +02003305" Test for jumping in a file using %
3306func Test_normal_percent_jump()
3307 new
3308 call setline(1, range(1, 100))
3309
3310 " jumping to a folded line should open the fold
3311 25,75fold
3312 call feedkeys('50%', 'xt')
3313 call assert_equal(50, line('.'))
3314 call assert_equal(-1, foldclosedend(50))
3315 close!
3316endfunc
3317
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01003318" vim: shiftwidth=2 sts=2 expandtab