Bram Moolenaar | 9aa1569 | 2017-08-19 15:05:32 +0200 | [diff] [blame] | 1 | " Tests for 'virtualedit'. |
| 2 | |
| 3 | func Test_yank_move_change() |
Bram Moolenaar | d41babe | 2017-08-30 17:01:35 +0200 | [diff] [blame] | 4 | new |
Bram Moolenaar | 9aa1569 | 2017-08-19 15:05:32 +0200 | [diff] [blame] | 5 | call setline(1, [ |
| 6 | \ "func foo() error {", |
| 7 | \ "\tif n, err := bar();", |
| 8 | \ "\terr != nil {", |
| 9 | \ "\t\treturn err", |
| 10 | \ "\t}", |
| 11 | \ "\tn = n * n", |
| 12 | \ ]) |
| 13 | set virtualedit=all |
| 14 | set ts=4 |
| 15 | function! MoveSelectionDown(count) abort |
| 16 | normal! m` |
| 17 | silent! exe "'<,'>move'>+".a:count |
| 18 | norm! `` |
| 19 | endfunction |
| 20 | |
| 21 | xmap ]e :<C-U>call MoveSelectionDown(v:count1)<CR> |
| 22 | 2 |
| 23 | normal 2gg |
| 24 | normal J |
| 25 | normal jVj |
| 26 | normal ]e |
| 27 | normal ce |
| 28 | bwipe! |
| 29 | set virtualedit= |
| 30 | set ts=8 |
| 31 | endfunc |
Bram Moolenaar | d41babe | 2017-08-30 17:01:35 +0200 | [diff] [blame] | 32 | |
| 33 | func Test_paste_end_of_line() |
| 34 | new |
| 35 | set virtualedit=all |
| 36 | call setline(1, ['456', '123']) |
| 37 | normal! gg0"ay$ |
| 38 | exe "normal! 2G$lllA\<C-O>:normal! \"agP\r" |
| 39 | call assert_equal('123456', getline(2)) |
| 40 | |
| 41 | bwipe! |
| 42 | set virtualedit= |
| 43 | endfunc |
Bram Moolenaar | db0eede | 2018-04-25 22:38:17 +0200 | [diff] [blame] | 44 | |
Bram Moolenaar | 630afe8 | 2018-06-28 19:26:28 +0200 | [diff] [blame] | 45 | func Test_replace_end_of_line() |
| 46 | new |
| 47 | set virtualedit=all |
| 48 | call setline(1, range(20)) |
| 49 | exe "normal! gg2jv10lr-" |
| 50 | call assert_equal(["1", "-----------", "3"], getline(2,4)) |
Bram Moolenaar | 30276f2 | 2019-01-24 17:59:39 +0100 | [diff] [blame] | 51 | call setline(1, range(20)) |
| 52 | exe "normal! gg2jv10lr\<c-k>hh" |
| 53 | call assert_equal(["1", "───────────", "3"], getline(2,4)) |
Bram Moolenaar | 630afe8 | 2018-06-28 19:26:28 +0200 | [diff] [blame] | 54 | |
| 55 | bwipe! |
| 56 | set virtualedit= |
| 57 | endfunc |
| 58 | |
Bram Moolenaar | db0eede | 2018-04-25 22:38:17 +0200 | [diff] [blame] | 59 | func Test_edit_CTRL_G() |
| 60 | new |
| 61 | set virtualedit=insert |
| 62 | call setline(1, ['123', '1', '12']) |
| 63 | exe "normal! ggA\<c-g>jx\<c-g>jx" |
| 64 | call assert_equal(['123', '1 x', '12 x'], getline(1,'$')) |
| 65 | |
| 66 | set virtualedit=all |
| 67 | %d_ |
| 68 | call setline(1, ['1', '12']) |
| 69 | exe "normal! ggllix\<c-g>jx" |
| 70 | call assert_equal(['1 x', '12x'], getline(1,'$')) |
| 71 | |
| 72 | |
| 73 | bwipe! |
| 74 | set virtualedit= |
| 75 | endfunc |
Bram Moolenaar | 77ccc00 | 2019-10-31 03:21:25 +0100 | [diff] [blame] | 76 | |
| 77 | func Test_edit_change() |
| 78 | new |
| 79 | set virtualedit=all |
zeertzjq | 048761b | 2024-02-24 14:21:39 +0100 | [diff] [blame] | 80 | |
Bram Moolenaar | 77ccc00 | 2019-10-31 03:21:25 +0100 | [diff] [blame] | 81 | call setline(1, "\t⒌") |
| 82 | normal Cx |
| 83 | call assert_equal('x', getline(1)) |
zeertzjq | 048761b | 2024-02-24 14:21:39 +0100 | [diff] [blame] | 84 | |
| 85 | call setline(1, "\ta̳") |
| 86 | normal Cx |
| 87 | call assert_equal('x', getline(1)) |
| 88 | |
| 89 | call setline(1, "\tβ̳") |
| 90 | normal Cx |
| 91 | call assert_equal('x', getline(1)) |
| 92 | |
| 93 | if has('arabic') |
| 94 | call setline(1, "\tلا") |
| 95 | normal Cx |
| 96 | call assert_equal('x', getline(1)) |
| 97 | endif |
| 98 | |
Bram Moolenaar | 3e72dca | 2021-05-29 16:30:12 +0200 | [diff] [blame] | 99 | " Do a visual block change |
| 100 | call setline(1, ['a', 'b', 'c']) |
| 101 | exe "normal gg3l\<C-V>2jcx" |
| 102 | call assert_equal(['a x', 'b x', 'c x'], getline(1, '$')) |
zeertzjq | 048761b | 2024-02-24 14:21:39 +0100 | [diff] [blame] | 103 | |
Bram Moolenaar | 77ccc00 | 2019-10-31 03:21:25 +0100 | [diff] [blame] | 104 | bwipe! |
Bram Moolenaar | 6f1f0ca | 2019-12-01 18:16:18 +0100 | [diff] [blame] | 105 | set virtualedit= |
| 106 | endfunc |
| 107 | |
Bram Moolenaar | c99cbf8 | 2023-03-04 14:13:10 +0000 | [diff] [blame] | 108 | func Test_edit_special_char() |
| 109 | new |
| 110 | se ve=all |
| 111 | norm a0 |
| 112 | sil! exe "norm o00000\<Nul>k<a0s" |
| 113 | |
| 114 | bwipe! |
| 115 | set virtualedit= |
| 116 | endfunc |
| 117 | |
Bram Moolenaar | 54c8d22 | 2019-12-02 20:41:39 +0100 | [diff] [blame] | 118 | " Tests for pasting at the beginning, end and middle of a tab character |
| 119 | " in virtual edit mode. |
Bram Moolenaar | 6f1f0ca | 2019-12-01 18:16:18 +0100 | [diff] [blame] | 120 | func Test_paste_in_tab() |
| 121 | new |
Bram Moolenaar | 54c8d22 | 2019-12-02 20:41:39 +0100 | [diff] [blame] | 122 | call append(0, '') |
Bram Moolenaar | 6f1f0ca | 2019-12-01 18:16:18 +0100 | [diff] [blame] | 123 | set virtualedit=all |
Bram Moolenaar | 54c8d22 | 2019-12-02 20:41:39 +0100 | [diff] [blame] | 124 | |
| 125 | " Tests for pasting a register with characterwise mode type |
| 126 | call setreg('"', 'xyz', 'c') |
| 127 | |
| 128 | " paste (p) unnamed register at the beginning of a tab |
Bram Moolenaar | 6f1f0ca | 2019-12-01 18:16:18 +0100 | [diff] [blame] | 129 | call setline(1, "a\tb") |
Bram Moolenaar | 54c8d22 | 2019-12-02 20:41:39 +0100 | [diff] [blame] | 130 | call cursor(1, 2, 0) |
| 131 | normal p |
| 132 | call assert_equal('a xyz b', getline(1)) |
| 133 | |
| 134 | " paste (P) unnamed register at the beginning of a tab |
| 135 | call setline(1, "a\tb") |
| 136 | call cursor(1, 2, 0) |
Bram Moolenaar | 6f1f0ca | 2019-12-01 18:16:18 +0100 | [diff] [blame] | 137 | normal P |
| 138 | call assert_equal("axyz\tb", getline(1)) |
| 139 | |
Bram Moolenaar | 54c8d22 | 2019-12-02 20:41:39 +0100 | [diff] [blame] | 140 | " paste (p) unnamed register at the end of a tab |
Bram Moolenaar | 6f1f0ca | 2019-12-01 18:16:18 +0100 | [diff] [blame] | 141 | call setline(1, "a\tb") |
| 142 | call cursor(1, 2, 6) |
| 143 | normal p |
| 144 | call assert_equal("a\txyzb", getline(1)) |
Bram Moolenaar | 54c8d22 | 2019-12-02 20:41:39 +0100 | [diff] [blame] | 145 | |
| 146 | " paste (P) unnamed register at the end of a tab |
Bram Moolenaar | 6f1f0ca | 2019-12-01 18:16:18 +0100 | [diff] [blame] | 147 | call setline(1, "a\tb") |
| 148 | call cursor(1, 2, 6) |
| 149 | normal P |
Bram Moolenaar | 54c8d22 | 2019-12-02 20:41:39 +0100 | [diff] [blame] | 150 | call assert_equal('a xyz b', getline(1)) |
Bram Moolenaar | 6f1f0ca | 2019-12-01 18:16:18 +0100 | [diff] [blame] | 151 | |
Bram Moolenaar | 54c8d22 | 2019-12-02 20:41:39 +0100 | [diff] [blame] | 152 | " Tests for pasting a register with blockwise mode type |
| 153 | call setreg('"', 'xyz', 'b') |
| 154 | |
| 155 | " paste (p) unnamed register at the beginning of a tab |
| 156 | call setline(1, "a\tb") |
| 157 | call cursor(1, 2, 0) |
| 158 | normal p |
| 159 | call assert_equal('a xyz b', getline(1)) |
| 160 | |
| 161 | " paste (P) unnamed register at the beginning of a tab |
| 162 | call setline(1, "a\tb") |
| 163 | call cursor(1, 2, 0) |
| 164 | normal P |
| 165 | call assert_equal("axyz\tb", getline(1)) |
| 166 | |
| 167 | " paste (p) unnamed register at the end of a tab |
| 168 | call setline(1, "a\tb") |
| 169 | call cursor(1, 2, 6) |
| 170 | normal p |
| 171 | call assert_equal("a\txyzb", getline(1)) |
| 172 | |
| 173 | " paste (P) unnamed register at the end of a tab |
| 174 | call setline(1, "a\tb") |
| 175 | call cursor(1, 2, 6) |
| 176 | normal P |
| 177 | call assert_equal('a xyz b', getline(1)) |
| 178 | |
| 179 | " Tests for pasting with gp and gP in virtual edit mode |
| 180 | |
| 181 | " paste (gp) unnamed register at the beginning of a tab |
| 182 | call setline(1, "a\tb") |
| 183 | call cursor(1, 2, 0) |
| 184 | normal gp |
| 185 | call assert_equal('a xyz b', getline(1)) |
| 186 | call assert_equal([0, 1, 12, 0, 12], getcurpos()) |
| 187 | |
| 188 | " paste (gP) unnamed register at the beginning of a tab |
| 189 | call setline(1, "a\tb") |
| 190 | call cursor(1, 2, 0) |
| 191 | normal gP |
| 192 | call assert_equal("axyz\tb", getline(1)) |
| 193 | call assert_equal([0, 1, 5, 0, 5], getcurpos()) |
| 194 | |
| 195 | " paste (gp) unnamed register at the end of a tab |
Bram Moolenaar | 6f1f0ca | 2019-12-01 18:16:18 +0100 | [diff] [blame] | 196 | call setline(1, "a\tb") |
| 197 | call cursor(1, 2, 6) |
| 198 | normal gp |
| 199 | call assert_equal("a\txyzb", getline(1)) |
| 200 | call assert_equal([0, 1, 6, 0, 12], getcurpos()) |
Bram Moolenaar | 54c8d22 | 2019-12-02 20:41:39 +0100 | [diff] [blame] | 201 | |
| 202 | " paste (gP) unnamed register at the end of a tab |
Bram Moolenaar | 6f1f0ca | 2019-12-01 18:16:18 +0100 | [diff] [blame] | 203 | call setline(1, "a\tb") |
| 204 | call cursor(1, 2, 6) |
| 205 | normal gP |
Bram Moolenaar | 54c8d22 | 2019-12-02 20:41:39 +0100 | [diff] [blame] | 206 | call assert_equal('a xyz b', getline(1)) |
| 207 | call assert_equal([0, 1, 12, 0, 12], getcurpos()) |
| 208 | |
| 209 | " Tests for pasting a named register |
| 210 | let @r = 'xyz' |
| 211 | |
| 212 | " paste (gp) named register in the middle of a tab |
| 213 | call setline(1, "a\tb") |
| 214 | call cursor(1, 2, 2) |
| 215 | normal "rgp |
| 216 | call assert_equal('a xyz b', getline(1)) |
| 217 | call assert_equal([0, 1, 8, 0, 8], getcurpos()) |
| 218 | |
| 219 | " paste (gP) named register in the middle of a tab |
| 220 | call setline(1, "a\tb") |
| 221 | call cursor(1, 2, 2) |
| 222 | normal "rgP |
| 223 | call assert_equal('a xyz b', getline(1)) |
| 224 | call assert_equal([0, 1, 7, 0, 7], getcurpos()) |
Bram Moolenaar | 6f1f0ca | 2019-12-01 18:16:18 +0100 | [diff] [blame] | 225 | |
| 226 | bwipe! |
| 227 | set virtualedit= |
Bram Moolenaar | 77ccc00 | 2019-10-31 03:21:25 +0100 | [diff] [blame] | 228 | endfunc |
Bram Moolenaar | 54c8d22 | 2019-12-02 20:41:39 +0100 | [diff] [blame] | 229 | |
| 230 | " Test for yanking a few spaces within a tab to a register |
| 231 | func Test_yank_in_tab() |
| 232 | new |
| 233 | let @r = '' |
| 234 | call setline(1, "a\tb") |
| 235 | set virtualedit=all |
| 236 | call cursor(1, 2, 2) |
| 237 | normal "ry5l |
| 238 | call assert_equal(' ', @r) |
| 239 | |
| 240 | bwipe! |
| 241 | set virtualedit= |
| 242 | endfunc |
| 243 | |
Bram Moolenaar | 079119b | 2019-12-03 22:59:23 +0100 | [diff] [blame] | 244 | " Insert "keyword keyw", ESC, C CTRL-N, shows "keyword ykeyword". |
| 245 | " Repeating CTRL-N fixes it. (Mary Ellen Foster) |
| 246 | func Test_ve_completion() |
| 247 | new |
| 248 | set completeopt&vim |
| 249 | set virtualedit=all |
| 250 | exe "normal ikeyword keyw\<Esc>C\<C-N>" |
| 251 | call assert_equal('keyword keyword', getline(1)) |
| 252 | bwipe! |
| 253 | set virtualedit= |
| 254 | endfunc |
| 255 | |
Christian Brabandt | ee17b6f | 2023-09-09 11:23:50 +0200 | [diff] [blame] | 256 | " Using "C" then <CR> moves the last remaining character to the next |
Bram Moolenaar | 079119b | 2019-12-03 22:59:23 +0100 | [diff] [blame] | 257 | " line. (Mary Ellen Foster) |
| 258 | func Test_ve_del_to_eol() |
| 259 | new |
| 260 | set virtualedit=all |
| 261 | call append(0, 'all your base are belong to us') |
| 262 | call search('are', 'w') |
| 263 | exe "normal C\<CR>are belong to vim" |
| 264 | call assert_equal(['all your base ', 'are belong to vim'], getline(1, 2)) |
| 265 | bwipe! |
| 266 | set virtualedit= |
| 267 | endfunc |
| 268 | |
| 269 | " When past the end of a line that ends in a single character "b" skips |
| 270 | " that word. |
| 271 | func Test_ve_b_past_eol() |
| 272 | new |
| 273 | set virtualedit=all |
| 274 | call append(0, '1 2 3 4 5 6') |
| 275 | normal gg^$15lbC7 |
| 276 | call assert_equal('1 2 3 4 5 7', getline(1)) |
| 277 | bwipe! |
| 278 | set virtualedit= |
| 279 | endfunc |
| 280 | |
| 281 | " Make sure 'i', 'C', 'a', 'A' and 'D' works |
| 282 | func Test_ve_ins_del() |
| 283 | new |
| 284 | set virtualedit=all |
| 285 | call append(0, ["'i'", "'C'", "'a'", "'A'", "'D'"]) |
| 286 | call cursor(1, 1) |
| 287 | normal $4lix |
| 288 | call assert_equal("'i' x", getline(1)) |
| 289 | call cursor(2, 1) |
| 290 | normal $4lCx |
| 291 | call assert_equal("'C' x", getline(2)) |
| 292 | call cursor(3, 1) |
| 293 | normal $4lax |
| 294 | call assert_equal("'a' x", getline(3)) |
| 295 | call cursor(4, 1) |
| 296 | normal $4lAx |
| 297 | call assert_equal("'A'x", getline(4)) |
| 298 | call cursor(5, 1) |
| 299 | normal $4lDix |
| 300 | call assert_equal("'D' x", getline(5)) |
| 301 | bwipe! |
| 302 | set virtualedit= |
| 303 | endfunc |
| 304 | |
| 305 | " Test for yank bug reported by Mark Waggoner. |
| 306 | func Test_yank_block() |
| 307 | new |
| 308 | set virtualedit=block |
| 309 | call append(0, repeat(['this is a test'], 3)) |
| 310 | exe "normal gg^2w\<C-V>3jy" |
| 311 | call assert_equal("a\na\na\n ", @") |
| 312 | bwipe! |
| 313 | set virtualedit= |
| 314 | endfunc |
| 315 | |
| 316 | " Test "r" beyond the end of the line |
| 317 | func Test_replace_after_eol() |
| 318 | new |
| 319 | set virtualedit=all |
| 320 | call append(0, '"r"') |
| 321 | normal gg$5lrxa |
| 322 | call assert_equal('"r" x', getline(1)) |
Bram Moolenaar | 3e72dca | 2021-05-29 16:30:12 +0200 | [diff] [blame] | 323 | " visual block replace |
| 324 | %d _ |
| 325 | call setline(1, ['a', '', 'b']) |
| 326 | exe "normal 2l\<C-V>2jrx" |
| 327 | call assert_equal(['a x', ' x', 'b x'], getline(1, '$')) |
| 328 | " visual characterwise selection replace after eol |
| 329 | %d _ |
| 330 | call setline(1, 'a') |
| 331 | normal 4lv2lrx |
| 332 | call assert_equal('a xxx', getline(1)) |
Bram Moolenaar | 079119b | 2019-12-03 22:59:23 +0100 | [diff] [blame] | 333 | bwipe! |
| 334 | set virtualedit= |
| 335 | endfunc |
| 336 | |
| 337 | " Test "r" on a tab |
| 338 | " Note that for this test, 'ts' must be 8 (the default). |
| 339 | func Test_replace_on_tab() |
| 340 | new |
| 341 | set virtualedit=all |
| 342 | call append(0, "'r'\t") |
| 343 | normal gg^5lrxAy |
| 344 | call assert_equal("'r' x y", getline(1)) |
Bram Moolenaar | f5f1e10 | 2020-03-08 05:13:15 +0100 | [diff] [blame] | 345 | call setline(1, 'aaaaaaaaaaaa') |
| 346 | exe "normal! gg2lgR\<Tab>" |
| 347 | call assert_equal("aa\taaaa", getline(1)) |
Bram Moolenaar | 079119b | 2019-12-03 22:59:23 +0100 | [diff] [blame] | 348 | bwipe! |
| 349 | set virtualedit= |
| 350 | endfunc |
| 351 | |
| 352 | " Test to make sure 'x' can delete control characters |
| 353 | func Test_ve_del_ctrl_chars() |
| 354 | new |
| 355 | set virtualedit=all |
| 356 | call append(0, "a\<C-V>b\<CR>sd") |
| 357 | set display=uhex |
| 358 | normal gg^xxxxxxi[text] |
| 359 | set display= |
| 360 | call assert_equal('[text]', getline(1)) |
| 361 | bwipe! |
| 362 | set virtualedit= |
| 363 | endfunc |
| 364 | |
| 365 | " Test for ^Y/^E due to bad w_virtcol value, reported by |
| 366 | " Roy <royl@netropolis.net>. |
| 367 | func Test_ins_copy_char() |
| 368 | new |
| 369 | set virtualedit=all |
| 370 | call append(0, 'abcv8efi.him2kl') |
| 371 | exe "normal gg^O\<Esc>3li\<C-E>\<Esc>4li\<C-E>\<Esc>4li\<C-E> <--" |
| 372 | exe "normal j^o\<Esc>4li\<C-Y>\<Esc>4li\<C-Y>\<Esc>4li\<C-Y> <--" |
| 373 | call assert_equal(' v i m <--', getline(1)) |
| 374 | call assert_equal(' 8 . 2 <--', getline(3)) |
| 375 | bwipe! |
| 376 | set virtualedit= |
| 377 | endfunc |
| 378 | |
| 379 | " Test for yanking and pasting using the small delete register |
| 380 | func Test_yank_paste_small_del_reg() |
| 381 | new |
| 382 | set virtualedit=all |
| 383 | call append(0, "foo, bar") |
| 384 | normal ggdewve"-p |
| 385 | call assert_equal(', foo', getline(1)) |
| 386 | bwipe! |
| 387 | set virtualedit= |
| 388 | endfunc |
| 389 | |
Bram Moolenaar | 004a678 | 2020-04-11 17:09:31 +0200 | [diff] [blame] | 390 | " Test for delete that breaks a tab into spaces |
| 391 | func Test_delete_break_tab() |
| 392 | new |
| 393 | call setline(1, "one\ttwo") |
| 394 | set virtualedit=all |
| 395 | normal v3ld |
| 396 | call assert_equal(' two', getline(1)) |
| 397 | set virtualedit& |
| 398 | close! |
| 399 | endfunc |
| 400 | |
Bram Moolenaar | 845e0ee | 2020-06-20 16:05:32 +0200 | [diff] [blame] | 401 | " Test for using <BS>, <C-W> and <C-U> in virtual edit mode |
| 402 | " to erase character, word and line. |
| 403 | func Test_ve_backspace() |
| 404 | new |
| 405 | call setline(1, 'sample') |
| 406 | set virtualedit=all |
| 407 | set backspace=indent,eol,start |
| 408 | exe "normal 15|i\<BS>\<BS>" |
| 409 | call assert_equal([0, 1, 7, 5], getpos('.')) |
| 410 | exe "normal 15|i\<C-W>" |
| 411 | call assert_equal([0, 1, 6, 0], getpos('.')) |
| 412 | exe "normal 15|i\<C-U>" |
| 413 | call assert_equal([0, 1, 1, 0], getpos('.')) |
| 414 | set backspace& |
| 415 | set virtualedit& |
| 416 | close! |
| 417 | endfunc |
| 418 | |
Bram Moolenaar | 3e72dca | 2021-05-29 16:30:12 +0200 | [diff] [blame] | 419 | " Test for delete (x) on EOL character and after EOL |
| 420 | func Test_delete_past_eol() |
| 421 | new |
| 422 | call setline(1, "ab") |
| 423 | set virtualedit=all |
| 424 | exe "normal 2lx" |
| 425 | call assert_equal('ab', getline(1)) |
| 426 | exe "normal 10lx" |
| 427 | call assert_equal('ab', getline(1)) |
| 428 | set virtualedit& |
| 429 | bw! |
| 430 | endfunc |
| 431 | |
Gary Johnson | 53ba05b | 2021-07-26 22:19:10 +0200 | [diff] [blame] | 432 | " After calling s:TryVirtualeditReplace(), line 1 will contain one of these |
| 433 | " two strings, depending on whether virtual editing is on or off. |
| 434 | let s:result_ve_on = 'a x' |
| 435 | let s:result_ve_off = 'x' |
| 436 | |
Gary Johnson | 51ad850 | 2021-08-03 18:33:08 +0200 | [diff] [blame] | 437 | " Utility function for Test_global_local_virtualedit() |
Gary Johnson | 53ba05b | 2021-07-26 22:19:10 +0200 | [diff] [blame] | 438 | func s:TryVirtualeditReplace() |
| 439 | call setline(1, 'a') |
| 440 | normal gg7l |
| 441 | normal rx |
| 442 | endfunc |
| 443 | |
| 444 | " Test for :set and :setlocal |
Gary Johnson | 51ad850 | 2021-08-03 18:33:08 +0200 | [diff] [blame] | 445 | func Test_global_local_virtualedit() |
Gary Johnson | 53ba05b | 2021-07-26 22:19:10 +0200 | [diff] [blame] | 446 | new |
| 447 | |
| 448 | " Verify that 'virtualedit' is initialized to empty, can be set globally to |
| 449 | " all and to empty, and can be set locally to all and to empty. |
| 450 | call s:TryVirtualeditReplace() |
| 451 | call assert_equal(s:result_ve_off, getline(1)) |
| 452 | set ve=all |
| 453 | call s:TryVirtualeditReplace() |
| 454 | call assert_equal(s:result_ve_on, getline(1)) |
| 455 | set ve= |
| 456 | call s:TryVirtualeditReplace() |
| 457 | call assert_equal(s:result_ve_off, getline(1)) |
| 458 | setlocal ve=all |
| 459 | call s:TryVirtualeditReplace() |
| 460 | call assert_equal(s:result_ve_on, getline(1)) |
| 461 | setlocal ve= |
| 462 | call s:TryVirtualeditReplace() |
| 463 | call assert_equal(s:result_ve_off, getline(1)) |
| 464 | |
Gary Johnson | 51ad850 | 2021-08-03 18:33:08 +0200 | [diff] [blame] | 465 | " Verify that :set affects multiple windows. |
| 466 | split |
Gary Johnson | 53ba05b | 2021-07-26 22:19:10 +0200 | [diff] [blame] | 467 | set ve=all |
| 468 | call s:TryVirtualeditReplace() |
| 469 | call assert_equal(s:result_ve_on, getline(1)) |
| 470 | wincmd p |
| 471 | call s:TryVirtualeditReplace() |
| 472 | call assert_equal(s:result_ve_on, getline(1)) |
| 473 | set ve= |
| 474 | wincmd p |
| 475 | call s:TryVirtualeditReplace() |
| 476 | call assert_equal(s:result_ve_off, getline(1)) |
| 477 | bwipe! |
| 478 | |
Gary Johnson | 51ad850 | 2021-08-03 18:33:08 +0200 | [diff] [blame] | 479 | " Verify that :setlocal affects only the current window. |
Gary Johnson | 53ba05b | 2021-07-26 22:19:10 +0200 | [diff] [blame] | 480 | new |
Gary Johnson | 51ad850 | 2021-08-03 18:33:08 +0200 | [diff] [blame] | 481 | split |
Gary Johnson | 53ba05b | 2021-07-26 22:19:10 +0200 | [diff] [blame] | 482 | setlocal ve=all |
Gary Johnson | 53ba05b | 2021-07-26 22:19:10 +0200 | [diff] [blame] | 483 | call s:TryVirtualeditReplace() |
| 484 | call assert_equal(s:result_ve_on, getline(1)) |
Gary Johnson | 51ad850 | 2021-08-03 18:33:08 +0200 | [diff] [blame] | 485 | wincmd p |
| 486 | call s:TryVirtualeditReplace() |
| 487 | call assert_equal(s:result_ve_off, getline(1)) |
Gary Johnson | 53ba05b | 2021-07-26 22:19:10 +0200 | [diff] [blame] | 488 | bwipe! |
| 489 | call s:TryVirtualeditReplace() |
| 490 | call assert_equal(s:result_ve_off, getline(1)) |
| 491 | |
| 492 | " Verify that the buffer 'virtualedit' state follows the global value only |
| 493 | " when empty and that "none" works as expected. |
| 494 | " |
| 495 | " 'virtualedit' State |
| 496 | " +--------+--------------------------+ |
| 497 | " | Local | Global | |
| 498 | " | | | |
| 499 | " +--------+--------+--------+--------+ |
| 500 | " | | "" | "all" | "none" | |
| 501 | " +--------+--------+--------+--------+ |
| 502 | " | "" | off | on | off | |
| 503 | " | "all" | on | on | on | |
| 504 | " | "none" | off | off | off | |
| 505 | " +--------+--------+--------+--------+ |
| 506 | new |
| 507 | |
| 508 | setglobal ve= |
| 509 | setlocal ve= |
| 510 | call s:TryVirtualeditReplace() |
| 511 | call assert_equal(s:result_ve_off, getline(1)) |
| 512 | setlocal ve=all |
| 513 | call s:TryVirtualeditReplace() |
| 514 | call assert_equal(s:result_ve_on, getline(1)) |
| 515 | setlocal ve=none |
| 516 | call s:TryVirtualeditReplace() |
| 517 | call assert_equal(s:result_ve_off, getline(1)) |
| 518 | |
| 519 | setglobal ve=all |
| 520 | setlocal ve= |
| 521 | call s:TryVirtualeditReplace() |
| 522 | call assert_equal(s:result_ve_on, getline(1)) |
| 523 | setlocal ve=all |
| 524 | call s:TryVirtualeditReplace() |
| 525 | call assert_equal(s:result_ve_on, getline(1)) |
| 526 | setlocal ve=none |
| 527 | call s:TryVirtualeditReplace() |
| 528 | call assert_equal(s:result_ve_off, getline(1)) |
| 529 | setlocal ve=NONE |
| 530 | call s:TryVirtualeditReplace() |
| 531 | call assert_equal(s:result_ve_off, getline(1)) |
| 532 | |
| 533 | setglobal ve=none |
| 534 | setlocal ve= |
| 535 | call s:TryVirtualeditReplace() |
| 536 | call assert_equal(s:result_ve_off, getline(1)) |
| 537 | setlocal ve=all |
| 538 | call s:TryVirtualeditReplace() |
| 539 | call assert_equal(s:result_ve_on, getline(1)) |
| 540 | setlocal ve=none |
| 541 | call s:TryVirtualeditReplace() |
| 542 | call assert_equal(s:result_ve_off, getline(1)) |
| 543 | |
| 544 | bwipe! |
| 545 | |
Gary Johnson | 51ad850 | 2021-08-03 18:33:08 +0200 | [diff] [blame] | 546 | " Verify that the 'virtualedit' state is copied to new windows. |
| 547 | new |
| 548 | call s:TryVirtualeditReplace() |
| 549 | call assert_equal(s:result_ve_off, getline(1)) |
| 550 | split |
| 551 | setlocal ve=all |
| 552 | call s:TryVirtualeditReplace() |
| 553 | call assert_equal(s:result_ve_on, getline(1)) |
| 554 | split |
| 555 | call s:TryVirtualeditReplace() |
| 556 | call assert_equal(s:result_ve_on, getline(1)) |
| 557 | setlocal ve= |
| 558 | split |
| 559 | call s:TryVirtualeditReplace() |
| 560 | call assert_equal(s:result_ve_off, getline(1)) |
| 561 | bwipe! |
| 562 | |
Gary Johnson | 53ba05b | 2021-07-26 22:19:10 +0200 | [diff] [blame] | 563 | setlocal virtualedit& |
| 564 | set virtualedit& |
| 565 | endfunc |
| 566 | |
Bram Moolenaar | 8fe5b9c | 2023-01-28 16:37:37 +0000 | [diff] [blame] | 567 | func Test_virtualedit_setlocal() |
| 568 | enew |
| 569 | setglobal virtualedit=all |
| 570 | setlocal virtualedit=all |
| 571 | normal! l |
| 572 | redraw |
| 573 | setlocal virtualedit=none |
| 574 | call assert_equal(1, wincol()) |
| 575 | |
| 576 | setlocal virtualedit& |
| 577 | set virtualedit& |
| 578 | endfunc |
| 579 | |
Bram Moolenaar | 8f49e69 | 2022-08-09 14:19:40 +0100 | [diff] [blame] | 580 | func Test_virtualedit_mouse() |
| 581 | let save_mouse = &mouse |
| 582 | set mouse=a |
| 583 | set virtualedit=all |
zeertzjq | 03cd697 | 2023-09-20 20:08:40 +0200 | [diff] [blame] | 584 | botright new |
| 585 | let row = win_screenpos(0)[0] |
| 586 | 20vsplit |
| 587 | wincmd p |
Bram Moolenaar | 8f49e69 | 2022-08-09 14:19:40 +0100 | [diff] [blame] | 588 | |
| 589 | call setline(1, ["text\tword"]) |
| 590 | redraw |
zeertzjq | 03cd697 | 2023-09-20 20:08:40 +0200 | [diff] [blame] | 591 | call test_setmouse(row, 21 + 4) |
Bram Moolenaar | 8f49e69 | 2022-08-09 14:19:40 +0100 | [diff] [blame] | 592 | call feedkeys("\<LeftMouse>", "xt") |
| 593 | call assert_equal([0, 1, 4, 0, 4], getcurpos()) |
zeertzjq | 03cd697 | 2023-09-20 20:08:40 +0200 | [diff] [blame] | 594 | call test_setmouse(row, 21 + 5) |
Bram Moolenaar | 8f49e69 | 2022-08-09 14:19:40 +0100 | [diff] [blame] | 595 | call feedkeys("\<LeftMouse>", "xt") |
| 596 | call assert_equal([0, 1, 5, 0, 5], getcurpos()) |
zeertzjq | 03cd697 | 2023-09-20 20:08:40 +0200 | [diff] [blame] | 597 | call test_setmouse(row, 21 + 6) |
Bram Moolenaar | 8f49e69 | 2022-08-09 14:19:40 +0100 | [diff] [blame] | 598 | call feedkeys("\<LeftMouse>", "xt") |
| 599 | call assert_equal([0, 1, 5, 1, 6], getcurpos()) |
zeertzjq | 03cd697 | 2023-09-20 20:08:40 +0200 | [diff] [blame] | 600 | call test_setmouse(row, 21 + 7) |
Bram Moolenaar | 8f49e69 | 2022-08-09 14:19:40 +0100 | [diff] [blame] | 601 | call feedkeys("\<LeftMouse>", "xt") |
| 602 | call assert_equal([0, 1, 5, 2, 7], getcurpos()) |
zeertzjq | 03cd697 | 2023-09-20 20:08:40 +0200 | [diff] [blame] | 603 | call test_setmouse(row, 21 + 8) |
Bram Moolenaar | 8f49e69 | 2022-08-09 14:19:40 +0100 | [diff] [blame] | 604 | call feedkeys("\<LeftMouse>", "xt") |
| 605 | call assert_equal([0, 1, 5, 3, 8], getcurpos()) |
zeertzjq | 03cd697 | 2023-09-20 20:08:40 +0200 | [diff] [blame] | 606 | call test_setmouse(row, 21 + 9) |
Bram Moolenaar | 8f49e69 | 2022-08-09 14:19:40 +0100 | [diff] [blame] | 607 | call feedkeys("\<LeftMouse>", "xt") |
| 608 | call assert_equal([0, 1, 6, 0, 9], getcurpos()) |
zeertzjq | 03cd697 | 2023-09-20 20:08:40 +0200 | [diff] [blame] | 609 | call test_setmouse(row, 21 + 12) |
zeertzjq | e500ae8 | 2023-08-17 22:35:26 +0200 | [diff] [blame] | 610 | call feedkeys("\<LeftMouse>", "xt") |
| 611 | call assert_equal([0, 1, 9, 0, 12], getcurpos()) |
zeertzjq | 03cd697 | 2023-09-20 20:08:40 +0200 | [diff] [blame] | 612 | call test_setmouse(row, 21 + 13) |
zeertzjq | e500ae8 | 2023-08-17 22:35:26 +0200 | [diff] [blame] | 613 | call feedkeys("\<LeftMouse>", "xt") |
| 614 | call assert_equal([0, 1, 10, 0, 13], getcurpos()) |
zeertzjq | 03cd697 | 2023-09-20 20:08:40 +0200 | [diff] [blame] | 615 | call test_setmouse(row, 21 + 15) |
Bram Moolenaar | 8f49e69 | 2022-08-09 14:19:40 +0100 | [diff] [blame] | 616 | call feedkeys("\<LeftMouse>", "xt") |
| 617 | call assert_equal([0, 1, 10, 2, 15], getcurpos()) |
zeertzjq | 46a0582 | 2023-09-24 23:30:03 +0200 | [diff] [blame] | 618 | call test_setmouse(row, 21 + 20) |
| 619 | call feedkeys("\<LeftMouse>", "xt") |
| 620 | call assert_equal([0, 1, 10, 7, 20], getcurpos()) |
Bram Moolenaar | 8f49e69 | 2022-08-09 14:19:40 +0100 | [diff] [blame] | 621 | |
zeertzjq | db54e98 | 2023-09-21 16:33:09 +0200 | [diff] [blame] | 622 | setlocal nowrap |
| 623 | call setline(2, repeat('a', 19)) |
| 624 | normal! j14zl |
| 625 | redraw |
| 626 | call test_setmouse(row, 21 + 1) |
| 627 | call feedkeys("\<LeftMouse>", "xt") |
| 628 | call assert_equal([0, 1, 10, 2, 15], getcurpos()) |
| 629 | call test_setmouse(row, 21 + 11) |
| 630 | call feedkeys("\<LeftMouse>", "xt") |
| 631 | call assert_equal([0, 1, 10, 12, 25], getcurpos()) |
| 632 | call test_setmouse(row + 1, 21 + 1) |
| 633 | call feedkeys("\<LeftMouse>", "xt") |
| 634 | call assert_equal([0, 2, 15, 0, 15], getcurpos()) |
| 635 | call test_setmouse(row + 1, 21 + 11) |
| 636 | call feedkeys("\<LeftMouse>", "xt") |
| 637 | call assert_equal([0, 2, 20, 5, 25], getcurpos()) |
| 638 | |
| 639 | setlocal number numberwidth=2 |
| 640 | redraw |
| 641 | call test_setmouse(row, 21 + 3) |
| 642 | call feedkeys("\<LeftMouse>", "xt") |
| 643 | call assert_equal([0, 1, 10, 2, 15], getcurpos()) |
| 644 | call test_setmouse(row, 21 + 13) |
| 645 | call feedkeys("\<LeftMouse>", "xt") |
| 646 | call assert_equal([0, 1, 10, 12, 25], getcurpos()) |
| 647 | call test_setmouse(row + 1, 21 + 3) |
| 648 | call feedkeys("\<LeftMouse>", "xt") |
| 649 | call assert_equal([0, 2, 15, 0, 15], getcurpos()) |
| 650 | call test_setmouse(row + 1, 21 + 13) |
| 651 | call feedkeys("\<LeftMouse>", "xt") |
| 652 | call assert_equal([0, 2, 20, 5, 25], getcurpos()) |
| 653 | setlocal nonumber |
| 654 | |
| 655 | if has('signs') |
| 656 | sign define Sign1 text=口 |
| 657 | sign place 1 name=Sign1 line=1 |
| 658 | sign place 2 name=Sign1 line=2 |
| 659 | redraw |
| 660 | call test_setmouse(row, 21 + 3) |
| 661 | call feedkeys("\<LeftMouse>", "xt") |
| 662 | call assert_equal([0, 1, 10, 2, 15], getcurpos()) |
| 663 | call test_setmouse(row, 21 + 13) |
| 664 | call feedkeys("\<LeftMouse>", "xt") |
| 665 | call assert_equal([0, 1, 10, 12, 25], getcurpos()) |
| 666 | call test_setmouse(row + 1, 21 + 3) |
| 667 | call feedkeys("\<LeftMouse>", "xt") |
| 668 | call assert_equal([0, 2, 15, 0, 15], getcurpos()) |
| 669 | call test_setmouse(row + 1, 21 + 13) |
| 670 | call feedkeys("\<LeftMouse>", "xt") |
| 671 | call assert_equal([0, 2, 20, 5, 25], getcurpos()) |
| 672 | sign unplace 1 |
| 673 | sign unplace 2 |
| 674 | sign undefine Sign1 |
| 675 | endif |
| 676 | |
zeertzjq | 46a0582 | 2023-09-24 23:30:03 +0200 | [diff] [blame] | 677 | wincmd h |
| 678 | 4wincmd > |
| 679 | normal! gg24I. |
| 680 | redraw |
| 681 | call test_setmouse(row + 1, 12) |
| 682 | call feedkeys("\<LeftMouse>", "xt") |
| 683 | call assert_equal([0, 1, 24 + 9, 0, 24 + 12], getcurpos()) |
| 684 | call test_setmouse(row + 1, 13) |
| 685 | call feedkeys("\<LeftMouse>", "xt") |
| 686 | call assert_equal([0, 1, 24 + 10, 0, 24 + 13], getcurpos()) |
| 687 | call test_setmouse(row + 1, 15) |
| 688 | call feedkeys("\<LeftMouse>", "xt") |
| 689 | call assert_equal([0, 1, 24 + 10, 2, 24 + 15], getcurpos()) |
| 690 | call test_setmouse(row + 1, 20) |
| 691 | call feedkeys("\<LeftMouse>", "xt") |
| 692 | call assert_equal([0, 1, 24 + 10, 7, 24 + 20], getcurpos()) |
| 693 | |
Bram Moolenaar | 8f49e69 | 2022-08-09 14:19:40 +0100 | [diff] [blame] | 694 | bwipe! |
| 695 | let &mouse = save_mouse |
| 696 | set virtualedit& |
| 697 | endfunc |
| 698 | |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 699 | " this was replacing the NUL at the end of the line |
Bram Moolenaar | c249913 | 2022-09-16 22:16:59 +0100 | [diff] [blame] | 700 | func Test_virtualedit_replace_after_tab() |
| 701 | new |
| 702 | s/\v/ 0 |
| 703 | set ve=all |
| 704 | let @" = '' |
| 705 | sil! norm vPvr0 |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 706 | |
Bram Moolenaar | c249913 | 2022-09-16 22:16:59 +0100 | [diff] [blame] | 707 | call assert_equal("\t0", getline(1)) |
| 708 | set ve& |
| 709 | bwipe! |
| 710 | endfunc |
| 711 | |
| 712 | |
Bram Moolenaar | 54c8d22 | 2019-12-02 20:41:39 +0100 | [diff] [blame] | 713 | " vim: shiftwidth=2 sts=2 expandtab |