blob: 3337e79492953855b4e09c4b5310f9acc34eda31 [file] [log] [blame]
Bram Moolenaar9aa15692017-08-19 15:05:32 +02001" Tests for 'virtualedit'.
2
3func Test_yank_move_change()
Bram Moolenaard41babe2017-08-30 17:01:35 +02004 new
Bram Moolenaar9aa15692017-08-19 15:05:32 +02005 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
31endfunc
Bram Moolenaard41babe2017-08-30 17:01:35 +020032
33func 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=
43endfunc
Bram Moolenaardb0eede2018-04-25 22:38:17 +020044
Bram Moolenaar630afe82018-06-28 19:26:28 +020045func 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 Moolenaar30276f22019-01-24 17:59:39 +010051 call setline(1, range(20))
52 exe "normal! gg2jv10lr\<c-k>hh"
53 call assert_equal(["1", "───────────", "3"], getline(2,4))
Bram Moolenaar630afe82018-06-28 19:26:28 +020054
55 bwipe!
56 set virtualedit=
57endfunc
58
Bram Moolenaardb0eede2018-04-25 22:38:17 +020059func 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=
75endfunc
Bram Moolenaar77ccc002019-10-31 03:21:25 +010076
77func Test_edit_change()
78 new
79 set virtualedit=all
80 call setline(1, "\t⒌")
81 normal Cx
82 call assert_equal('x', getline(1))
83 bwipe!
Bram Moolenaar6f1f0ca2019-12-01 18:16:18 +010084 set virtualedit=
85endfunc
86
87" Test for pasting before and after a tab character
88func Test_paste_in_tab()
89 new
90 let @" = 'xyz'
91 set virtualedit=all
92 call append(0, "a\tb")
93 call cursor(1, 2, 6)
94 normal p
95 call assert_equal("a\txyzb", getline(1))
96 call setline(1, "a\tb")
97 call cursor(1, 2)
98 normal P
99 call assert_equal("axyz\tb", getline(1))
100
101 " Test for virtual block paste
102 call setreg('"', 'xyz', 'b')
103 call setline(1, "a\tb")
104 call cursor(1, 2, 6)
105 normal p
106 call assert_equal("a\txyzb", getline(1))
107 call setline(1, "a\tb")
108 call cursor(1, 2, 6)
109 normal P
110 call assert_equal("a xyz b", getline(1))
111
112 " Test for virtual block paste with gp and gP
113 call setline(1, "a\tb")
114 call cursor(1, 2, 6)
115 normal gp
116 call assert_equal("a\txyzb", getline(1))
117 call assert_equal([0, 1, 6, 0, 12], getcurpos())
118 call setline(1, "a\tb")
119 call cursor(1, 2, 6)
120 normal gP
121 call assert_equal("a xyz b", getline(1))
122 call assert_equal([0, 1, 12, 0 ,12], getcurpos())
123
124 bwipe!
125 set virtualedit=
Bram Moolenaar77ccc002019-10-31 03:21:25 +0100126endfunc