Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1 | " Test for edit functions |
Bram Moolenaar | 215ba3b | 2019-11-06 15:07:07 +0100 | [diff] [blame] | 2 | |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 3 | if exists("+t_kD") |
| 4 | let &t_kD="[3;*~" |
| 5 | endif |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 6 | |
Bram Moolenaar | 215ba3b | 2019-11-06 15:07:07 +0100 | [diff] [blame] | 7 | source check.vim |
| 8 | |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 9 | " Needed for testing basic rightleft: Test_edit_rightleft |
| 10 | source view_util.vim |
| 11 | |
| 12 | " Needs to come first until the bug in getchar() is |
| 13 | " fixed: https://groups.google.com/d/msg/vim_dev/fXL9yme4H4c/bOR-U6_bAQAJ |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 14 | func Test_edit_00b() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 15 | new |
| 16 | call setline(1, ['abc ']) |
| 17 | inoreabbr <buffer> h here some more |
| 18 | call cursor(1, 4) |
| 19 | " <c-l> expands the abbreviation and ends insertmode |
| 20 | call feedkeys(":set im\<cr> h\<c-l>:set noim\<cr>", 'tix') |
| 21 | call assert_equal(['abc here some more '], getline(1,'$')) |
| 22 | iunabbr <buffer> h |
| 23 | bw! |
| 24 | endfunc |
| 25 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 26 | func Test_edit_01() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 27 | " set for Travis CI? |
| 28 | " set nocp noesckeys |
| 29 | new |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 30 | " 1) empty buffer |
| 31 | call assert_equal([''], getline(1,'$')) |
| 32 | " 2) delete in an empty line |
| 33 | call feedkeys("i\<del>\<esc>", 'tnix') |
| 34 | call assert_equal([''], getline(1,'$')) |
| 35 | %d |
| 36 | " 3) delete one character |
| 37 | call setline(1, 'a') |
| 38 | call feedkeys("i\<del>\<esc>", 'tnix') |
| 39 | call assert_equal([''], getline(1,'$')) |
| 40 | %d |
| 41 | " 4) delete a multibyte character |
Bram Moolenaar | 30276f2 | 2019-01-24 17:59:39 +0100 | [diff] [blame] | 42 | call setline(1, "\u0401") |
| 43 | call feedkeys("i\<del>\<esc>", 'tnix') |
| 44 | call assert_equal([''], getline(1,'$')) |
| 45 | %d |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 46 | " 5.1) delete linebreak with 'bs' option containing eol |
| 47 | let _bs=&bs |
| 48 | set bs=eol |
| 49 | call setline(1, ["abc def", "ghi jkl"]) |
| 50 | call cursor(1, 1) |
| 51 | call feedkeys("A\<del>\<esc>", 'tnix') |
| 52 | call assert_equal(['abc defghi jkl'], getline(1, 2)) |
| 53 | %d |
| 54 | " 5.2) delete linebreak with backspace option w/out eol |
| 55 | set bs= |
| 56 | call setline(1, ["abc def", "ghi jkl"]) |
| 57 | call cursor(1, 1) |
| 58 | call feedkeys("A\<del>\<esc>", 'tnix') |
| 59 | call assert_equal(["abc def", "ghi jkl"], getline(1, 2)) |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 60 | let &bs=_bs |
| 61 | bw! |
| 62 | endfunc |
| 63 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 64 | func Test_edit_02() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 65 | " Change cursor position in InsertCharPre command |
| 66 | new |
| 67 | call setline(1, 'abc') |
| 68 | call cursor(1, 1) |
| 69 | fu! DoIt(...) |
| 70 | call cursor(1, 4) |
| 71 | if len(a:000) |
| 72 | let v:char=a:1 |
| 73 | endif |
| 74 | endfu |
| 75 | au InsertCharPre <buffer> :call DoIt('y') |
| 76 | call feedkeys("ix\<esc>", 'tnix') |
| 77 | call assert_equal(['abcy'], getline(1, '$')) |
| 78 | " Setting <Enter> in InsertCharPre |
| 79 | au! InsertCharPre <buffer> :call DoIt("\n") |
| 80 | call setline(1, 'abc') |
| 81 | call cursor(1, 1) |
| 82 | call feedkeys("ix\<esc>", 'tnix') |
| 83 | call assert_equal(['abc', ''], getline(1, '$')) |
| 84 | %d |
| 85 | au! InsertCharPre |
| 86 | " Change cursor position in InsertEnter command |
| 87 | " 1) when setting v:char, keeps changed cursor position |
| 88 | au! InsertEnter <buffer> :call DoIt('y') |
| 89 | call setline(1, 'abc') |
| 90 | call cursor(1, 1) |
| 91 | call feedkeys("ix\<esc>", 'tnix') |
| 92 | call assert_equal(['abxc'], getline(1, '$')) |
| 93 | " 2) when not setting v:char, restores changed cursor position |
| 94 | au! InsertEnter <buffer> :call DoIt() |
| 95 | call setline(1, 'abc') |
| 96 | call cursor(1, 1) |
| 97 | call feedkeys("ix\<esc>", 'tnix') |
| 98 | call assert_equal(['xabc'], getline(1, '$')) |
| 99 | au! InsertEnter |
| 100 | delfu DoIt |
| 101 | bw! |
| 102 | endfunc |
| 103 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 104 | func Test_edit_03() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 105 | " Change cursor after <c-o> command to end of line |
| 106 | new |
| 107 | call setline(1, 'abc') |
| 108 | call cursor(1, 1) |
| 109 | call feedkeys("i\<c-o>$y\<esc>", 'tnix') |
| 110 | call assert_equal(['abcy'], getline(1, '$')) |
| 111 | %d |
| 112 | call setline(1, 'abc') |
| 113 | call cursor(1, 1) |
| 114 | call feedkeys("i\<c-o>80|y\<esc>", 'tnix') |
| 115 | call assert_equal(['abcy'], getline(1, '$')) |
| 116 | %d |
| 117 | call setline(1, 'abc') |
| 118 | call feedkeys("Ad\<c-o>:s/$/efg/\<cr>hij", 'tnix') |
| 119 | call assert_equal(['hijabcdefg'], getline(1, '$')) |
| 120 | bw! |
| 121 | endfunc |
| 122 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 123 | func Test_edit_04() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 124 | " test for :stopinsert |
| 125 | new |
| 126 | call setline(1, 'abc') |
| 127 | call cursor(1, 1) |
| 128 | call feedkeys("i\<c-o>:stopinsert\<cr>$", 'tnix') |
| 129 | call feedkeys("aX\<esc>", 'tnix') |
| 130 | call assert_equal(['abcX'], getline(1, '$')) |
| 131 | %d |
| 132 | bw! |
| 133 | endfunc |
| 134 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 135 | func Test_edit_05() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 136 | " test for folds being opened |
| 137 | new |
| 138 | call setline(1, ['abcX', 'abcX', 'zzzZ']) |
| 139 | call cursor(1, 1) |
| 140 | set foldmethod=manual foldopen+=insert |
| 141 | " create fold for those two lines |
| 142 | norm! Vjzf |
| 143 | call feedkeys("$ay\<esc>", 'tnix') |
| 144 | call assert_equal(['abcXy', 'abcX', 'zzzZ'], getline(1, '$')) |
| 145 | %d |
| 146 | call setline(1, ['abcX', 'abcX', 'zzzZ']) |
| 147 | call cursor(1, 1) |
| 148 | set foldmethod=manual foldopen-=insert |
| 149 | " create fold for those two lines |
| 150 | norm! Vjzf |
| 151 | call feedkeys("$ay\<esc>", 'tnix') |
| 152 | call assert_equal(['abcXy', 'abcX', 'zzzZ'], getline(1, '$')) |
| 153 | %d |
| 154 | bw! |
| 155 | endfunc |
| 156 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 157 | func Test_edit_06() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 158 | " Test in diff mode |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 159 | CheckFeature diff |
| 160 | CheckExecutable diff |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 161 | new |
| 162 | call setline(1, ['abc', 'xxx', 'yyy']) |
| 163 | vnew |
| 164 | call setline(1, ['abc', 'zzz', 'xxx', 'yyy']) |
| 165 | wincmd p |
| 166 | diffthis |
| 167 | wincmd p |
| 168 | diffthis |
| 169 | wincmd p |
| 170 | call cursor(2, 1) |
| 171 | norm! zt |
| 172 | call feedkeys("Ozzz\<esc>", 'tnix') |
| 173 | call assert_equal(['abc', 'zzz', 'xxx', 'yyy'], getline(1,'$')) |
| 174 | bw! |
| 175 | bw! |
| 176 | endfunc |
| 177 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 178 | func Test_edit_07() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 179 | " 1) Test with completion <c-l> when popupmenu is visible |
| 180 | new |
| 181 | call setline(1, 'J') |
| 182 | |
| 183 | func! ListMonths() |
| 184 | call complete(col('.')-1, ['January', 'February', 'March', |
| 185 | \ 'April', 'May', 'June', 'July', 'August', 'September', |
| 186 | \ 'October', 'November', 'December']) |
| 187 | return '' |
| 188 | endfunc |
| 189 | inoremap <buffer> <F5> <C-R>=ListMonths()<CR> |
| 190 | |
| 191 | call feedkeys("A\<f5>\<c-p>". repeat("\<down>", 6)."\<c-l>\<down>\<c-l>\<cr>", 'tx') |
| 192 | call assert_equal(['July'], getline(1,'$')) |
| 193 | " 1) Test completion when InsertCharPre kicks in |
| 194 | %d |
| 195 | call setline(1, 'J') |
| 196 | fu! DoIt() |
| 197 | if v:char=='u' |
| 198 | let v:char='an' |
| 199 | endif |
| 200 | endfu |
| 201 | au InsertCharPre <buffer> :call DoIt() |
| 202 | call feedkeys("A\<f5>\<c-p>u\<cr>\<c-l>\<cr>", 'tx') |
Bram Moolenaar | 4c313b1 | 2019-08-24 22:58:31 +0200 | [diff] [blame] | 203 | call assert_equal(["Jan\<c-l>",''], 1->getline('$')) |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 204 | %d |
| 205 | call setline(1, 'J') |
| 206 | call feedkeys("A\<f5>\<c-p>u\<down>\<c-l>\<cr>", 'tx') |
Bram Moolenaar | 4c313b1 | 2019-08-24 22:58:31 +0200 | [diff] [blame] | 207 | call assert_equal(["January"], 1->getline('$')) |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 208 | |
| 209 | delfu ListMonths |
| 210 | delfu DoIt |
| 211 | iunmap <buffer> <f5> |
| 212 | bw! |
| 213 | endfunc |
| 214 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 215 | func Test_edit_08() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 216 | " reset insertmode from i_ctrl-r_= |
Bram Moolenaar | 2a45d64 | 2017-10-27 01:35:00 +0200 | [diff] [blame] | 217 | let g:bufnr = bufnr('%') |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 218 | new |
| 219 | call setline(1, ['abc']) |
| 220 | call cursor(1, 4) |
Bram Moolenaar | 2a45d64 | 2017-10-27 01:35:00 +0200 | [diff] [blame] | 221 | call feedkeys(":set im\<cr>ZZZ\<c-r>=setbufvar(g:bufnr,'&im', 0)\<cr>",'tnix') |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 222 | call assert_equal(['abZZZc'], getline(1,'$')) |
| 223 | call assert_equal([0, 1, 1, 0], getpos('.')) |
| 224 | call assert_false(0, '&im') |
| 225 | bw! |
Bram Moolenaar | 2a45d64 | 2017-10-27 01:35:00 +0200 | [diff] [blame] | 226 | unlet g:bufnr |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 227 | endfunc |
| 228 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 229 | func Test_edit_09() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 230 | " test i_CTRL-\ combinations |
| 231 | new |
| 232 | call setline(1, ['abc', 'def', 'ghi']) |
| 233 | call cursor(1, 1) |
| 234 | " 1) CTRL-\ CTLR-N |
| 235 | call feedkeys(":set im\<cr>\<c-\>\<c-n>ccABC\<c-l>", 'txin') |
| 236 | call assert_equal(['ABC', 'def', 'ghi'], getline(1,'$')) |
| 237 | call setline(1, ['ABC', 'def', 'ghi']) |
| 238 | " 2) CTRL-\ CTLR-G |
| 239 | call feedkeys("j0\<c-\>\<c-g>ZZZ\<cr>\<c-l>", 'txin') |
| 240 | call assert_equal(['ABC', 'ZZZ', 'def', 'ghi'], getline(1,'$')) |
| 241 | call feedkeys("I\<c-\>\<c-g>YYY\<c-l>", 'txin') |
| 242 | call assert_equal(['ABC', 'ZZZ', 'YYYdef', 'ghi'], getline(1,'$')) |
| 243 | set noinsertmode |
| 244 | " 3) CTRL-\ CTRL-O |
| 245 | call setline(1, ['ABC', 'ZZZ', 'def', 'ghi']) |
| 246 | call cursor(1, 1) |
| 247 | call feedkeys("A\<c-o>ix", 'txin') |
| 248 | call assert_equal(['ABxC', 'ZZZ', 'def', 'ghi'], getline(1,'$')) |
| 249 | call feedkeys("A\<c-\>\<c-o>ix", 'txin') |
| 250 | call assert_equal(['ABxCx', 'ZZZ', 'def', 'ghi'], getline(1,'$')) |
| 251 | " 4) CTRL-\ a (should be inserted literally, not special after <c-\> |
| 252 | call setline(1, ['ABC', 'ZZZ', 'def', 'ghi']) |
| 253 | call cursor(1, 1) |
| 254 | call feedkeys("A\<c-\>a", 'txin') |
| 255 | call assert_equal(["ABC\<c-\>a", 'ZZZ', 'def', 'ghi'], getline(1, '$')) |
| 256 | bw! |
| 257 | endfunc |
| 258 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 259 | func Test_edit_11() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 260 | " Test that indenting kicks in |
| 261 | new |
| 262 | set cindent |
| 263 | call setline(1, ['{', '', '']) |
| 264 | call cursor(2, 1) |
| 265 | call feedkeys("i\<c-f>int c;\<esc>", 'tnix') |
| 266 | call cursor(3, 1) |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 267 | call feedkeys("\<Insert>/* comment */", 'tnix') |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 268 | call assert_equal(['{', "\<tab>int c;", "/* comment */"], getline(1, '$')) |
| 269 | " added changed cindentkeys slightly |
| 270 | set cindent cinkeys+=*/ |
| 271 | call setline(1, ['{', '', '']) |
| 272 | call cursor(2, 1) |
| 273 | call feedkeys("i\<c-f>int c;\<esc>", 'tnix') |
| 274 | call cursor(3, 1) |
| 275 | call feedkeys("i/* comment */", 'tnix') |
| 276 | call assert_equal(['{', "\<tab>int c;", "\<tab>/* comment */"], getline(1, '$')) |
| 277 | set cindent cinkeys+==end |
| 278 | call feedkeys("oend\<cr>\<esc>", 'tnix') |
| 279 | call assert_equal(['{', "\<tab>int c;", "\<tab>/* comment */", "\tend", ''], getline(1, '$')) |
| 280 | set cinkeys-==end |
| 281 | %d |
| 282 | " Use indentexpr instead of cindenting |
| 283 | func! Do_Indent() |
| 284 | if v:lnum == 3 |
| 285 | return 3*shiftwidth() |
| 286 | else |
| 287 | return 2*shiftwidth() |
| 288 | endif |
| 289 | endfunc |
| 290 | setl indentexpr=Do_Indent() indentkeys+=*/ |
| 291 | call setline(1, ['{', '', '']) |
| 292 | call cursor(2, 1) |
| 293 | call feedkeys("i\<c-f>int c;\<esc>", 'tnix') |
| 294 | call cursor(3, 1) |
| 295 | call feedkeys("i/* comment */", 'tnix') |
| 296 | call assert_equal(['{', "\<tab>\<tab>int c;", "\<tab>\<tab>\<tab>/* comment */"], getline(1, '$')) |
| 297 | set cinkeys&vim indentkeys&vim |
| 298 | set nocindent indentexpr= |
| 299 | delfu Do_Indent |
| 300 | bw! |
| 301 | endfunc |
| 302 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 303 | func Test_edit_11_indentexpr() |
Bram Moolenaar | 1b38344 | 2017-09-26 20:04:54 +0200 | [diff] [blame] | 304 | " Test that indenting kicks in |
| 305 | new |
| 306 | " Use indentexpr instead of cindenting |
| 307 | func! Do_Indent() |
| 308 | let pline=prevnonblank(v:lnum) |
| 309 | if empty(getline(v:lnum)) |
| 310 | if getline(pline) =~ 'if\|then' |
| 311 | return shiftwidth() |
| 312 | else |
| 313 | return 0 |
| 314 | endif |
| 315 | else |
| 316 | return 0 |
| 317 | endif |
| 318 | endfunc |
| 319 | setl indentexpr=Do_Indent() indentkeys+=0=then,0=fi |
| 320 | call setline(1, ['if [ $this ]']) |
| 321 | call cursor(1, 1) |
| 322 | call feedkeys("othen\<cr>that\<cr>fi", 'tnix') |
| 323 | call assert_equal(['if [ $this ]', "then", "\<tab>that", "fi"], getline(1, '$')) |
| 324 | set cinkeys&vim indentkeys&vim |
| 325 | set nocindent indentexpr= |
| 326 | delfu Do_Indent |
Yegappan Lakshmanan | 8bb65f2 | 2021-12-26 10:51:39 +0000 | [diff] [blame] | 327 | |
| 328 | " Using a script-local function |
| 329 | func s:NewIndentExpr() |
| 330 | endfunc |
| 331 | set indentexpr=s:NewIndentExpr() |
| 332 | call assert_equal(expand('<SID>') .. 'NewIndentExpr()', &indentexpr) |
zeertzjq | 01d4efe | 2023-01-25 15:31:28 +0000 | [diff] [blame] | 333 | call assert_equal(expand('<SID>') .. 'NewIndentExpr()', &g:indentexpr) |
Yegappan Lakshmanan | 8bb65f2 | 2021-12-26 10:51:39 +0000 | [diff] [blame] | 334 | set indentexpr=<SID>NewIndentExpr() |
| 335 | call assert_equal(expand('<SID>') .. 'NewIndentExpr()', &indentexpr) |
zeertzjq | 01d4efe | 2023-01-25 15:31:28 +0000 | [diff] [blame] | 336 | call assert_equal(expand('<SID>') .. 'NewIndentExpr()', &g:indentexpr) |
| 337 | setlocal indentexpr= |
| 338 | setglobal indentexpr=s:NewIndentExpr() |
| 339 | call assert_equal(expand('<SID>') .. 'NewIndentExpr()', &g:indentexpr) |
| 340 | call assert_equal('', &indentexpr) |
| 341 | new |
| 342 | call assert_equal(expand('<SID>') .. 'NewIndentExpr()', &indentexpr) |
| 343 | bw! |
| 344 | setglobal indentexpr=<SID>NewIndentExpr() |
| 345 | call assert_equal(expand('<SID>') .. 'NewIndentExpr()', &g:indentexpr) |
| 346 | call assert_equal('', &indentexpr) |
| 347 | new |
| 348 | call assert_equal(expand('<SID>') .. 'NewIndentExpr()', &indentexpr) |
| 349 | bw! |
Yegappan Lakshmanan | 8bb65f2 | 2021-12-26 10:51:39 +0000 | [diff] [blame] | 350 | set indentexpr& |
| 351 | |
Bram Moolenaar | 1b38344 | 2017-09-26 20:04:54 +0200 | [diff] [blame] | 352 | bw! |
| 353 | endfunc |
| 354 | |
Bram Moolenaar | f9ab52e | 2020-05-05 19:57:18 +0200 | [diff] [blame] | 355 | " Test changing indent in replace mode |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 356 | func Test_edit_12() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 357 | new |
| 358 | call setline(1, ["\tabc", "\tdef"]) |
| 359 | call cursor(2, 4) |
| 360 | call feedkeys("R^\<c-d>", 'tnix') |
| 361 | call assert_equal(["\tabc", "def"], getline(1, '$')) |
Bram Moolenaar | 4c313b1 | 2019-08-24 22:58:31 +0200 | [diff] [blame] | 362 | call assert_equal([0, 2, 2, 0], '.'->getpos()) |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 363 | %d |
| 364 | call setline(1, ["\tabc", "\t\tdef"]) |
| 365 | call cursor(2, 2) |
| 366 | call feedkeys("R^\<c-d>", 'tnix') |
| 367 | call assert_equal(["\tabc", "def"], getline(1, '$')) |
| 368 | call assert_equal([0, 2, 1, 0], getpos('.')) |
| 369 | %d |
| 370 | call setline(1, ["\tabc", "\t\tdef"]) |
| 371 | call cursor(2, 2) |
| 372 | call feedkeys("R\<c-t>", 'tnix') |
| 373 | call assert_equal(["\tabc", "\t\t\tdef"], getline(1, '$')) |
| 374 | call assert_equal([0, 2, 2, 0], getpos('.')) |
| 375 | bw! |
| 376 | 10vnew |
| 377 | call setline(1, ["\tabc", "\t\tdef"]) |
| 378 | call cursor(2, 2) |
| 379 | call feedkeys("R\<c-t>", 'tnix') |
| 380 | call assert_equal(["\tabc", "\t\t\tdef"], getline(1, '$')) |
| 381 | call assert_equal([0, 2, 2, 0], getpos('.')) |
| 382 | %d |
| 383 | set sw=4 |
| 384 | call setline(1, ["\tabc", "\t\tdef"]) |
| 385 | call cursor(2, 2) |
| 386 | call feedkeys("R\<c-t>\<c-t>", 'tnix') |
| 387 | call assert_equal(["\tabc", "\t\t\tdef"], getline(1, '$')) |
| 388 | call assert_equal([0, 2, 2, 0], getpos('.')) |
| 389 | %d |
| 390 | call setline(1, ["\tabc", "\t\tdef"]) |
| 391 | call cursor(2, 2) |
| 392 | call feedkeys("R\<c-t>\<c-t>", 'tnix') |
| 393 | call assert_equal(["\tabc", "\t\t\tdef"], getline(1, '$')) |
| 394 | call assert_equal([0, 2, 2, 0], getpos('.')) |
Bram Moolenaar | f9ab52e | 2020-05-05 19:57:18 +0200 | [diff] [blame] | 395 | set sw& |
| 396 | |
| 397 | " In replace mode, after hitting enter in a line with tab characters, |
| 398 | " pressing backspace should restore the tab characters. |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 399 | %d |
Bram Moolenaar | f9ab52e | 2020-05-05 19:57:18 +0200 | [diff] [blame] | 400 | setlocal autoindent backspace=2 |
| 401 | call setline(1, "\tone\t\ttwo") |
| 402 | exe "normal ggRred\<CR>six" .. repeat("\<BS>", 8) |
| 403 | call assert_equal(["\tone\t\ttwo"], getline(1, '$')) |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 404 | bw! |
| 405 | endfunc |
| 406 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 407 | func Test_edit_13() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 408 | " Test smartindenting |
Bram Moolenaar | 8e145b8 | 2022-05-21 20:17:31 +0100 | [diff] [blame] | 409 | new |
| 410 | set smartindent autoindent |
| 411 | call setline(1, ["\tabc"]) |
| 412 | call feedkeys("A {\<cr>more\<cr>}\<esc>", 'tnix') |
| 413 | call assert_equal(["\tabc {", "\t\tmore", "\t}"], getline(1, '$')) |
| 414 | set smartindent& autoindent& |
| 415 | bwipe! |
Bram Moolenaar | 2ba4238 | 2019-03-16 18:11:07 +0100 | [diff] [blame] | 416 | |
| 417 | " Test autoindent removing indent of blank line. |
| 418 | new |
| 419 | call setline(1, ' foo bar baz') |
| 420 | set autoindent |
| 421 | exe "normal 0eea\<CR>\<CR>\<Esc>" |
| 422 | call assert_equal(" foo bar", getline(1)) |
| 423 | call assert_equal("", getline(2)) |
| 424 | call assert_equal(" baz", getline(3)) |
| 425 | set autoindent& |
Bram Moolenaar | 845e0ee | 2020-06-20 16:05:32 +0200 | [diff] [blame] | 426 | |
| 427 | " pressing <C-U> to erase line should keep the indent with 'autoindent' |
| 428 | set backspace=2 autoindent |
| 429 | %d |
| 430 | exe "normal i\tone\<CR>three\<C-U>two" |
| 431 | call assert_equal(["\tone", "\ttwo"], getline(1, '$')) |
| 432 | set backspace& autoindent& |
| 433 | |
Bram Moolenaar | 2ba4238 | 2019-03-16 18:11:07 +0100 | [diff] [blame] | 434 | bwipe! |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 435 | endfunc |
| 436 | |
Bram Moolenaar | 1f448d9 | 2021-03-22 19:37:06 +0100 | [diff] [blame] | 437 | " Test for autoindent removing indent when insert mode is stopped. Some parts |
| 438 | " of the code is exercised only when interactive mode is used. So use Vim in a |
| 439 | " terminal. |
| 440 | func Test_autoindent_remove_indent() |
| 441 | CheckRunVimInTerminal |
Bram Moolenaar | 61abe7d | 2022-08-30 21:46:08 +0100 | [diff] [blame] | 442 | let buf = RunVimInTerminal('-N Xarifile', {'rows': 6, 'cols' : 20}) |
Bram Moolenaar | 1f448d9 | 2021-03-22 19:37:06 +0100 | [diff] [blame] | 443 | call TermWait(buf) |
| 444 | call term_sendkeys(buf, ":set autoindent\n") |
| 445 | " leaving insert mode in a new line with indent added by autoindent, should |
| 446 | " remove the indent. |
| 447 | call term_sendkeys(buf, "i\<Tab>foo\<CR>\<Esc>") |
Dominique Pelle | 923dce2 | 2021-11-21 11:36:04 +0000 | [diff] [blame] | 448 | " Need to delay for some time, otherwise the code in getchar.c will not be |
Bram Moolenaar | 1f448d9 | 2021-03-22 19:37:06 +0100 | [diff] [blame] | 449 | " exercised. |
| 450 | call TermWait(buf, 50) |
| 451 | " when a line is wrapped and the cursor is at the start of the second line, |
| 452 | " leaving insert mode, should move the cursor back to the first line. |
| 453 | call term_sendkeys(buf, "o" .. repeat('x', 20) .. "\<Esc>") |
Dominique Pelle | 923dce2 | 2021-11-21 11:36:04 +0000 | [diff] [blame] | 454 | " Need to delay for some time, otherwise the code in getchar.c will not be |
Bram Moolenaar | 1f448d9 | 2021-03-22 19:37:06 +0100 | [diff] [blame] | 455 | " exercised. |
| 456 | call TermWait(buf, 50) |
| 457 | call term_sendkeys(buf, ":w\n") |
| 458 | call TermWait(buf) |
| 459 | call StopVimInTerminal(buf) |
Bram Moolenaar | 61abe7d | 2022-08-30 21:46:08 +0100 | [diff] [blame] | 460 | call assert_equal(["\tfoo", '', repeat('x', 20)], readfile('Xarifile')) |
| 461 | call delete('Xarifile') |
Bram Moolenaar | 1f448d9 | 2021-03-22 19:37:06 +0100 | [diff] [blame] | 462 | endfunc |
| 463 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 464 | func Test_edit_CR() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 465 | " Test for <CR> in insert mode |
Dominique Pelle | 923dce2 | 2021-11-21 11:36:04 +0000 | [diff] [blame] | 466 | " basically only in quickfix mode it's tested, the rest |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 467 | " has been taken care of by other tests |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 468 | CheckFeature quickfix |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 469 | botright new |
Bram Moolenaar | 14f9176 | 2022-09-21 15:13:52 +0100 | [diff] [blame] | 470 | call writefile(range(1, 10), 'Xqflist.txt', 'D') |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 471 | call setqflist([{'filename': 'Xqflist.txt', 'lnum': 2}]) |
| 472 | copen |
| 473 | set modifiable |
| 474 | call feedkeys("A\<cr>", 'tnix') |
| 475 | call assert_equal('Xqflist.txt', bufname('')) |
| 476 | call assert_equal(2, line('.')) |
| 477 | cclose |
| 478 | botright new |
| 479 | call setloclist(0, [{'filename': 'Xqflist.txt', 'lnum': 10}]) |
| 480 | lopen |
| 481 | set modifiable |
| 482 | call feedkeys("A\<cr>", 'tnix') |
| 483 | call assert_equal('Xqflist.txt', bufname('')) |
| 484 | call assert_equal(10, line('.')) |
| 485 | call feedkeys("A\<Enter>", 'tnix') |
| 486 | call feedkeys("A\<kEnter>", 'tnix') |
| 487 | call feedkeys("A\n", 'tnix') |
| 488 | call feedkeys("A\r", 'tnix') |
| 489 | call assert_equal(map(range(1, 10), 'string(v:val)') + ['', '', '', ''], getline(1, '$')) |
Bram Moolenaar | 14f9176 | 2022-09-21 15:13:52 +0100 | [diff] [blame] | 490 | |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 491 | bw! |
| 492 | lclose |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 493 | endfunc |
| 494 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 495 | func Test_edit_CTRL_() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 496 | CheckFeature rightleft |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 497 | " disabled for Windows builds, why? |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 498 | CheckNotMSWindows |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 499 | let _encoding=&encoding |
| 500 | set encoding=utf-8 |
| 501 | " Test for CTRL-_ |
| 502 | new |
| 503 | call setline(1, ['abc']) |
| 504 | call cursor(1, 1) |
| 505 | call feedkeys("i\<c-_>xyz\<esc>", 'tnix') |
| 506 | call assert_equal(["\<C-_>xyzabc"], getline(1, '$')) |
| 507 | call assert_false(&revins) |
| 508 | set ari |
| 509 | call setline(1, ['abc']) |
| 510 | call cursor(1, 1) |
| 511 | call feedkeys("i\<c-_>xyz\<esc>", 'tnix') |
| 512 | call assert_equal(["æèñabc"], getline(1, '$')) |
| 513 | call assert_true(&revins) |
| 514 | call setline(1, ['abc']) |
| 515 | call cursor(1, 1) |
| 516 | call feedkeys("i\<c-_>xyz\<esc>", 'tnix') |
| 517 | call assert_equal(["xyzabc"], getline(1, '$')) |
| 518 | call assert_false(&revins) |
| 519 | set noari |
| 520 | let &encoding=_encoding |
| 521 | bw! |
| 522 | endfunc |
| 523 | |
| 524 | " needs to come first, to have the @. register empty |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 525 | func Test_edit_00a_CTRL_A() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 526 | " Test pressing CTRL-A |
| 527 | new |
| 528 | call setline(1, repeat([''], 5)) |
| 529 | call cursor(1, 1) |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 530 | try |
| 531 | call feedkeys("A\<NUL>", 'tnix') |
| 532 | catch /^Vim\%((\a\+)\)\=:E29/ |
| 533 | call assert_true(1, 'E29 error caught') |
| 534 | endtry |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 535 | call cursor(1, 1) |
| 536 | call feedkeys("Afoobar \<esc>", 'tnix') |
| 537 | call cursor(2, 1) |
| 538 | call feedkeys("A\<c-a>more\<esc>", 'tnix') |
| 539 | call cursor(3, 1) |
| 540 | call feedkeys("A\<NUL>and more\<esc>", 'tnix') |
| 541 | call assert_equal(['foobar ', 'foobar more', 'foobar morend more', '', ''], getline(1, '$')) |
| 542 | bw! |
| 543 | endfunc |
| 544 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 545 | func Test_edit_CTRL_EY() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 546 | " Ctrl-E/ Ctrl-Y in insert mode completion to scroll |
| 547 | 10new |
| 548 | call setline(1, range(1, 100)) |
| 549 | call cursor(30, 1) |
| 550 | norm! z. |
| 551 | call feedkeys("A\<c-x>\<c-e>\<c-e>\<c-e>\<c-e>\<c-e>", 'tnix') |
| 552 | call assert_equal(30, winsaveview()['topline']) |
| 553 | call assert_equal([0, 30, 2, 0], getpos('.')) |
| 554 | call feedkeys("A\<c-x>\<c-e>\<c-e>\<c-e>\<c-e>\<c-e>", 'tnix') |
| 555 | call feedkeys("A\<c-x>".repeat("\<c-y>", 10), 'tnix') |
| 556 | call assert_equal(21, winsaveview()['topline']) |
| 557 | call assert_equal([0, 30, 2, 0], getpos('.')) |
| 558 | bw! |
| 559 | endfunc |
| 560 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 561 | func Test_edit_CTRL_G() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 562 | new |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 563 | call setline(1, ['foobar', 'foobar', 'foobar']) |
| 564 | call cursor(2, 4) |
| 565 | call feedkeys("ioooooooo\<c-g>k\<c-r>.\<esc>", 'tnix') |
| 566 | call assert_equal(['foooooooooobar', 'foooooooooobar', 'foobar'], getline(1, '$')) |
| 567 | call assert_equal([0, 1, 11, 0], getpos('.')) |
| 568 | call feedkeys("i\<c-g>k\<esc>", 'tnix') |
| 569 | call assert_equal([0, 1, 10, 0], getpos('.')) |
| 570 | call cursor(2, 4) |
| 571 | call feedkeys("i\<c-g>jzzzz\<esc>", 'tnix') |
| 572 | call assert_equal(['foooooooooobar', 'foooooooooobar', 'foozzzzbar'], getline(1, '$')) |
| 573 | call assert_equal([0, 3, 7, 0], getpos('.')) |
| 574 | call feedkeys("i\<c-g>j\<esc>", 'tnix') |
| 575 | call assert_equal([0, 3, 6, 0], getpos('.')) |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 576 | bw! |
| 577 | endfunc |
| 578 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 579 | func Test_edit_CTRL_I() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 580 | " Tab in completion mode |
| 581 | let path=expand("%:p:h") |
| 582 | new |
Bram Moolenaar | ca85159 | 2018-06-06 21:04:07 +0200 | [diff] [blame] | 583 | call setline(1, [path. "/", '']) |
Bram Moolenaar | c537947 | 2017-03-16 22:38:00 +0100 | [diff] [blame] | 584 | call feedkeys("Arunt\<c-x>\<c-f>\<tab>\<cr>\<esc>", 'tnix') |
| 585 | call assert_match('runtest\.vim', getline(1)) |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 586 | %d |
Bram Moolenaar | 14f9176 | 2022-09-21 15:13:52 +0100 | [diff] [blame] | 587 | call writefile(['one', 'two', 'three'], 'Xinclude.txt', 'D') |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 588 | let include='#include Xinclude.txt' |
| 589 | call setline(1, [include, '']) |
| 590 | call cursor(2, 1) |
| 591 | call feedkeys("A\<c-x>\<tab>\<cr>\<esc>", 'tnix') |
| 592 | call assert_equal([include, 'one', ''], getline(1, '$')) |
| 593 | call feedkeys("2ggC\<c-x>\<tab>\<down>\<cr>\<esc>", 'tnix') |
| 594 | call assert_equal([include, 'two', ''], getline(1, '$')) |
| 595 | call feedkeys("2ggC\<c-x>\<tab>\<down>\<down>\<cr>\<esc>", 'tnix') |
| 596 | call assert_equal([include, 'three', ''], getline(1, '$')) |
| 597 | call feedkeys("2ggC\<c-x>\<tab>\<down>\<down>\<down>\<cr>\<esc>", 'tnix') |
| 598 | call assert_equal([include, '', ''], getline(1, '$')) |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 599 | bw! |
| 600 | endfunc |
| 601 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 602 | func Test_edit_CTRL_K() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 603 | " Test pressing CTRL-K (basically only dictionary completion and digraphs |
| 604 | " the rest is already covered |
Bram Moolenaar | 14f9176 | 2022-09-21 15:13:52 +0100 | [diff] [blame] | 605 | call writefile(['A', 'AA', 'AAA', 'AAAA'], 'Xdictionary.txt', 'D') |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 606 | set dictionary=Xdictionary.txt |
| 607 | new |
| 608 | call setline(1, 'A') |
| 609 | call cursor(1, 1) |
| 610 | call feedkeys("A\<c-x>\<c-k>\<cr>\<esc>", 'tnix') |
| 611 | call assert_equal(['AA', ''], getline(1, '$')) |
| 612 | %d |
| 613 | call setline(1, 'A') |
| 614 | call cursor(1, 1) |
| 615 | call feedkeys("A\<c-x>\<c-k>\<down>\<cr>\<esc>", 'tnix') |
| 616 | call assert_equal(['AAA'], getline(1, '$')) |
| 617 | %d |
| 618 | call setline(1, 'A') |
| 619 | call cursor(1, 1) |
| 620 | call feedkeys("A\<c-x>\<c-k>\<down>\<down>\<cr>\<esc>", 'tnix') |
| 621 | call assert_equal(['AAAA'], getline(1, '$')) |
| 622 | %d |
| 623 | call setline(1, 'A') |
| 624 | call cursor(1, 1) |
| 625 | call feedkeys("A\<c-x>\<c-k>\<down>\<down>\<down>\<cr>\<esc>", 'tnix') |
| 626 | call assert_equal(['A'], getline(1, '$')) |
| 627 | %d |
| 628 | call setline(1, 'A') |
| 629 | call cursor(1, 1) |
| 630 | call feedkeys("A\<c-x>\<c-k>\<down>\<down>\<down>\<down>\<cr>\<esc>", 'tnix') |
| 631 | call assert_equal(['AA'], getline(1, '$')) |
| 632 | |
Bram Moolenaar | 4b96df5 | 2020-01-26 22:00:26 +0100 | [diff] [blame] | 633 | " press an unexpected key after dictionary completion |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 634 | %d |
| 635 | call setline(1, 'A') |
| 636 | call cursor(1, 1) |
| 637 | call feedkeys("A\<c-x>\<c-k>\<c-]>\<cr>\<esc>", 'tnix') |
| 638 | call assert_equal(['AA', ''], getline(1, '$')) |
| 639 | %d |
| 640 | call setline(1, 'A') |
| 641 | call cursor(1, 1) |
| 642 | call feedkeys("A\<c-x>\<c-k>\<c-s>\<cr>\<esc>", 'tnix') |
| 643 | call assert_equal(["AA\<c-s>", ''], getline(1, '$')) |
| 644 | %d |
| 645 | call setline(1, 'A') |
| 646 | call cursor(1, 1) |
| 647 | call feedkeys("A\<c-x>\<c-k>\<c-f>\<cr>\<esc>", 'tnix') |
| 648 | call assert_equal(["AA\<c-f>", ''], getline(1, '$')) |
| 649 | |
| 650 | set dictionary= |
| 651 | %d |
| 652 | call setline(1, 'A') |
| 653 | call cursor(1, 1) |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 654 | let v:testing = 1 |
| 655 | try |
| 656 | call feedkeys("A\<c-x>\<c-k>\<esc>", 'tnix') |
| 657 | catch |
| 658 | " error sleeps 2 seconds, when v:testing is not set |
| 659 | let v:testing = 0 |
| 660 | endtry |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 661 | |
Bram Moolenaar | 30276f2 | 2019-01-24 17:59:39 +0100 | [diff] [blame] | 662 | call test_override("char_avail", 1) |
| 663 | set showcmd |
| 664 | %d |
| 665 | call feedkeys("A\<c-k>a:\<esc>", 'tnix') |
| 666 | call assert_equal(['ä'], getline(1, '$')) |
| 667 | call test_override("char_avail", 0) |
| 668 | set noshowcmd |
| 669 | |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 670 | bw! |
| 671 | endfunc |
| 672 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 673 | func Test_edit_CTRL_L() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 674 | " Test Ctrl-X Ctrl-L (line completion) |
| 675 | new |
| 676 | set complete=. |
| 677 | call setline(1, ['one', 'two', 'three', '', '', '', '']) |
| 678 | call cursor(4, 1) |
| 679 | call feedkeys("A\<c-x>\<c-l>\<esc>", 'tnix') |
| 680 | call assert_equal(['one', 'two', 'three', 'three', '', '', ''], getline(1, '$')) |
| 681 | call feedkeys("cct\<c-x>\<c-l>\<c-n>\<esc>", 'tnix') |
| 682 | call assert_equal(['one', 'two', 'three', 't', '', '', ''], getline(1, '$')) |
| 683 | call feedkeys("cct\<c-x>\<c-l>\<c-n>\<c-n>\<esc>", 'tnix') |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 684 | call assert_equal(['one', 'two', 'three', 'two', '', '', ''], getline(1, '$')) |
Bram Moolenaar | 02ae9b4 | 2018-02-09 15:06:02 +0100 | [diff] [blame] | 685 | call feedkeys("cct\<c-x>\<c-l>\<c-n>\<c-n>\<c-n>\<esc>", 'tnix') |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 686 | call assert_equal(['one', 'two', 'three', 'three', '', '', ''], getline(1, '$')) |
Bram Moolenaar | 02ae9b4 | 2018-02-09 15:06:02 +0100 | [diff] [blame] | 687 | call feedkeys("cct\<c-x>\<c-l>\<c-n>\<c-n>\<c-n>\<c-n>\<esc>", 'tnix') |
| 688 | call assert_equal(['one', 'two', 'three', 't', '', '', ''], getline(1, '$')) |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 689 | call feedkeys("cct\<c-x>\<c-l>\<c-p>\<esc>", 'tnix') |
| 690 | call assert_equal(['one', 'two', 'three', 'two', '', '', ''], getline(1, '$')) |
| 691 | call feedkeys("cct\<c-x>\<c-l>\<c-p>\<c-p>\<esc>", 'tnix') |
| 692 | call assert_equal(['one', 'two', 'three', 't', '', '', ''], getline(1, '$')) |
| 693 | call feedkeys("cct\<c-x>\<c-l>\<c-p>\<c-p>\<c-p>\<esc>", 'tnix') |
| 694 | call assert_equal(['one', 'two', 'three', 'three', '', '', ''], getline(1, '$')) |
| 695 | set complete= |
| 696 | call cursor(5, 1) |
| 697 | call feedkeys("A\<c-x>\<c-l>\<c-p>\<c-n>\<esc>", 'tnix') |
| 698 | call assert_equal(['one', 'two', 'three', 'three', "\<c-l>\<c-p>\<c-n>", '', ''], getline(1, '$')) |
| 699 | set complete& |
| 700 | %d |
| 701 | if has("conceal") && has("syntax") |
| 702 | call setline(1, ['foo', 'bar', 'foobar']) |
| 703 | call test_override("char_avail", 1) |
| 704 | set conceallevel=2 concealcursor=n |
| 705 | syn on |
| 706 | syn match ErrorMsg "^bar" |
| 707 | call matchadd("Conceal", 'oo', 10, -1, {'conceal': 'X'}) |
| 708 | func! DoIt() |
| 709 | let g:change=1 |
| 710 | endfunc |
| 711 | au! TextChangedI <buffer> :call DoIt() |
| 712 | |
| 713 | call cursor(2, 1) |
| 714 | call assert_false(exists("g:change")) |
| 715 | call feedkeys("A \<esc>", 'tnix') |
| 716 | call assert_equal(['foo', 'bar ', 'foobar'], getline(1, '$')) |
| 717 | call assert_equal(1, g:change) |
| 718 | |
| 719 | call test_override("char_avail", 0) |
| 720 | call clearmatches() |
| 721 | syn off |
| 722 | au! TextChangedI |
| 723 | delfu DoIt |
| 724 | unlet! g:change |
| 725 | endif |
| 726 | bw! |
| 727 | endfunc |
| 728 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 729 | func Test_edit_CTRL_N() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 730 | " Check keyword completion |
Bram Moolenaar | a1070ea | 2021-02-20 19:21:36 +0100 | [diff] [blame] | 731 | for e in ['latin1', 'utf-8'] |
| 732 | exe 'set encoding=' .. e |
| 733 | new |
| 734 | set complete=. |
| 735 | call setline(1, ['INFER', 'loWER', '', '', ]) |
| 736 | call cursor(3, 1) |
| 737 | call feedkeys("Ai\<c-n>\<cr>\<esc>", "tnix") |
| 738 | call feedkeys("ILO\<c-n>\<cr>\<esc>", 'tnix') |
| 739 | call assert_equal(['INFER', 'loWER', 'i', 'LO', '', ''], getline(1, '$'), e) |
| 740 | %d |
| 741 | call setline(1, ['INFER', 'loWER', '', '', ]) |
| 742 | call cursor(3, 1) |
| 743 | set ignorecase infercase |
| 744 | call feedkeys("Ii\<c-n>\<cr>\<esc>", "tnix") |
| 745 | call feedkeys("ILO\<c-n>\<cr>\<esc>", 'tnix') |
| 746 | call assert_equal(['INFER', 'loWER', 'infer', 'LOWER', '', ''], getline(1, '$'), e) |
Yegappan Lakshmanan | e982586 | 2022-01-03 11:03:48 +0000 | [diff] [blame] | 747 | set noignorecase noinfercase |
| 748 | %d |
| 749 | call setline(1, ['one word', 'two word']) |
| 750 | exe "normal! Goo\<C-P>\<C-X>\<C-P>" |
| 751 | call assert_equal('one word', getline(3)) |
| 752 | %d |
| 753 | set complete& |
Bram Moolenaar | a1070ea | 2021-02-20 19:21:36 +0100 | [diff] [blame] | 754 | bw! |
| 755 | endfor |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 756 | endfunc |
| 757 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 758 | func Test_edit_CTRL_O() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 759 | " Check for CTRL-O in insert mode |
| 760 | new |
| 761 | inoreabbr <buffer> h here some more |
| 762 | call setline(1, ['abc', 'def']) |
| 763 | call cursor(1, 1) |
| 764 | " Ctrl-O after an abbreviation |
| 765 | exe "norm A h\<c-o>:set nu\<cr> text" |
| 766 | call assert_equal(['abc here some more text', 'def'], getline(1, '$')) |
| 767 | call assert_true(&nu) |
| 768 | set nonu |
| 769 | iunabbr <buffer> h |
| 770 | " Ctrl-O at end of line with 've'=onemore |
| 771 | call cursor(1, 1) |
| 772 | call feedkeys("A\<c-o>:let g:a=getpos('.')\<cr>\<esc>", 'tnix') |
| 773 | call assert_equal([0, 1, 23, 0], g:a) |
| 774 | call cursor(1, 1) |
| 775 | set ve=onemore |
| 776 | call feedkeys("A\<c-o>:let g:a=getpos('.')\<cr>\<esc>", 'tnix') |
| 777 | call assert_equal([0, 1, 24, 0], g:a) |
| 778 | set ve= |
| 779 | unlet! g:a |
| 780 | bw! |
| 781 | endfunc |
| 782 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 783 | func Test_edit_CTRL_R() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 784 | " Insert Register |
| 785 | new |
| 786 | call test_override("ALL", 1) |
| 787 | set showcmd |
| 788 | call feedkeys("AFOOBAR eins zwei\<esc>", 'tnix') |
| 789 | call feedkeys("O\<c-r>.", 'tnix') |
| 790 | call feedkeys("O\<c-r>=10*500\<cr>\<esc>", 'tnix') |
| 791 | call feedkeys("O\<c-r>=getreg('=', 1)\<cr>\<esc>", 'tnix') |
| 792 | call assert_equal(["getreg('=', 1)", '5000', "FOOBAR eins zwei", "FOOBAR eins zwei"], getline(1, '$')) |
| 793 | call test_override("ALL", 0) |
| 794 | set noshowcmd |
| 795 | bw! |
| 796 | endfunc |
| 797 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 798 | func Test_edit_CTRL_S() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 799 | " Test pressing CTRL-S (basically only spellfile completion) |
| 800 | " the rest is already covered |
| 801 | new |
| 802 | if !has("spell") |
| 803 | call setline(1, 'vim') |
| 804 | call feedkeys("A\<c-x>ss\<cr>\<esc>", 'tnix') |
| 805 | call assert_equal(['vims', ''], getline(1, '$')) |
| 806 | bw! |
| 807 | return |
| 808 | endif |
| 809 | call setline(1, 'vim') |
| 810 | " spell option not yet set |
| 811 | try |
| 812 | call feedkeys("A\<c-x>\<c-s>\<cr>\<esc>", 'tnix') |
| 813 | catch /^Vim\%((\a\+)\)\=:E756/ |
| 814 | call assert_true(1, 'error caught') |
| 815 | endtry |
| 816 | call assert_equal(['vim', ''], getline(1, '$')) |
| 817 | %d |
| 818 | setl spell spelllang=en |
| 819 | call setline(1, 'vim') |
| 820 | call cursor(1, 1) |
| 821 | call feedkeys("A\<c-x>\<c-s>\<cr>\<esc>", 'tnix') |
| 822 | call assert_equal(['Vim', ''], getline(1, '$')) |
| 823 | %d |
| 824 | call setline(1, 'vim') |
| 825 | call cursor(1, 1) |
| 826 | call feedkeys("A\<c-x>\<c-s>\<down>\<cr>\<esc>", 'tnix') |
| 827 | call assert_equal(['Aim'], getline(1, '$')) |
| 828 | %d |
| 829 | call setline(1, 'vim') |
| 830 | call cursor(1, 1) |
| 831 | call feedkeys("A\<c-x>\<c-s>\<c-p>\<cr>\<esc>", 'tnix') |
| 832 | call assert_equal(['vim', ''], getline(1, '$')) |
| 833 | %d |
| 834 | " empty buffer |
| 835 | call cursor(1, 1) |
| 836 | call feedkeys("A\<c-x>\<c-s>\<c-p>\<cr>\<esc>", 'tnix') |
| 837 | call assert_equal(['', ''], getline(1, '$')) |
| 838 | setl nospell |
| 839 | bw! |
| 840 | endfunc |
| 841 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 842 | func Test_edit_CTRL_T() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 843 | " Check for CTRL-T and CTRL-X CTRL-T in insert mode |
| 844 | " 1) increase indent |
| 845 | new |
| 846 | call setline(1, "abc") |
| 847 | call cursor(1, 1) |
| 848 | call feedkeys("A\<c-t>xyz", 'tnix') |
| 849 | call assert_equal(["\<tab>abcxyz"], getline(1, '$')) |
| 850 | " 2) also when paste option is set |
| 851 | set paste |
| 852 | call setline(1, "abc") |
| 853 | call cursor(1, 1) |
| 854 | call feedkeys("A\<c-t>xyz", 'tnix') |
| 855 | call assert_equal(["\<tab>abcxyz"], getline(1, '$')) |
| 856 | set nopaste |
| 857 | " CTRL-X CTRL-T (thesaurus complete) |
Bram Moolenaar | 14f9176 | 2022-09-21 15:13:52 +0100 | [diff] [blame] | 858 | call writefile(['angry furious mad enraged'], 'Xthesaurus', 'D') |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 859 | set thesaurus=Xthesaurus |
| 860 | call setline(1, 'mad') |
| 861 | call cursor(1, 1) |
| 862 | call feedkeys("A\<c-x>\<c-t>\<cr>\<esc>", 'tnix') |
| 863 | call assert_equal(['mad', ''], getline(1, '$')) |
| 864 | %d |
| 865 | call setline(1, 'mad') |
| 866 | call cursor(1, 1) |
| 867 | call feedkeys("A\<c-x>\<c-t>\<c-n>\<cr>\<esc>", 'tnix') |
| 868 | call assert_equal(['angry', ''], getline(1, '$')) |
| 869 | %d |
| 870 | call setline(1, 'mad') |
| 871 | call cursor(1, 1) |
| 872 | call feedkeys("A\<c-x>\<c-t>\<c-n>\<c-n>\<cr>\<esc>", 'tnix') |
| 873 | call assert_equal(['furious', ''], getline(1, '$')) |
| 874 | %d |
| 875 | call setline(1, 'mad') |
| 876 | call cursor(1, 1) |
| 877 | call feedkeys("A\<c-x>\<c-t>\<c-n>\<c-n>\<c-n>\<cr>\<esc>", 'tnix') |
| 878 | call assert_equal(['enraged', ''], getline(1, '$')) |
| 879 | %d |
| 880 | call setline(1, 'mad') |
| 881 | call cursor(1, 1) |
| 882 | call feedkeys("A\<c-x>\<c-t>\<c-n>\<c-n>\<c-n>\<c-n>\<cr>\<esc>", 'tnix') |
| 883 | call assert_equal(['mad', ''], getline(1, '$')) |
| 884 | %d |
| 885 | call setline(1, 'mad') |
| 886 | call cursor(1, 1) |
| 887 | call feedkeys("A\<c-x>\<c-t>\<c-n>\<c-n>\<c-n>\<c-n>\<c-n>\<cr>\<esc>", 'tnix') |
| 888 | call assert_equal(['mad', ''], getline(1, '$')) |
| 889 | " Using <c-p> <c-n> when 'complete' is empty |
| 890 | set complete= |
| 891 | %d |
| 892 | call setline(1, 'mad') |
| 893 | call cursor(1, 1) |
| 894 | call feedkeys("A\<c-x>\<c-t>\<c-n>\<cr>\<esc>", 'tnix') |
| 895 | call assert_equal(['angry', ''], getline(1, '$')) |
| 896 | %d |
| 897 | call setline(1, 'mad') |
| 898 | call cursor(1, 1) |
| 899 | call feedkeys("A\<c-x>\<c-t>\<c-p>\<cr>\<esc>", 'tnix') |
| 900 | call assert_equal(['mad', ''], getline(1, '$')) |
| 901 | set complete& |
| 902 | |
| 903 | set thesaurus= |
| 904 | %d |
| 905 | call setline(1, 'mad') |
| 906 | call cursor(1, 1) |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 907 | let v:testing = 1 |
| 908 | try |
| 909 | call feedkeys("A\<c-x>\<c-t>\<esc>", 'tnix') |
| 910 | catch |
| 911 | " error sleeps 2 seconds, when v:testing is not set |
| 912 | let v:testing = 0 |
| 913 | endtry |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 914 | call assert_equal(['mad'], getline(1, '$')) |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 915 | bw! |
| 916 | endfunc |
| 917 | |
Yegappan Lakshmanan | e982586 | 2022-01-03 11:03:48 +0000 | [diff] [blame] | 918 | " Test thesaurus completion with different encodings |
| 919 | func Test_thesaurus_complete_with_encoding() |
Bram Moolenaar | 14f9176 | 2022-09-21 15:13:52 +0100 | [diff] [blame] | 920 | call writefile(['angry furious mad enraged'], 'Xthesaurus', 'D') |
Yegappan Lakshmanan | e982586 | 2022-01-03 11:03:48 +0000 | [diff] [blame] | 921 | set thesaurus=Xthesaurus |
| 922 | for e in ['latin1', 'utf-8'] |
| 923 | exe 'set encoding=' .. e |
| 924 | new |
| 925 | call setline(1, 'mad') |
| 926 | call cursor(1, 1) |
| 927 | call feedkeys("A\<c-x>\<c-t>\<cr>\<esc>", 'tnix') |
| 928 | call assert_equal(['mad', ''], getline(1, '$')) |
| 929 | bw! |
| 930 | endfor |
| 931 | set thesaurus= |
Yegappan Lakshmanan | e982586 | 2022-01-03 11:03:48 +0000 | [diff] [blame] | 932 | endfunc |
| 933 | |
Yegappan Lakshmanan | 160e994 | 2021-10-16 15:41:29 +0100 | [diff] [blame] | 934 | " Test 'thesaurusfunc' |
| 935 | func MyThesaurus(findstart, base) |
| 936 | let mythesaurus = [ |
| 937 | \ #{word: "happy", |
| 938 | \ synonyms: "cheerful,blissful,flying high,looking good,peppy"}, |
| 939 | \ #{word: "kind", |
| 940 | \ synonyms: "amiable,bleeding-heart,heart in right place"}] |
| 941 | if a:findstart |
| 942 | " locate the start of the word |
| 943 | let line = getline('.') |
| 944 | let start = col('.') - 1 |
| 945 | while start > 0 && line[start - 1] =~ '\a' |
| 946 | let start -= 1 |
| 947 | endwhile |
| 948 | return start |
| 949 | else |
| 950 | " find strings matching with "a:base" |
| 951 | let res = [] |
| 952 | for w in mythesaurus |
| 953 | if w.word =~ '^' . a:base |
| 954 | call add(res, w.word) |
| 955 | call extend(res, split(w.synonyms, ",")) |
| 956 | endif |
| 957 | endfor |
| 958 | return res |
| 959 | endif |
| 960 | endfunc |
| 961 | |
| 962 | func Test_thesaurus_func() |
| 963 | new |
Bram Moolenaar | f4d8b76 | 2021-10-17 14:13:09 +0100 | [diff] [blame] | 964 | set thesaurus=notused |
| 965 | set thesaurusfunc=NotUsed |
| 966 | setlocal thesaurusfunc=MyThesaurus |
Yegappan Lakshmanan | 160e994 | 2021-10-16 15:41:29 +0100 | [diff] [blame] | 967 | call setline(1, "an ki") |
| 968 | call cursor(1, 1) |
| 969 | call feedkeys("A\<c-x>\<c-t>\<c-n>\<cr>\<esc>", 'tnix') |
| 970 | call assert_equal(['an amiable', ''], getline(1, '$')) |
Bram Moolenaar | f4d8b76 | 2021-10-17 14:13:09 +0100 | [diff] [blame] | 971 | |
| 972 | setlocal thesaurusfunc=NonExistingFunc |
| 973 | call assert_fails("normal $a\<C-X>\<C-T>", 'E117:') |
| 974 | |
| 975 | setlocal thesaurusfunc= |
Yegappan Lakshmanan | 160e994 | 2021-10-16 15:41:29 +0100 | [diff] [blame] | 976 | set thesaurusfunc=NonExistingFunc |
| 977 | call assert_fails("normal $a\<C-X>\<C-T>", 'E117:') |
Yegappan Lakshmanan | 160e994 | 2021-10-16 15:41:29 +0100 | [diff] [blame] | 978 | %bw! |
Bram Moolenaar | f4d8b76 | 2021-10-17 14:13:09 +0100 | [diff] [blame] | 979 | |
| 980 | set thesaurusfunc= |
| 981 | set thesaurus= |
Yegappan Lakshmanan | 160e994 | 2021-10-16 15:41:29 +0100 | [diff] [blame] | 982 | endfunc |
| 983 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 984 | func Test_edit_CTRL_U() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 985 | " Test 'completefunc' |
| 986 | new |
| 987 | " -1, -2 and -3 are special return values |
| 988 | let g:special=0 |
| 989 | fun! CompleteMonths(findstart, base) |
| 990 | if a:findstart |
| 991 | " locate the start of the word |
| 992 | return g:special |
| 993 | else |
| 994 | " find months matching with "a:base" |
| 995 | let res = [] |
| 996 | for m in split("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec") |
| 997 | if m =~ '^\c'.a:base |
| 998 | call add(res, {'word': m, 'abbr': m.' Month', 'icase': 0}) |
| 999 | endif |
| 1000 | endfor |
| 1001 | return {'words': res, 'refresh': 'always'} |
| 1002 | endif |
| 1003 | endfun |
| 1004 | set completefunc=CompleteMonths |
| 1005 | call setline(1, ['', '']) |
| 1006 | call cursor(1, 1) |
| 1007 | call feedkeys("AX\<c-x>\<c-u>\<cr>\<esc>", 'tnix') |
| 1008 | call assert_equal(['X', '', ''], getline(1, '$')) |
| 1009 | %d |
| 1010 | let g:special=-1 |
| 1011 | call feedkeys("AX\<c-x>\<c-u>\<cr>\<esc>", 'tnix') |
| 1012 | call assert_equal(['XJan', ''], getline(1, '$')) |
| 1013 | %d |
| 1014 | let g:special=-2 |
| 1015 | call feedkeys("AX\<c-x>\<c-u>\<cr>\<esc>", 'tnix') |
| 1016 | call assert_equal(['X', ''], getline(1, '$')) |
| 1017 | %d |
| 1018 | let g:special=-3 |
| 1019 | call feedkeys("AX\<c-x>\<c-u>\<cr>\<esc>", 'tnix') |
| 1020 | call assert_equal(['X', ''], getline(1, '$')) |
| 1021 | %d |
| 1022 | let g:special=0 |
| 1023 | call feedkeys("AM\<c-x>\<c-u>\<cr>\<esc>", 'tnix') |
| 1024 | call assert_equal(['Mar', ''], getline(1, '$')) |
| 1025 | %d |
| 1026 | call feedkeys("AM\<c-x>\<c-u>\<c-n>\<cr>\<esc>", 'tnix') |
| 1027 | call assert_equal(['May', ''], getline(1, '$')) |
| 1028 | %d |
| 1029 | call feedkeys("AM\<c-x>\<c-u>\<c-n>\<c-n>\<cr>\<esc>", 'tnix') |
| 1030 | call assert_equal(['M', ''], getline(1, '$')) |
| 1031 | delfu CompleteMonths |
| 1032 | %d |
| 1033 | try |
| 1034 | call feedkeys("A\<c-x>\<c-u>", 'tnix') |
| 1035 | call assert_fails(1, 'unknown completion function') |
| 1036 | catch /^Vim\%((\a\+)\)\=:E117/ |
| 1037 | call assert_true(1, 'E117 error caught') |
| 1038 | endtry |
| 1039 | set completefunc= |
| 1040 | bw! |
| 1041 | endfunc |
| 1042 | |
Bram Moolenaar | ff06f28 | 2020-04-21 22:01:14 +0200 | [diff] [blame] | 1043 | func Test_edit_completefunc_delete() |
| 1044 | func CompleteFunc(findstart, base) |
| 1045 | if a:findstart == 1 |
| 1046 | return col('.') - 1 |
| 1047 | endif |
| 1048 | normal dd |
| 1049 | return ['a', 'b'] |
| 1050 | endfunc |
| 1051 | new |
| 1052 | set completefunc=CompleteFunc |
| 1053 | call setline(1, ['', 'abcd', '']) |
| 1054 | 2d |
zeertzjq | cfe4565 | 2022-05-27 17:26:55 +0100 | [diff] [blame] | 1055 | call assert_fails("normal 2G$a\<C-X>\<C-U>", 'E565:') |
Bram Moolenaar | ff06f28 | 2020-04-21 22:01:14 +0200 | [diff] [blame] | 1056 | bwipe! |
| 1057 | endfunc |
| 1058 | |
| 1059 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 1060 | func Test_edit_CTRL_Z() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1061 | " Ctrl-Z when insertmode is not set inserts it literally |
| 1062 | new |
| 1063 | call setline(1, 'abc') |
| 1064 | call feedkeys("A\<c-z>\<esc>", 'tnix') |
| 1065 | call assert_equal(["abc\<c-z>"], getline(1,'$')) |
| 1066 | bw! |
| 1067 | " TODO: How to Test Ctrl-Z in insert mode, e.g. suspend? |
| 1068 | endfunc |
| 1069 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 1070 | func Test_edit_DROP() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 1071 | CheckFeature dnd |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1072 | new |
| 1073 | call setline(1, ['abc def ghi']) |
| 1074 | call cursor(1, 1) |
| 1075 | try |
| 1076 | call feedkeys("i\<Drop>\<Esc>", 'tnix') |
| 1077 | call assert_fails(1, 'Invalid register name') |
| 1078 | catch /^Vim\%((\a\+)\)\=:E353/ |
| 1079 | call assert_true(1, 'error caught') |
| 1080 | endtry |
| 1081 | bw! |
| 1082 | endfunc |
| 1083 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 1084 | func Test_edit_CTRL_V() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1085 | new |
| 1086 | call setline(1, ['abc']) |
| 1087 | call cursor(2, 1) |
zeertzjq | 502d8ae | 2022-01-24 15:27:50 +0000 | [diff] [blame] | 1088 | |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1089 | " force some redraws |
| 1090 | set showmode showcmd |
zeertzjq | 502d8ae | 2022-01-24 15:27:50 +0000 | [diff] [blame] | 1091 | call test_override('char_avail', 1) |
| 1092 | |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1093 | call feedkeys("A\<c-v>\<c-n>\<c-v>\<c-l>\<c-v>\<c-b>\<esc>", 'tnix') |
| 1094 | call assert_equal(["abc\x0e\x0c\x02"], getline(1, '$')) |
| 1095 | |
| 1096 | if has("rightleft") && exists("+rl") |
| 1097 | set rl |
| 1098 | call setline(1, ['abc']) |
| 1099 | call cursor(2, 1) |
| 1100 | call feedkeys("A\<c-v>\<c-n>\<c-v>\<c-l>\<c-v>\<c-b>\<esc>", 'tnix') |
| 1101 | call assert_equal(["abc\x0e\x0c\x02"], getline(1, '$')) |
| 1102 | set norl |
| 1103 | endif |
| 1104 | |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1105 | set noshowmode showcmd |
zeertzjq | 502d8ae | 2022-01-24 15:27:50 +0000 | [diff] [blame] | 1106 | call test_override('char_avail', 0) |
| 1107 | |
| 1108 | " No modifiers should be applied to the char typed using i_CTRL-V_digit. |
| 1109 | call feedkeys(":append\<CR>\<C-V>76c\<C-V>76\<C-F2>\<C-V>u3c0j\<C-V>u3c0\<M-F3>\<CR>.\<CR>", 'tnix') |
| 1110 | call assert_equal('LcL<C-F2>πjπ<M-F3>', getline(2)) |
| 1111 | |
| 1112 | if has('osx') |
| 1113 | " A char with a modifier should not be a valid char for i_CTRL-V_digit. |
| 1114 | call feedkeys("o\<C-V>\<D-j>\<C-V>\<D-1>\<C-V>\<D-o>\<C-V>\<D-x>\<C-V>\<D-u>", 'tnix') |
| 1115 | call assert_equal('<D-j><D-1><D-o><D-x><D-u>', getline(3)) |
| 1116 | endif |
| 1117 | |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1118 | bw! |
| 1119 | endfunc |
| 1120 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 1121 | func Test_edit_F1() |
Bram Moolenaar | 5a4c308 | 2019-12-01 15:23:11 +0100 | [diff] [blame] | 1122 | CheckFeature quickfix |
| 1123 | |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1124 | " Pressing <f1> |
| 1125 | new |
| 1126 | call feedkeys(":set im\<cr>\<f1>\<c-l>", 'tnix') |
| 1127 | set noinsertmode |
| 1128 | call assert_equal('help', &buftype) |
| 1129 | bw |
| 1130 | bw |
| 1131 | endfunc |
| 1132 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 1133 | func Test_edit_F21() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1134 | " Pressing <f21> |
| 1135 | " sends a netbeans command |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 1136 | CheckFeature netbeans_intg |
| 1137 | new |
| 1138 | " I have no idea what this is supposed to do :) |
| 1139 | call feedkeys("A\<F21>\<F1>\<esc>", 'tnix') |
| 1140 | bw |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1141 | endfunc |
| 1142 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 1143 | func Test_edit_HOME_END() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1144 | " Test Home/End Keys |
| 1145 | new |
| 1146 | set foldopen+=hor |
| 1147 | call setline(1, ['abc', 'def']) |
| 1148 | call cursor(1, 1) |
| 1149 | call feedkeys("AX\<Home>Y\<esc>", 'tnix') |
| 1150 | call cursor(2, 1) |
| 1151 | call feedkeys("iZ\<End>Y\<esc>", 'tnix') |
| 1152 | call assert_equal(['YabcX', 'ZdefY'], getline(1, '$')) |
| 1153 | |
| 1154 | set foldopen-=hor |
| 1155 | bw! |
| 1156 | endfunc |
| 1157 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 1158 | func Test_edit_INS() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1159 | " Test for Pressing <Insert> |
| 1160 | new |
| 1161 | call setline(1, ['abc', 'def']) |
| 1162 | call cursor(1, 1) |
| 1163 | call feedkeys("i\<Insert>ZYX>", 'tnix') |
| 1164 | call assert_equal(['ZYX>', 'def'], getline(1, '$')) |
| 1165 | call setline(1, ['abc', 'def']) |
| 1166 | call cursor(1, 1) |
| 1167 | call feedkeys("i\<Insert>Z\<Insert>YX>", 'tnix') |
| 1168 | call assert_equal(['ZYX>bc', 'def'], getline(1, '$')) |
| 1169 | bw! |
| 1170 | endfunc |
| 1171 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 1172 | func Test_edit_LEFT_RIGHT() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1173 | " Left, Shift-Left, Right, Shift-Right |
| 1174 | new |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1175 | call setline(1, ['abc def ghi', 'ABC DEF GHI', 'ZZZ YYY XXX']) |
| 1176 | let _ww=&ww |
| 1177 | set ww= |
| 1178 | call cursor(2, 1) |
| 1179 | call feedkeys("i\<left>\<esc>", 'tnix') |
| 1180 | call assert_equal([0, 2, 1, 0], getpos('.')) |
| 1181 | " Is this a bug, <s-left> does not respect whichwrap option |
| 1182 | call feedkeys("i\<s-left>\<esc>", 'tnix') |
| 1183 | call assert_equal([0, 1, 8, 0], getpos('.')) |
| 1184 | call feedkeys("i". repeat("\<s-left>", 3). "\<esc>", 'tnix') |
| 1185 | call assert_equal([0, 1, 1, 0], getpos('.')) |
| 1186 | call feedkeys("i\<right>\<esc>", 'tnix') |
| 1187 | call assert_equal([0, 1, 1, 0], getpos('.')) |
| 1188 | call feedkeys("i\<right>\<right>\<esc>", 'tnix') |
| 1189 | call assert_equal([0, 1, 2, 0], getpos('.')) |
| 1190 | call feedkeys("A\<right>\<esc>", 'tnix') |
| 1191 | call assert_equal([0, 1, 11, 0], getpos('.')) |
| 1192 | call feedkeys("A\<s-right>\<esc>", 'tnix') |
| 1193 | call assert_equal([0, 2, 1, 0], getpos('.')) |
| 1194 | call feedkeys("i\<s-right>\<esc>", 'tnix') |
| 1195 | call assert_equal([0, 2, 4, 0], getpos('.')) |
| 1196 | call cursor(3, 11) |
| 1197 | call feedkeys("A\<right>\<esc>", 'tnix') |
| 1198 | call feedkeys("A\<s-right>\<esc>", 'tnix') |
| 1199 | call assert_equal([0, 3, 11, 0], getpos('.')) |
| 1200 | call cursor(2, 11) |
| 1201 | " <S-Right> does not respect 'whichwrap' option |
| 1202 | call feedkeys("A\<s-right>\<esc>", 'tnix') |
| 1203 | call assert_equal([0, 3, 1, 0], getpos('.')) |
| 1204 | " Check motion when 'whichwrap' contains cursor keys for insert mode |
| 1205 | set ww+=[,] |
| 1206 | call cursor(2, 1) |
| 1207 | call feedkeys("i\<left>\<esc>", 'tnix') |
| 1208 | call assert_equal([0, 1, 11, 0], getpos('.')) |
| 1209 | call cursor(2, 11) |
| 1210 | call feedkeys("A\<right>\<esc>", 'tnix') |
| 1211 | call assert_equal([0, 3, 1, 0], getpos('.')) |
| 1212 | call cursor(2, 11) |
| 1213 | call feedkeys("A\<s-right>\<esc>", 'tnix') |
| 1214 | call assert_equal([0, 3, 1, 0], getpos('.')) |
| 1215 | let &ww = _ww |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1216 | bw! |
| 1217 | endfunc |
| 1218 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 1219 | func Test_edit_MOUSE() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1220 | " This is a simple test, since we not really using the mouse here |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 1221 | CheckFeature mouse |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1222 | 10new |
| 1223 | call setline(1, range(1, 100)) |
| 1224 | call cursor(1, 1) |
Bram Moolenaar | 8e8dc9b | 2022-05-08 20:38:06 +0100 | [diff] [blame] | 1225 | call assert_equal(1, line('w0')) |
| 1226 | call assert_equal(10, line('w$')) |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1227 | set mouse=a |
Bram Moolenaar | 8e8dc9b | 2022-05-08 20:38:06 +0100 | [diff] [blame] | 1228 | " One scroll event moves three lines. |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1229 | call feedkeys("A\<ScrollWheelDown>\<esc>", 'tnix') |
Bram Moolenaar | 8e8dc9b | 2022-05-08 20:38:06 +0100 | [diff] [blame] | 1230 | call assert_equal(4, line('w0')) |
| 1231 | call assert_equal(13, line('w$')) |
| 1232 | " This should move by one page down. |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1233 | call feedkeys("A\<S-ScrollWheelDown>\<esc>", 'tnix') |
Bram Moolenaar | 8e8dc9b | 2022-05-08 20:38:06 +0100 | [diff] [blame] | 1234 | call assert_equal(14, line('w0')) |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1235 | set nostartofline |
Bram Moolenaar | 8e8dc9b | 2022-05-08 20:38:06 +0100 | [diff] [blame] | 1236 | " Another page down. |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1237 | call feedkeys("A\<C-ScrollWheelDown>\<esc>", 'tnix') |
Bram Moolenaar | 8e8dc9b | 2022-05-08 20:38:06 +0100 | [diff] [blame] | 1238 | call assert_equal(24, line('w0')) |
| 1239 | |
| 1240 | call assert_equal([0, 24, 2, 0], getpos('.')) |
| 1241 | call test_setmouse(4, 3) |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1242 | call feedkeys("A\<LeftMouse>\<esc>", 'tnix') |
Bram Moolenaar | 8e8dc9b | 2022-05-08 20:38:06 +0100 | [diff] [blame] | 1243 | call assert_equal([0, 27, 2, 0], getpos('.')) |
Bram Moolenaar | b370771 | 2022-05-08 22:49:43 +0100 | [diff] [blame] | 1244 | set mousemodel=extend |
Bram Moolenaar | 8e8dc9b | 2022-05-08 20:38:06 +0100 | [diff] [blame] | 1245 | call test_setmouse(5, 3) |
| 1246 | call feedkeys("A\<RightMouse>\<esc>\<esc>", 'tnix') |
| 1247 | call assert_equal([0, 28, 2, 0], getpos('.')) |
Bram Moolenaar | b370771 | 2022-05-08 22:49:43 +0100 | [diff] [blame] | 1248 | set mousemodel& |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1249 | call cursor(1, 100) |
| 1250 | norm! zt |
| 1251 | " this should move by a screen up, but when the test |
| 1252 | " is run, it moves up to the top of the buffer... |
| 1253 | call feedkeys("A\<ScrollWheelUp>\<esc>", 'tnix') |
| 1254 | call assert_equal([0, 1, 1, 0], getpos('.')) |
| 1255 | call cursor(1, 30) |
| 1256 | norm! zt |
| 1257 | call feedkeys("A\<S-ScrollWheelUp>\<esc>", 'tnix') |
| 1258 | call assert_equal([0, 1, 1, 0], getpos('.')) |
| 1259 | call cursor(1, 30) |
| 1260 | norm! zt |
| 1261 | call feedkeys("A\<C-ScrollWheelUp>\<esc>", 'tnix') |
| 1262 | call assert_equal([0, 1, 1, 0], getpos('.')) |
| 1263 | %d |
| 1264 | call setline(1, repeat(["12345678901234567890"], 100)) |
| 1265 | call cursor(2, 1) |
| 1266 | call feedkeys("A\<ScrollWheelRight>\<esc>", 'tnix') |
| 1267 | call assert_equal([0, 2, 20, 0], getpos('.')) |
| 1268 | call feedkeys("A\<ScrollWheelLeft>\<esc>", 'tnix') |
| 1269 | call assert_equal([0, 2, 20, 0], getpos('.')) |
| 1270 | call feedkeys("A\<S-ScrollWheelRight>\<esc>", 'tnix') |
| 1271 | call assert_equal([0, 2, 20, 0], getpos('.')) |
| 1272 | call feedkeys("A\<S-ScrollWheelLeft>\<esc>", 'tnix') |
| 1273 | call assert_equal([0, 2, 20, 0], getpos('.')) |
| 1274 | call feedkeys("A\<C-ScrollWheelRight>\<esc>", 'tnix') |
| 1275 | call assert_equal([0, 2, 20, 0], getpos('.')) |
| 1276 | call feedkeys("A\<C-ScrollWheelLeft>\<esc>", 'tnix') |
| 1277 | call assert_equal([0, 2, 20, 0], getpos('.')) |
| 1278 | set mouse& startofline |
| 1279 | bw! |
| 1280 | endfunc |
| 1281 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 1282 | func Test_edit_PAGEUP_PAGEDOWN() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1283 | 10new |
| 1284 | call setline(1, repeat(['abc def ghi'], 30)) |
| 1285 | call cursor(1, 1) |
| 1286 | call feedkeys("i\<PageDown>\<esc>", 'tnix') |
| 1287 | call assert_equal([0, 9, 1, 0], getpos('.')) |
| 1288 | call feedkeys("i\<PageDown>\<esc>", 'tnix') |
| 1289 | call assert_equal([0, 17, 1, 0], getpos('.')) |
| 1290 | call feedkeys("i\<PageDown>\<esc>", 'tnix') |
| 1291 | call assert_equal([0, 25, 1, 0], getpos('.')) |
| 1292 | call feedkeys("i\<PageDown>\<esc>", 'tnix') |
| 1293 | call assert_equal([0, 30, 1, 0], getpos('.')) |
| 1294 | call feedkeys("i\<PageDown>\<esc>", 'tnix') |
| 1295 | call assert_equal([0, 30, 1, 0], getpos('.')) |
| 1296 | call feedkeys("A\<PageUp>\<esc>", 'tnix') |
| 1297 | call assert_equal([0, 29, 1, 0], getpos('.')) |
| 1298 | call feedkeys("A\<PageUp>\<esc>", 'tnix') |
| 1299 | call assert_equal([0, 21, 1, 0], getpos('.')) |
| 1300 | call feedkeys("A\<PageUp>\<esc>", 'tnix') |
| 1301 | call assert_equal([0, 13, 1, 0], getpos('.')) |
| 1302 | call feedkeys("A\<PageUp>\<esc>", 'tnix') |
| 1303 | call assert_equal([0, 5, 1, 0], getpos('.')) |
| 1304 | call feedkeys("A\<PageUp>\<esc>", 'tnix') |
| 1305 | call assert_equal([0, 5, 11, 0], getpos('.')) |
| 1306 | " <S-Up> is the same as <PageUp> |
| 1307 | " <S-Down> is the same as <PageDown> |
| 1308 | call cursor(1, 1) |
| 1309 | call feedkeys("i\<S-Down>\<esc>", 'tnix') |
| 1310 | call assert_equal([0, 9, 1, 0], getpos('.')) |
| 1311 | call feedkeys("i\<S-Down>\<esc>", 'tnix') |
| 1312 | call assert_equal([0, 17, 1, 0], getpos('.')) |
| 1313 | call feedkeys("i\<S-Down>\<esc>", 'tnix') |
| 1314 | call assert_equal([0, 25, 1, 0], getpos('.')) |
| 1315 | call feedkeys("i\<S-Down>\<esc>", 'tnix') |
| 1316 | call assert_equal([0, 30, 1, 0], getpos('.')) |
| 1317 | call feedkeys("i\<S-Down>\<esc>", 'tnix') |
| 1318 | call assert_equal([0, 30, 1, 0], getpos('.')) |
| 1319 | call feedkeys("A\<S-Up>\<esc>", 'tnix') |
| 1320 | call assert_equal([0, 29, 1, 0], getpos('.')) |
| 1321 | call feedkeys("A\<S-Up>\<esc>", 'tnix') |
| 1322 | call assert_equal([0, 21, 1, 0], getpos('.')) |
| 1323 | call feedkeys("A\<S-Up>\<esc>", 'tnix') |
| 1324 | call assert_equal([0, 13, 1, 0], getpos('.')) |
| 1325 | call feedkeys("A\<S-Up>\<esc>", 'tnix') |
| 1326 | call assert_equal([0, 5, 1, 0], getpos('.')) |
| 1327 | call feedkeys("A\<S-Up>\<esc>", 'tnix') |
| 1328 | call assert_equal([0, 5, 11, 0], getpos('.')) |
| 1329 | set nostartofline |
| 1330 | call cursor(30, 11) |
| 1331 | norm! zt |
| 1332 | call feedkeys("A\<PageUp>\<esc>", 'tnix') |
| 1333 | call assert_equal([0, 29, 11, 0], getpos('.')) |
| 1334 | call feedkeys("A\<PageUp>\<esc>", 'tnix') |
| 1335 | call assert_equal([0, 21, 11, 0], getpos('.')) |
| 1336 | call feedkeys("A\<PageUp>\<esc>", 'tnix') |
| 1337 | call assert_equal([0, 13, 11, 0], getpos('.')) |
| 1338 | call feedkeys("A\<PageUp>\<esc>", 'tnix') |
| 1339 | call assert_equal([0, 5, 11, 0], getpos('.')) |
| 1340 | call feedkeys("A\<PageUp>\<esc>", 'tnix') |
| 1341 | call assert_equal([0, 5, 11, 0], getpos('.')) |
| 1342 | call cursor(1, 1) |
| 1343 | call feedkeys("A\<PageDown>\<esc>", 'tnix') |
| 1344 | call assert_equal([0, 9, 11, 0], getpos('.')) |
| 1345 | call feedkeys("A\<PageDown>\<esc>", 'tnix') |
| 1346 | call assert_equal([0, 17, 11, 0], getpos('.')) |
| 1347 | call feedkeys("A\<PageDown>\<esc>", 'tnix') |
| 1348 | call assert_equal([0, 25, 11, 0], getpos('.')) |
| 1349 | call feedkeys("A\<PageDown>\<esc>", 'tnix') |
| 1350 | call assert_equal([0, 30, 11, 0], getpos('.')) |
| 1351 | call feedkeys("A\<PageDown>\<esc>", 'tnix') |
| 1352 | call assert_equal([0, 30, 11, 0], getpos('.')) |
| 1353 | " <S-Up> is the same as <PageUp> |
| 1354 | " <S-Down> is the same as <PageDown> |
| 1355 | call cursor(30, 11) |
| 1356 | norm! zt |
| 1357 | call feedkeys("A\<S-Up>\<esc>", 'tnix') |
| 1358 | call assert_equal([0, 29, 11, 0], getpos('.')) |
| 1359 | call feedkeys("A\<S-Up>\<esc>", 'tnix') |
| 1360 | call assert_equal([0, 21, 11, 0], getpos('.')) |
| 1361 | call feedkeys("A\<S-Up>\<esc>", 'tnix') |
| 1362 | call assert_equal([0, 13, 11, 0], getpos('.')) |
| 1363 | call feedkeys("A\<S-Up>\<esc>", 'tnix') |
| 1364 | call assert_equal([0, 5, 11, 0], getpos('.')) |
| 1365 | call feedkeys("A\<S-Up>\<esc>", 'tnix') |
| 1366 | call assert_equal([0, 5, 11, 0], getpos('.')) |
| 1367 | call cursor(1, 1) |
| 1368 | call feedkeys("A\<S-Down>\<esc>", 'tnix') |
| 1369 | call assert_equal([0, 9, 11, 0], getpos('.')) |
| 1370 | call feedkeys("A\<S-Down>\<esc>", 'tnix') |
| 1371 | call assert_equal([0, 17, 11, 0], getpos('.')) |
| 1372 | call feedkeys("A\<S-Down>\<esc>", 'tnix') |
| 1373 | call assert_equal([0, 25, 11, 0], getpos('.')) |
| 1374 | call feedkeys("A\<S-Down>\<esc>", 'tnix') |
| 1375 | call assert_equal([0, 30, 11, 0], getpos('.')) |
| 1376 | call feedkeys("A\<S-Down>\<esc>", 'tnix') |
| 1377 | call assert_equal([0, 30, 11, 0], getpos('.')) |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1378 | bw! |
| 1379 | endfunc |
| 1380 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 1381 | func Test_edit_forbidden() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1382 | new |
| 1383 | " 1) edit in the sandbox is not allowed |
| 1384 | call setline(1, 'a') |
| 1385 | com! Sandbox :sandbox call feedkeys("i\<del>\<esc>", 'tnix') |
| 1386 | call assert_fails(':Sandbox', 'E48:') |
| 1387 | com! Sandbox :sandbox exe "norm! i\<del>" |
| 1388 | call assert_fails(':Sandbox', 'E48:') |
| 1389 | delcom Sandbox |
| 1390 | call assert_equal(['a'], getline(1,'$')) |
Bram Moolenaar | 52797ba | 2021-12-16 14:45:13 +0000 | [diff] [blame] | 1391 | |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1392 | " 2) edit with textlock set |
| 1393 | fu! DoIt() |
| 1394 | call feedkeys("i\<del>\<esc>", 'tnix') |
| 1395 | endfu |
| 1396 | au InsertCharPre <buffer> :call DoIt() |
| 1397 | try |
| 1398 | call feedkeys("ix\<esc>", 'tnix') |
| 1399 | call assert_fails(1, 'textlock') |
Bram Moolenaar | ff06f28 | 2020-04-21 22:01:14 +0200 | [diff] [blame] | 1400 | catch /^Vim\%((\a\+)\)\=:E565/ " catch E565: not allowed here |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1401 | endtry |
| 1402 | " TODO: Might be a bug: should x really be inserted here |
| 1403 | call assert_equal(['xa'], getline(1, '$')) |
| 1404 | delfu DoIt |
| 1405 | try |
| 1406 | call feedkeys("ix\<esc>", 'tnix') |
| 1407 | call assert_fails(1, 'unknown function') |
| 1408 | catch /^Vim\%((\a\+)\)\=:E117/ " catch E117: unknown function |
| 1409 | endtry |
| 1410 | au! InsertCharPre |
Bram Moolenaar | 52797ba | 2021-12-16 14:45:13 +0000 | [diff] [blame] | 1411 | |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1412 | " 3) edit when completion is shown |
| 1413 | fun! Complete(findstart, base) |
| 1414 | if a:findstart |
| 1415 | return col('.') |
| 1416 | else |
| 1417 | call feedkeys("i\<del>\<esc>", 'tnix') |
| 1418 | return [] |
| 1419 | endif |
| 1420 | endfun |
| 1421 | set completefunc=Complete |
| 1422 | try |
| 1423 | call feedkeys("i\<c-x>\<c-u>\<esc>", 'tnix') |
| 1424 | call assert_fails(1, 'change in complete function') |
Bram Moolenaar | ff06f28 | 2020-04-21 22:01:14 +0200 | [diff] [blame] | 1425 | catch /^Vim\%((\a\+)\)\=:E565/ " catch E565 |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1426 | endtry |
| 1427 | delfu Complete |
| 1428 | set completefunc= |
Bram Moolenaar | 52797ba | 2021-12-16 14:45:13 +0000 | [diff] [blame] | 1429 | |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1430 | if has("rightleft") && exists("+fkmap") |
| 1431 | " 4) 'R' when 'fkmap' and 'revins' is set. |
| 1432 | set revins fkmap |
| 1433 | try |
| 1434 | normal Ri |
| 1435 | call assert_fails(1, "R with 'fkmap' and 'ri' set") |
| 1436 | catch |
| 1437 | finally |
| 1438 | set norevins nofkmap |
| 1439 | endtry |
| 1440 | endif |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1441 | bw! |
| 1442 | endfunc |
| 1443 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 1444 | func Test_edit_rightleft() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1445 | " Cursor in rightleft mode moves differently |
Bram Moolenaar | 845e0ee | 2020-06-20 16:05:32 +0200 | [diff] [blame] | 1446 | CheckFeature rightleft |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1447 | call NewWindow(10, 20) |
| 1448 | call setline(1, ['abc', 'def', 'ghi']) |
| 1449 | call cursor(1, 2) |
| 1450 | set rightleft |
| 1451 | " Screen looks as expected |
| 1452 | let lines = ScreenLines([1, 4], winwidth(0)) |
| 1453 | let expect = [ |
| 1454 | \" cba", |
| 1455 | \" fed", |
| 1456 | \" ihg", |
| 1457 | \" ~"] |
| 1458 | call assert_equal(join(expect, "\n"), join(lines, "\n")) |
| 1459 | " 2) right moves to the left |
| 1460 | call feedkeys("i\<right>\<esc>x", 'txin') |
| 1461 | call assert_equal(['bc', 'def', 'ghi'], getline(1,'$')) |
| 1462 | call cursor(1, 2) |
| 1463 | call feedkeys("i\<s-right>\<esc>", 'txin') |
| 1464 | call cursor(1, 2) |
| 1465 | call feedkeys("i\<c-right>\<esc>", 'txin') |
| 1466 | " Screen looks as expected |
| 1467 | let lines = ScreenLines([1, 4], winwidth(0)) |
| 1468 | let expect = [ |
| 1469 | \" cb", |
| 1470 | \" fed", |
| 1471 | \" ihg", |
| 1472 | \" ~"] |
| 1473 | call assert_equal(join(expect, "\n"), join(lines, "\n")) |
| 1474 | " 2) left moves to the right |
| 1475 | call setline(1, ['abc', 'def', 'ghi']) |
| 1476 | call cursor(1, 2) |
| 1477 | call feedkeys("i\<left>\<esc>x", 'txin') |
| 1478 | call assert_equal(['ac', 'def', 'ghi'], getline(1,'$')) |
| 1479 | call cursor(1, 2) |
| 1480 | call feedkeys("i\<s-left>\<esc>", 'txin') |
| 1481 | call cursor(1, 2) |
| 1482 | call feedkeys("i\<c-left>\<esc>", 'txin') |
| 1483 | " Screen looks as expected |
| 1484 | let lines = ScreenLines([1, 4], winwidth(0)) |
| 1485 | let expect = [ |
| 1486 | \" ca", |
| 1487 | \" fed", |
| 1488 | \" ihg", |
| 1489 | \" ~"] |
| 1490 | call assert_equal(join(expect, "\n"), join(lines, "\n")) |
Bram Moolenaar | 845e0ee | 2020-06-20 16:05:32 +0200 | [diff] [blame] | 1491 | %d _ |
| 1492 | call test_override('redraw_flag', 1) |
| 1493 | call test_override('char_avail', 1) |
| 1494 | call feedkeys("a\<C-V>x41", "xt") |
| 1495 | redraw! |
| 1496 | call assert_equal(repeat(' ', 19) .. 'A', Screenline(1)) |
| 1497 | call test_override('ALL', 0) |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1498 | set norightleft |
| 1499 | bw! |
| 1500 | endfunc |
Bram Moolenaar | 658a3a2 | 2017-03-31 22:27:12 +0200 | [diff] [blame] | 1501 | |
| 1502 | func Test_edit_complete_very_long_name() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 1503 | " Long directory names only work on Unix. |
| 1504 | CheckUnix |
Bram Moolenaar | 15ecbd6 | 2017-04-07 14:10:48 +0200 | [diff] [blame] | 1505 | |
Bram Moolenaar | 3b0d70f | 2022-08-29 22:31:20 +0100 | [diff] [blame] | 1506 | let dirname = getcwd() . "/Xlongdir" |
Bram Moolenaar | 15ecbd6 | 2017-04-07 14:10:48 +0200 | [diff] [blame] | 1507 | let longdirname = dirname . repeat('/' . repeat('d', 255), 4) |
| 1508 | try |
Bram Moolenaar | 14f9176 | 2022-09-21 15:13:52 +0100 | [diff] [blame] | 1509 | call mkdir(longdirname, 'pR') |
Bram Moolenaar | 15ecbd6 | 2017-04-07 14:10:48 +0200 | [diff] [blame] | 1510 | catch /E739:/ |
| 1511 | " Long directory name probably not supported. |
| 1512 | call delete(dirname, 'rf') |
| 1513 | return |
| 1514 | endtry |
| 1515 | |
Bram Moolenaar | f8191c5 | 2019-05-18 17:22:54 +0200 | [diff] [blame] | 1516 | " Try to get the Vim window position before setting 'columns', so that we can |
| 1517 | " move the window back to where it was. |
Bram Moolenaar | ba6ec18 | 2017-04-04 22:41:10 +0200 | [diff] [blame] | 1518 | let winposx = getwinposx() |
| 1519 | let winposy = getwinposy() |
Bram Moolenaar | f8191c5 | 2019-05-18 17:22:54 +0200 | [diff] [blame] | 1520 | |
| 1521 | if winposx >= 0 && winposy >= 0 && !has('gui_running') |
| 1522 | " We did get the window position, but xterm may report the wrong numbers. |
| 1523 | " Move the window to the reported position and compute any offset. |
| 1524 | exe 'winpos ' . winposx . ' ' . winposy |
| 1525 | sleep 100m |
| 1526 | let x = getwinposx() |
| 1527 | if x >= 0 |
| 1528 | let winposx += winposx - x |
| 1529 | endif |
| 1530 | let y = getwinposy() |
| 1531 | if y >= 0 |
| 1532 | let winposy += winposy - y |
| 1533 | endif |
| 1534 | endif |
| 1535 | |
Bram Moolenaar | 658a3a2 | 2017-03-31 22:27:12 +0200 | [diff] [blame] | 1536 | let save_columns = &columns |
Bram Moolenaar | 15ecbd6 | 2017-04-07 14:10:48 +0200 | [diff] [blame] | 1537 | " Need at least about 1100 columns to reproduce the problem. |
Bram Moolenaar | ba6ec18 | 2017-04-04 22:41:10 +0200 | [diff] [blame] | 1538 | set columns=2000 |
Bram Moolenaar | 658a3a2 | 2017-03-31 22:27:12 +0200 | [diff] [blame] | 1539 | set noswapfile |
Bram Moolenaar | ba6ec18 | 2017-04-04 22:41:10 +0200 | [diff] [blame] | 1540 | |
Bram Moolenaar | 658a3a2 | 2017-03-31 22:27:12 +0200 | [diff] [blame] | 1541 | let longfilename = longdirname . '/' . repeat('a', 255) |
Bram Moolenaar | 658a3a2 | 2017-03-31 22:27:12 +0200 | [diff] [blame] | 1542 | call writefile(['Totum', 'Table'], longfilename) |
| 1543 | new |
Bram Moolenaar | 61abe7d | 2022-08-30 21:46:08 +0100 | [diff] [blame] | 1544 | exe "next Xnofile " . longfilename |
Bram Moolenaar | 658a3a2 | 2017-03-31 22:27:12 +0200 | [diff] [blame] | 1545 | exe "normal iT\<C-N>" |
| 1546 | |
| 1547 | bwipe! |
| 1548 | exe 'bwipe! ' . longfilename |
Bram Moolenaar | 658a3a2 | 2017-03-31 22:27:12 +0200 | [diff] [blame] | 1549 | let &columns = save_columns |
Bram Moolenaar | ba6ec18 | 2017-04-04 22:41:10 +0200 | [diff] [blame] | 1550 | if winposx >= 0 && winposy >= 0 |
| 1551 | exe 'winpos ' . winposx . ' ' . winposy |
| 1552 | endif |
Bram Moolenaar | 658a3a2 | 2017-03-31 22:27:12 +0200 | [diff] [blame] | 1553 | set swapfile& |
| 1554 | endfunc |
Bram Moolenaar | ff930ca | 2017-10-19 17:12:10 +0200 | [diff] [blame] | 1555 | |
Bram Moolenaar | 2c8c681 | 2018-07-28 17:07:52 +0200 | [diff] [blame] | 1556 | func Test_edit_backtick() |
| 1557 | next a\`b c |
| 1558 | call assert_equal('a`b', expand('%')) |
| 1559 | next |
| 1560 | call assert_equal('c', expand('%')) |
| 1561 | call assert_equal('a\`b c', expand('##')) |
| 1562 | endfunc |
| 1563 | |
Bram Moolenaar | ff930ca | 2017-10-19 17:12:10 +0200 | [diff] [blame] | 1564 | func Test_edit_quit() |
| 1565 | edit foo.txt |
| 1566 | split |
| 1567 | new |
| 1568 | call setline(1, 'hello') |
| 1569 | 3wincmd w |
| 1570 | redraw! |
| 1571 | call assert_fails('1q', 'E37:') |
| 1572 | bwipe! foo.txt |
| 1573 | only |
| 1574 | endfunc |
| 1575 | |
Bram Moolenaar | adb8fbe | 2018-06-04 20:34:23 +0200 | [diff] [blame] | 1576 | func Test_edit_alt() |
| 1577 | " Keeping the cursor line didn't happen when the first line has indent. |
| 1578 | new |
| 1579 | call setline(1, [' one', 'two', 'three']) |
| 1580 | w XAltFile |
| 1581 | $ |
| 1582 | call assert_equal(3, line('.')) |
| 1583 | e Xother |
| 1584 | e # |
| 1585 | call assert_equal(3, line('.')) |
| 1586 | |
| 1587 | bwipe XAltFile |
| 1588 | call delete('XAltFile') |
| 1589 | endfunc |
Bram Moolenaar | 4dbc262 | 2018-11-02 11:59:15 +0100 | [diff] [blame] | 1590 | |
Bram Moolenaar | db93495 | 2020-04-27 20:18:31 +0200 | [diff] [blame] | 1591 | func Test_edit_InsertLeave() |
Bram Moolenaar | 4dbc262 | 2018-11-02 11:59:15 +0100 | [diff] [blame] | 1592 | new |
Bram Moolenaar | b53e13a | 2020-10-21 12:19:53 +0200 | [diff] [blame] | 1593 | au InsertLeavePre * let g:did_au_pre = 1 |
Bram Moolenaar | 4dbc262 | 2018-11-02 11:59:15 +0100 | [diff] [blame] | 1594 | au InsertLeave * let g:did_au = 1 |
Bram Moolenaar | b53e13a | 2020-10-21 12:19:53 +0200 | [diff] [blame] | 1595 | let g:did_au_pre = 0 |
Bram Moolenaar | 4dbc262 | 2018-11-02 11:59:15 +0100 | [diff] [blame] | 1596 | let g:did_au = 0 |
| 1597 | call feedkeys("afoo\<Esc>", 'tx') |
Bram Moolenaar | b53e13a | 2020-10-21 12:19:53 +0200 | [diff] [blame] | 1598 | call assert_equal(1, g:did_au_pre) |
Bram Moolenaar | 4dbc262 | 2018-11-02 11:59:15 +0100 | [diff] [blame] | 1599 | call assert_equal(1, g:did_au) |
| 1600 | call assert_equal('foo', getline(1)) |
| 1601 | |
Bram Moolenaar | b53e13a | 2020-10-21 12:19:53 +0200 | [diff] [blame] | 1602 | let g:did_au_pre = 0 |
Bram Moolenaar | 4dbc262 | 2018-11-02 11:59:15 +0100 | [diff] [blame] | 1603 | let g:did_au = 0 |
| 1604 | call feedkeys("Sbar\<C-C>", 'tx') |
Bram Moolenaar | b53e13a | 2020-10-21 12:19:53 +0200 | [diff] [blame] | 1605 | call assert_equal(1, g:did_au_pre) |
Bram Moolenaar | 4dbc262 | 2018-11-02 11:59:15 +0100 | [diff] [blame] | 1606 | call assert_equal(0, g:did_au) |
| 1607 | call assert_equal('bar', getline(1)) |
| 1608 | |
| 1609 | inoremap x xx<Esc> |
Bram Moolenaar | b53e13a | 2020-10-21 12:19:53 +0200 | [diff] [blame] | 1610 | let g:did_au_pre = 0 |
Bram Moolenaar | 4dbc262 | 2018-11-02 11:59:15 +0100 | [diff] [blame] | 1611 | let g:did_au = 0 |
| 1612 | call feedkeys("Saax", 'tx') |
Bram Moolenaar | b53e13a | 2020-10-21 12:19:53 +0200 | [diff] [blame] | 1613 | call assert_equal(1, g:did_au_pre) |
Bram Moolenaar | 4dbc262 | 2018-11-02 11:59:15 +0100 | [diff] [blame] | 1614 | call assert_equal(1, g:did_au) |
| 1615 | call assert_equal('aaxx', getline(1)) |
| 1616 | |
| 1617 | inoremap x xx<C-C> |
Bram Moolenaar | b53e13a | 2020-10-21 12:19:53 +0200 | [diff] [blame] | 1618 | let g:did_au_pre = 0 |
Bram Moolenaar | 4dbc262 | 2018-11-02 11:59:15 +0100 | [diff] [blame] | 1619 | let g:did_au = 0 |
| 1620 | call feedkeys("Sbbx", 'tx') |
Bram Moolenaar | b53e13a | 2020-10-21 12:19:53 +0200 | [diff] [blame] | 1621 | call assert_equal(1, g:did_au_pre) |
Bram Moolenaar | 4dbc262 | 2018-11-02 11:59:15 +0100 | [diff] [blame] | 1622 | call assert_equal(0, g:did_au) |
| 1623 | call assert_equal('bbxx', getline(1)) |
| 1624 | |
| 1625 | bwipe! |
Bram Moolenaar | b53e13a | 2020-10-21 12:19:53 +0200 | [diff] [blame] | 1626 | au! InsertLeave InsertLeavePre |
Bram Moolenaar | 4dbc262 | 2018-11-02 11:59:15 +0100 | [diff] [blame] | 1627 | iunmap x |
| 1628 | endfunc |
Bram Moolenaar | c6b37db | 2019-04-27 18:00:34 +0200 | [diff] [blame] | 1629 | |
Bram Moolenaar | db93495 | 2020-04-27 20:18:31 +0200 | [diff] [blame] | 1630 | func Test_edit_InsertLeave_undo() |
| 1631 | new XtestUndo |
| 1632 | set undofile |
| 1633 | au InsertLeave * wall |
| 1634 | exe "normal ofoo\<Esc>" |
| 1635 | call assert_equal(2, line('$')) |
| 1636 | normal u |
| 1637 | call assert_equal(1, line('$')) |
| 1638 | |
| 1639 | bwipe! |
| 1640 | au! InsertLeave |
| 1641 | call delete('XtestUndo') |
Bram Moolenaar | b340bae | 2020-06-15 19:51:56 +0200 | [diff] [blame] | 1642 | call delete(undofile('XtestUndo')) |
Bram Moolenaar | db93495 | 2020-04-27 20:18:31 +0200 | [diff] [blame] | 1643 | set undofile& |
| 1644 | endfunc |
| 1645 | |
Bram Moolenaar | c6b37db | 2019-04-27 18:00:34 +0200 | [diff] [blame] | 1646 | " Test for inserting characters using CTRL-V followed by a number. |
| 1647 | func Test_edit_special_chars() |
| 1648 | new |
| 1649 | |
Bram Moolenaar | 424bcae | 2022-01-31 14:59:41 +0000 | [diff] [blame] | 1650 | let t = "o\<C-V>65\<C-V>x42\<C-V>o103 \<C-V>33a\<C-V>xfg\<C-V>o78\<Esc>" |
Bram Moolenaar | c6b37db | 2019-04-27 18:00:34 +0200 | [diff] [blame] | 1651 | |
| 1652 | exe "normal " . t |
| 1653 | call assert_equal("ABC !a\<C-O>g\<C-G>8", getline(2)) |
| 1654 | |
| 1655 | close! |
| 1656 | endfunc |
Bram Moolenaar | 8d3b510 | 2019-09-05 21:29:01 +0200 | [diff] [blame] | 1657 | |
| 1658 | func Test_edit_startinsert() |
| 1659 | new |
| 1660 | set backspace+=start |
| 1661 | call setline(1, 'foobar') |
| 1662 | call feedkeys("A\<C-U>\<Esc>", 'xt') |
| 1663 | call assert_equal('', getline(1)) |
| 1664 | |
| 1665 | call setline(1, 'foobar') |
| 1666 | call feedkeys(":startinsert!\<CR>\<C-U>\<Esc>", 'xt') |
| 1667 | call assert_equal('', getline(1)) |
| 1668 | |
| 1669 | set backspace& |
| 1670 | bwipe! |
| 1671 | endfunc |
Bram Moolenaar | 177c9f2 | 2019-11-06 13:59:16 +0100 | [diff] [blame] | 1672 | |
Bram Moolenaar | bc2b71d | 2020-02-17 21:33:30 +0100 | [diff] [blame] | 1673 | " Test for :startreplace and :startgreplace |
| 1674 | func Test_edit_startreplace() |
| 1675 | new |
| 1676 | call setline(1, 'abc') |
| 1677 | call feedkeys("l:startreplace\<CR>xyz\e", 'xt') |
| 1678 | call assert_equal('axyz', getline(1)) |
| 1679 | call feedkeys("0:startreplace!\<CR>abc\e", 'xt') |
| 1680 | call assert_equal('axyzabc', getline(1)) |
| 1681 | call setline(1, "a\tb") |
| 1682 | call feedkeys("0l:startgreplace\<CR>xyz\e", 'xt') |
| 1683 | call assert_equal("axyz\tb", getline(1)) |
| 1684 | call feedkeys("0i\<C-R>=execute('startreplace')\<CR>12\e", 'xt') |
| 1685 | call assert_equal("12axyz\tb", getline(1)) |
| 1686 | close! |
| 1687 | endfunc |
| 1688 | |
Bram Moolenaar | 177c9f2 | 2019-11-06 13:59:16 +0100 | [diff] [blame] | 1689 | func Test_edit_noesckeys() |
Bram Moolenaar | 215ba3b | 2019-11-06 15:07:07 +0100 | [diff] [blame] | 1690 | CheckNotGui |
Bram Moolenaar | 177c9f2 | 2019-11-06 13:59:16 +0100 | [diff] [blame] | 1691 | new |
| 1692 | |
| 1693 | " <Left> moves cursor when 'esckeys' is set |
| 1694 | exe "set t_kl=\<Esc>OD" |
| 1695 | set esckeys |
| 1696 | call feedkeys("axyz\<Esc>ODX", "xt") |
| 1697 | call assert_equal("xyXz", getline(1)) |
| 1698 | |
| 1699 | " <Left> exits Insert mode when 'esckeys' is off |
| 1700 | set noesckeys |
| 1701 | call setline(1, '') |
| 1702 | call feedkeys("axyz\<Esc>ODX", "xt") |
| 1703 | call assert_equal(["DX", "xyz"], getline(1, 2)) |
| 1704 | |
| 1705 | bwipe! |
| 1706 | set esckeys |
| 1707 | endfunc |
Bram Moolenaar | bc2b71d | 2020-02-17 21:33:30 +0100 | [diff] [blame] | 1708 | |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 1709 | " Test for running an invalid ex command in insert mode using CTRL-O |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 1710 | func Test_edit_ctrl_o_invalid_cmd() |
| 1711 | new |
| 1712 | set showmode showcmd |
Bram Moolenaar | b340bae | 2020-06-15 19:51:56 +0200 | [diff] [blame] | 1713 | " Avoid a sleep of 3 seconds. Zero might have side effects. |
| 1714 | call test_override('ui_delay', 50) |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 1715 | let caught_e492 = 0 |
| 1716 | try |
| 1717 | call feedkeys("i\<C-O>:invalid\<CR>abc\<Esc>", "xt") |
| 1718 | catch /E492:/ |
| 1719 | let caught_e492 = 1 |
| 1720 | endtry |
| 1721 | call assert_equal(1, caught_e492) |
| 1722 | call assert_equal('abc', getline(1)) |
| 1723 | set showmode& showcmd& |
Bram Moolenaar | b340bae | 2020-06-15 19:51:56 +0200 | [diff] [blame] | 1724 | call test_override('ui_delay', 0) |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 1725 | close! |
| 1726 | endfunc |
| 1727 | |
Bram Moolenaar | b340bae | 2020-06-15 19:51:56 +0200 | [diff] [blame] | 1728 | " Test for editing a file with a very long name |
| 1729 | func Test_edit_illegal_filename() |
| 1730 | CheckEnglish |
| 1731 | new |
| 1732 | redir => msg |
| 1733 | exe 'edit ' . repeat('f', 5000) |
| 1734 | redir END |
| 1735 | call assert_match("Illegal file name$", split(msg, "\n")[0]) |
| 1736 | close! |
| 1737 | endfunc |
| 1738 | |
Bram Moolenaar | c8fe645 | 2020-10-03 17:04:37 +0200 | [diff] [blame] | 1739 | " Test for editing a directory |
| 1740 | func Test_edit_is_a_directory() |
| 1741 | CheckEnglish |
Bram Moolenaar | 3b0d70f | 2022-08-29 22:31:20 +0100 | [diff] [blame] | 1742 | let dirname = getcwd() . "/Xeditdir" |
Bram Moolenaar | c8fe645 | 2020-10-03 17:04:37 +0200 | [diff] [blame] | 1743 | call mkdir(dirname, 'p') |
| 1744 | |
| 1745 | new |
| 1746 | redir => msg |
| 1747 | exe 'edit' dirname |
| 1748 | redir END |
| 1749 | call assert_match("is a directory$", split(msg, "\n")[0]) |
| 1750 | bwipe! |
| 1751 | |
| 1752 | let dirname .= '/' |
| 1753 | |
| 1754 | new |
| 1755 | redir => msg |
| 1756 | exe 'edit' dirname |
| 1757 | redir END |
| 1758 | call assert_match("is a directory$", split(msg, "\n")[0]) |
| 1759 | bwipe! |
| 1760 | |
| 1761 | call delete(dirname, 'rf') |
| 1762 | endfunc |
| 1763 | |
Bram Moolenaar | b340bae | 2020-06-15 19:51:56 +0200 | [diff] [blame] | 1764 | " Test for editing a file using invalid file encoding |
| 1765 | func Test_edit_invalid_encoding() |
| 1766 | CheckEnglish |
Bram Moolenaar | 14f9176 | 2022-09-21 15:13:52 +0100 | [diff] [blame] | 1767 | call writefile([], 'Xinvfile', 'D') |
Bram Moolenaar | b340bae | 2020-06-15 19:51:56 +0200 | [diff] [blame] | 1768 | redir => msg |
Bram Moolenaar | 61abe7d | 2022-08-30 21:46:08 +0100 | [diff] [blame] | 1769 | new ++enc=axbyc Xinvfile |
Bram Moolenaar | b340bae | 2020-06-15 19:51:56 +0200 | [diff] [blame] | 1770 | redir END |
| 1771 | call assert_match('\[NOT converted\]', msg) |
Bram Moolenaar | b340bae | 2020-06-15 19:51:56 +0200 | [diff] [blame] | 1772 | close! |
| 1773 | endfunc |
| 1774 | |
| 1775 | " Test for the "charconvert" option |
| 1776 | func Test_edit_charconvert() |
| 1777 | CheckEnglish |
Bram Moolenaar | 14f9176 | 2022-09-21 15:13:52 +0100 | [diff] [blame] | 1778 | call writefile(['one', 'two'], 'Xccfile', 'D') |
Bram Moolenaar | b340bae | 2020-06-15 19:51:56 +0200 | [diff] [blame] | 1779 | |
| 1780 | " set 'charconvert' to a non-existing function |
| 1781 | set charconvert=NonExitingFunc() |
| 1782 | new |
| 1783 | let caught_e117 = v:false |
| 1784 | try |
| 1785 | redir => msg |
Bram Moolenaar | 61abe7d | 2022-08-30 21:46:08 +0100 | [diff] [blame] | 1786 | edit ++enc=axbyc Xccfile |
Bram Moolenaar | b340bae | 2020-06-15 19:51:56 +0200 | [diff] [blame] | 1787 | catch /E117:/ |
| 1788 | let caught_e117 = v:true |
| 1789 | finally |
| 1790 | redir END |
| 1791 | endtry |
| 1792 | call assert_true(caught_e117) |
| 1793 | call assert_equal(['one', 'two'], getline(1, '$')) |
| 1794 | call assert_match("Conversion with 'charconvert' failed", msg) |
| 1795 | close! |
| 1796 | set charconvert& |
| 1797 | |
| 1798 | " 'charconvert' function doesn't create a output file |
| 1799 | func Cconv1() |
| 1800 | endfunc |
| 1801 | set charconvert=Cconv1() |
| 1802 | new |
| 1803 | redir => msg |
Bram Moolenaar | 61abe7d | 2022-08-30 21:46:08 +0100 | [diff] [blame] | 1804 | edit ++enc=axbyc Xccfile |
Bram Moolenaar | b340bae | 2020-06-15 19:51:56 +0200 | [diff] [blame] | 1805 | redir END |
| 1806 | call assert_equal(['one', 'two'], getline(1, '$')) |
| 1807 | call assert_match("can't read output of 'charconvert'", msg) |
| 1808 | close! |
| 1809 | delfunc Cconv1 |
| 1810 | set charconvert& |
| 1811 | |
| 1812 | " 'charconvert' function to convert to upper case |
| 1813 | func Cconv2() |
| 1814 | let data = readfile(v:fname_in) |
| 1815 | call map(data, 'toupper(v:val)') |
| 1816 | call writefile(data, v:fname_out) |
| 1817 | endfunc |
| 1818 | set charconvert=Cconv2() |
Bram Moolenaar | 61abe7d | 2022-08-30 21:46:08 +0100 | [diff] [blame] | 1819 | new Xccfile |
| 1820 | write ++enc=ucase Xccfile1 |
| 1821 | call assert_equal(['ONE', 'TWO'], readfile('Xccfile1')) |
| 1822 | call delete('Xccfile1') |
Bram Moolenaar | b340bae | 2020-06-15 19:51:56 +0200 | [diff] [blame] | 1823 | close! |
| 1824 | delfunc Cconv2 |
| 1825 | set charconvert& |
| 1826 | |
| 1827 | " 'charconvert' function removes the input file |
| 1828 | func Cconv3() |
| 1829 | call delete(v:fname_in) |
| 1830 | endfunc |
| 1831 | set charconvert=Cconv3() |
| 1832 | new |
Bram Moolenaar | 61abe7d | 2022-08-30 21:46:08 +0100 | [diff] [blame] | 1833 | call assert_fails('edit ++enc=lcase Xccfile', 'E202:') |
Bram Moolenaar | b340bae | 2020-06-15 19:51:56 +0200 | [diff] [blame] | 1834 | call assert_equal([''], getline(1, '$')) |
| 1835 | close! |
| 1836 | delfunc Cconv3 |
| 1837 | set charconvert& |
Bram Moolenaar | b340bae | 2020-06-15 19:51:56 +0200 | [diff] [blame] | 1838 | endfunc |
| 1839 | |
| 1840 | " Test for editing a file without read permission |
| 1841 | func Test_edit_file_no_read_perm() |
| 1842 | CheckUnix |
Bram Moolenaar | 17709e2 | 2021-03-19 14:38:12 +0100 | [diff] [blame] | 1843 | CheckNotRoot |
| 1844 | |
Bram Moolenaar | 14f9176 | 2022-09-21 15:13:52 +0100 | [diff] [blame] | 1845 | call writefile(['one', 'two'], 'Xnrpfile', 'D') |
Bram Moolenaar | 61abe7d | 2022-08-30 21:46:08 +0100 | [diff] [blame] | 1846 | call setfperm('Xnrpfile', '-w-------') |
Bram Moolenaar | b340bae | 2020-06-15 19:51:56 +0200 | [diff] [blame] | 1847 | new |
| 1848 | redir => msg |
Bram Moolenaar | 61abe7d | 2022-08-30 21:46:08 +0100 | [diff] [blame] | 1849 | edit Xnrpfile |
Bram Moolenaar | b340bae | 2020-06-15 19:51:56 +0200 | [diff] [blame] | 1850 | redir END |
| 1851 | call assert_equal(1, &readonly) |
| 1852 | call assert_equal([''], getline(1, '$')) |
| 1853 | call assert_match('\[Permission Denied\]', msg) |
| 1854 | close! |
Bram Moolenaar | b340bae | 2020-06-15 19:51:56 +0200 | [diff] [blame] | 1855 | endfunc |
| 1856 | |
zeertzjq | 3a56b6d | 2022-04-08 11:56:14 +0100 | [diff] [blame] | 1857 | " Using :edit without leaving 'insertmode' should not cause Insert mode to be |
| 1858 | " re-entered immediately after <C-L> |
| 1859 | func Test_edit_insertmode_ex_edit() |
| 1860 | CheckRunVimInTerminal |
| 1861 | |
| 1862 | let lines =<< trim END |
| 1863 | set insertmode noruler |
| 1864 | inoremap <C-B> <Cmd>edit Xfoo<CR> |
| 1865 | END |
Bram Moolenaar | 14f9176 | 2022-09-21 15:13:52 +0100 | [diff] [blame] | 1866 | call writefile(lines, 'Xtest_edit_insertmode_ex_edit', 'D') |
zeertzjq | 3a56b6d | 2022-04-08 11:56:14 +0100 | [diff] [blame] | 1867 | |
Bram Moolenaar | 14f9176 | 2022-09-21 15:13:52 +0100 | [diff] [blame] | 1868 | let buf = RunVimInTerminal('-S Xtest_edit_insertmode_ex_edit', #{rows: 6, wait_for_ruler: 0}) |
| 1869 | " Somehow when using valgrind "INSERT" does not show up unless we send |
| 1870 | " something to the terminal. |
| 1871 | for i in range(30) |
| 1872 | if term_getline(buf, 6) =~ 'INSERT' |
| 1873 | break |
| 1874 | endif |
| 1875 | call term_sendkeys(buf, "-") |
| 1876 | sleep 100m |
| 1877 | endfor |
Bram Moolenaar | c5382b6 | 2022-06-19 15:22:36 +0100 | [diff] [blame] | 1878 | call WaitForAssert({-> assert_match('^-- INSERT --\s*$', term_getline(buf, 6))}) |
zeertzjq | 3a56b6d | 2022-04-08 11:56:14 +0100 | [diff] [blame] | 1879 | call term_sendkeys(buf, "\<C-B>\<C-L>") |
Bram Moolenaar | c5382b6 | 2022-06-19 15:22:36 +0100 | [diff] [blame] | 1880 | call WaitForAssert({-> assert_notmatch('^-- INSERT --\s*$', term_getline(buf, 6))}) |
zeertzjq | 3a56b6d | 2022-04-08 11:56:14 +0100 | [diff] [blame] | 1881 | |
| 1882 | " clean up |
| 1883 | call StopVimInTerminal(buf) |
zeertzjq | 3a56b6d | 2022-04-08 11:56:14 +0100 | [diff] [blame] | 1884 | endfunc |
| 1885 | |
Bram Moolenaar | 845e0ee | 2020-06-20 16:05:32 +0200 | [diff] [blame] | 1886 | " Pressing escape in 'insertmode' should beep |
Bram Moolenaar | c5382b6 | 2022-06-19 15:22:36 +0100 | [diff] [blame] | 1887 | " FIXME: Execute this later, when using valgrind it makes the next test |
| 1888 | " Test_edit_insertmode_ex_edit() fail. |
| 1889 | func Test_z_edit_insertmode_esc_beeps() |
Bram Moolenaar | 845e0ee | 2020-06-20 16:05:32 +0200 | [diff] [blame] | 1890 | new |
| 1891 | set insertmode |
| 1892 | call assert_beeps("call feedkeys(\"one\<Esc>\", 'xt')") |
| 1893 | set insertmode& |
Bram Moolenaar | c5382b6 | 2022-06-19 15:22:36 +0100 | [diff] [blame] | 1894 | " unsupported "CTRL-G l" command should beep in insert mode. |
Bram Moolenaar | 845e0ee | 2020-06-20 16:05:32 +0200 | [diff] [blame] | 1895 | call assert_beeps("normal i\<C-G>l") |
Bram Moolenaar | c5382b6 | 2022-06-19 15:22:36 +0100 | [diff] [blame] | 1896 | bwipe! |
Bram Moolenaar | 845e0ee | 2020-06-20 16:05:32 +0200 | [diff] [blame] | 1897 | endfunc |
| 1898 | |
| 1899 | " Test for 'hkmap' and 'hkmapp' |
| 1900 | func Test_edit_hkmap() |
| 1901 | CheckFeature rightleft |
| 1902 | if has('win32') && !has('gui') |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 1903 | throw 'Skipped: fails on the MS-Windows terminal version' |
Bram Moolenaar | 845e0ee | 2020-06-20 16:05:32 +0200 | [diff] [blame] | 1904 | endif |
| 1905 | new |
| 1906 | |
| 1907 | set revins hkmap |
| 1908 | let str = 'abcdefghijklmnopqrstuvwxyz' |
| 1909 | let str ..= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' |
| 1910 | let str ..= '`/'',.;' |
| 1911 | call feedkeys('i' .. str, 'xt') |
| 1912 | let expected = "óõú,.;" |
| 1913 | let expected ..= "ZYXWVUTSRQPONMLKJIHGFEDCBA" |
| 1914 | let expected ..= "æèñ'äåàãø/ôíîöêìçïéòë÷âáðù" |
| 1915 | call assert_equal(expected, getline(1)) |
| 1916 | |
| 1917 | %d |
| 1918 | set revins hkmap hkmapp |
| 1919 | let str = 'abcdefghijklmnopqrstuvwxyz' |
| 1920 | let str ..= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' |
| 1921 | call feedkeys('i' .. str, 'xt') |
| 1922 | let expected = "õYXWVUTSRQóOïíLKJIHGFEDêBA" |
| 1923 | let expected ..= "öòXùåèúæø'ôñðîì÷çéäâóǟãëáà" |
| 1924 | call assert_equal(expected, getline(1)) |
| 1925 | |
| 1926 | set revins& hkmap& hkmapp& |
| 1927 | close! |
| 1928 | endfunc |
| 1929 | |
| 1930 | " Test for 'allowrevins' and using CTRL-_ in insert mode |
| 1931 | func Test_edit_allowrevins() |
| 1932 | CheckFeature rightleft |
| 1933 | new |
| 1934 | set allowrevins |
| 1935 | call feedkeys("iABC\<C-_>DEF\<C-_>GHI", 'xt') |
| 1936 | call assert_equal('ABCFEDGHI', getline(1)) |
| 1937 | set allowrevins& |
| 1938 | close! |
| 1939 | endfunc |
| 1940 | |
| 1941 | " Test for inserting a register in insert mode using CTRL-R |
| 1942 | func Test_edit_insert_reg() |
| 1943 | new |
| 1944 | let g:Line = '' |
| 1945 | func SaveFirstLine() |
| 1946 | let g:Line = Screenline(1) |
| 1947 | return 'r' |
| 1948 | endfunc |
| 1949 | inoremap <expr> <buffer> <F2> SaveFirstLine() |
| 1950 | call test_override('redraw_flag', 1) |
| 1951 | call test_override('char_avail', 1) |
| 1952 | let @r = 'sample' |
| 1953 | call feedkeys("a\<C-R>=SaveFirstLine()\<CR>", "xt") |
| 1954 | call assert_equal('"', g:Line) |
| 1955 | call test_override('ALL', 0) |
| 1956 | close! |
| 1957 | endfunc |
| 1958 | |
| 1959 | " When a character is inserted at the last position of the last line in a |
| 1960 | " window, the window contents should be scrolled one line up. If the top line |
| 1961 | " is part of a fold, then the entire fold should be scrolled up. |
| 1962 | func Test_edit_lastline_scroll() |
| 1963 | new |
| 1964 | let h = winheight(0) |
| 1965 | let lines = ['one', 'two', 'three'] |
| 1966 | let lines += repeat(['vim'], h - 4) |
| 1967 | call setline(1, lines) |
| 1968 | call setline(h, repeat('x', winwidth(0) - 1)) |
| 1969 | call feedkeys("GAx", 'xt') |
| 1970 | redraw! |
| 1971 | call assert_equal(h - 1, winline()) |
| 1972 | call assert_equal(2, line('w0')) |
| 1973 | |
| 1974 | " scroll with a fold |
| 1975 | 1,2fold |
| 1976 | normal gg |
| 1977 | call setline(h + 1, repeat('x', winwidth(0) - 1)) |
| 1978 | call feedkeys("GAx", 'xt') |
| 1979 | redraw! |
| 1980 | call assert_equal(h - 1, winline()) |
| 1981 | call assert_equal(3, line('w0')) |
| 1982 | |
| 1983 | close! |
| 1984 | endfunc |
| 1985 | |
Bram Moolenaar | 21cbe17 | 2020-10-13 19:08:24 +0200 | [diff] [blame] | 1986 | func Test_edit_browse() |
| 1987 | " in the GUI this opens a file picker, we only test the terminal behavior |
| 1988 | CheckNotGui |
| 1989 | |
| 1990 | " ":browse xxx" checks for the FileExplorer augroup and assumes editing "." |
| 1991 | " works then. |
| 1992 | augroup FileExplorer |
| 1993 | au! |
| 1994 | augroup END |
| 1995 | |
| 1996 | " When the USE_FNAME_CASE is defined this used to cause a crash. |
| 1997 | browse enew |
| 1998 | bwipe! |
| 1999 | |
| 2000 | browse split |
| 2001 | bwipe! |
| 2002 | endfunc |
| 2003 | |
Bram Moolenaar | caf73dc | 2020-10-26 21:39:13 +0100 | [diff] [blame] | 2004 | func Test_read_invalid() |
| 2005 | set encoding=latin1 |
| 2006 | " This was not properly checking for going past the end. |
| 2007 | call assert_fails('r`=', 'E484') |
| 2008 | set encoding=utf-8 |
| 2009 | endfunc |
| 2010 | |
Yegappan Lakshmanan | 5958549 | 2021-06-12 13:46:41 +0200 | [diff] [blame] | 2011 | " Test for the 'revins' option |
| 2012 | func Test_edit_revins() |
| 2013 | CheckFeature rightleft |
| 2014 | new |
| 2015 | set revins |
| 2016 | exe "normal! ione\ttwo three" |
| 2017 | call assert_equal("eerht owt\teno", getline(1)) |
| 2018 | call setline(1, "one\ttwo three") |
| 2019 | normal! gg$bi a |
| 2020 | call assert_equal("one\ttwo a three", getline(1)) |
| 2021 | exe "normal! $bi\<BS>\<BS>" |
| 2022 | call assert_equal("one\ttwo a ree", getline(1)) |
| 2023 | exe "normal! 0wi\<C-W>" |
| 2024 | call assert_equal("one\t a ree", getline(1)) |
| 2025 | exe "normal! 0wi\<C-U>" |
| 2026 | call assert_equal("one\t ", getline(1)) |
| 2027 | " newline in insert mode starts at the end of the line |
| 2028 | call setline(1, 'one two three') |
| 2029 | exe "normal! wi\nfour" |
| 2030 | call assert_equal(['one two three', 'ruof'], getline(1, '$')) |
| 2031 | set revins& |
| 2032 | bw! |
| 2033 | endfunc |
| 2034 | |
Bram Moolenaar | 35a9a00 | 2021-09-11 21:14:20 +0200 | [diff] [blame] | 2035 | " Test for getting the character of the line below after "p" |
| 2036 | func Test_edit_put_CTRL_E() |
| 2037 | set encoding=latin1 |
| 2038 | new |
| 2039 | let @" = '' |
| 2040 | sil! norm orggRx |
| 2041 | sil! norm pr |
| 2042 | call assert_equal(['r', 'r'], getline(1, 2)) |
| 2043 | bwipe! |
| 2044 | set encoding=utf-8 |
| 2045 | endfunc |
| 2046 | |
Dominique Pelle | 9cd063e | 2021-10-28 21:06:05 +0100 | [diff] [blame] | 2047 | " Test toggling of input method. See :help i_CTRL-^ |
| 2048 | func Test_edit_CTRL_hat() |
| 2049 | CheckFeature xim |
Dominique Pelle | 8753c1d | 2021-10-31 20:19:17 +0000 | [diff] [blame] | 2050 | |
Bram Moolenaar | 0b962e5 | 2022-04-03 18:02:37 +0100 | [diff] [blame] | 2051 | " FIXME: test fails with Motif GUI. |
Dominique Pelle | 8753c1d | 2021-10-31 20:19:17 +0000 | [diff] [blame] | 2052 | " test also fails when running in the GUI. |
| 2053 | CheckFeature gui_gtk |
| 2054 | CheckNotGui |
Dominique Pelle | 9cd063e | 2021-10-28 21:06:05 +0100 | [diff] [blame] | 2055 | |
| 2056 | new |
| 2057 | |
| 2058 | call assert_equal(0, &iminsert) |
| 2059 | call feedkeys("i\<C-^>", 'xt') |
| 2060 | call assert_equal(2, &iminsert) |
| 2061 | call feedkeys("i\<C-^>", 'xt') |
| 2062 | call assert_equal(0, &iminsert) |
| 2063 | |
| 2064 | bwipe! |
| 2065 | endfunc |
| 2066 | |
Bram Moolenaar | 2824d1e | 2023-02-23 20:13:04 +0000 | [diff] [blame] | 2067 | " Test "gr" followed by an Insert mode command does get out of Insert mode. |
| 2068 | func Test_edit_gr_special() |
| 2069 | enew |
| 2070 | call setline(1, ['abcdef', 'xxxxxx']) |
Bram Moolenaar | d6a4ea3 | 2023-02-25 14:24:44 +0000 | [diff] [blame] | 2071 | exe "normal! gr\<C-O>lx" |
| 2072 | call assert_equal("\<C-O>def", getline(1)) |
| 2073 | |
| 2074 | call setline(1, 'abcdef') |
| 2075 | exe "normal! 0gr\<C-G>lx" |
| 2076 | call assert_equal("\<C-G>def", getline(1)) |
Bram Moolenaar | 2824d1e | 2023-02-23 20:13:04 +0000 | [diff] [blame] | 2077 | |
| 2078 | bwipe! |
| 2079 | endfunc |
| 2080 | |
Bram Moolenaar | de05bb2 | 2022-01-13 13:08:14 +0000 | [diff] [blame] | 2081 | " Weird long file name was going over the end of NameBuff |
| 2082 | func Test_edit_overlong_file_name() |
| 2083 | CheckUnix |
| 2084 | |
| 2085 | file 0000000000000000000000000000 |
| 2086 | file %%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2087 | file %%%%%% |
| 2088 | set readonly |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 2089 | set ls=2 |
Bram Moolenaar | de05bb2 | 2022-01-13 13:08:14 +0000 | [diff] [blame] | 2090 | |
| 2091 | redraw! |
| 2092 | set noreadonly ls& |
| 2093 | bwipe! |
| 2094 | endfunc |
| 2095 | |
Christian Brabandt | dfbdadc | 2022-05-05 20:46:47 +0100 | [diff] [blame] | 2096 | func Test_edit_shift_bs() |
| 2097 | CheckMSWindows |
| 2098 | |
| 2099 | " FIXME: this works interactively, but the test fails |
| 2100 | throw 'Skipped: Shift-Backspace Test not working correctly :(' |
| 2101 | |
| 2102 | " Need to run this in Win32 Terminal, do not use CheckRunVimInTerminal |
| 2103 | if !has("terminal") |
| 2104 | return |
| 2105 | endif |
| 2106 | |
| 2107 | " Shift Backspace should work like Backspace in insert mode |
| 2108 | let lines =<< trim END |
| 2109 | call setline(1, ['abc']) |
| 2110 | END |
Bram Moolenaar | 14f9176 | 2022-09-21 15:13:52 +0100 | [diff] [blame] | 2111 | call writefile(lines, 'Xtest_edit_shift_bs', 'D') |
Christian Brabandt | dfbdadc | 2022-05-05 20:46:47 +0100 | [diff] [blame] | 2112 | |
| 2113 | let buf = RunVimInTerminal('-S Xtest_edit_shift_bs', #{rows: 3}) |
| 2114 | call term_sendkeys(buf, "A\<S-BS>-\<esc>") |
| 2115 | call TermWait(buf, 50) |
| 2116 | call assert_equal('ab-', term_getline(buf, 1)) |
| 2117 | |
| 2118 | " clean up |
| 2119 | call StopVimInTerminal(buf) |
Christian Brabandt | dfbdadc | 2022-05-05 20:46:47 +0100 | [diff] [blame] | 2120 | endfunc |
Dominique Pelle | 9cd063e | 2021-10-28 21:06:05 +0100 | [diff] [blame] | 2121 | |
Bram Moolenaar | bc2b71d | 2020-02-17 21:33:30 +0100 | [diff] [blame] | 2122 | " vim: shiftwidth=2 sts=2 expandtab |