1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
" Test for gn command
func Test_gn_command()
noautocmd new
" replace a single char by itsself quoted:
call setline('.', 'abc x def x ghi x jkl')
let @/ = 'x'
exe "norm! cgn'x'\<esc>.."
call assert_equal("abc 'x' def 'x' ghi 'x' jkl", getline('.'))
sil! %d_
" simple search match
call setline('.', 'foobar')
let @/ = 'foobar'
exe "norm! gncsearchmatch"
call assert_equal('searchmatch', getline('.'))
sil! %d _
" replace a multi-line match
call setline('.', ['', 'one', 'two'])
let @/ = 'one\_s*two\_s'
exe "norm! gnceins\<CR>zwei"
call assert_equal(['','eins','zwei'], getline(1,'$'))
sil! %d _
" test count argument
call setline('.', ['', 'abcdx | abcdx | abcdx'])
let @/ = '[a]bcdx'
exe "norm! 2gnd"
call assert_equal(['','abcdx | | abcdx'], getline(1,'$'))
sil! %d _
" join lines
call setline('.', ['join ', 'lines'])
let @/ = '$'
exe "norm! 0gnd"
call assert_equal(['join lines'], getline(1,'$'))
sil! %d _
" zero-width match
call setline('.', ['', 'zero width pattern'])
let @/ = '\>\zs'
exe "norm! 0gnd"
call assert_equal(['', 'zerowidth pattern'], getline(1,'$'))
sil! %d _
" delete first and last chars
call setline('.', ['delete first and last chars'])
let @/ = '^'
exe "norm! 0gnd$"
let @/ = '\zs'
exe "norm! gnd"
call assert_equal(['elete first and last char'], getline(1,'$'))
sil! %d _
" using visual mode
call setline('.', ['', 'uniquepattern uniquepattern'])
exe "norm! /[u]niquepattern/s\<cr>vlgnd"
call assert_equal(['', ' uniquepattern'], getline(1,'$'))
sil! %d _
" backwards search
call setline('.', ['my very excellent mother just served us nachos'])
let @/ = 'mother'
exe "norm! $cgNmongoose"
call assert_equal(['my very excellent mongoose just served us nachos'], getline(1,'$'))
sil! %d _
" search for single char
call setline('.', ['','for (i=0; i<=10; i++)'])
let @/ = 'i'
exe "norm! cgnj"
call assert_equal(['','for (j=0; i<=10; i++)'], getline(1,'$'))
sil! %d _
" search hex char
call setline('.', ['','Y'])
set noignorecase
let @/ = '\%x59'
exe "norm! gnd"
call assert_equal(['',''], getline(1,'$'))
sil! %d _
" test repeating gdn
call setline('.', ['', '1', 'Johnny', '2', 'Johnny', '3'])
let @/ = 'Johnny'
exe "norm! dgn."
call assert_equal(['','1', '', '2', '', '3'], getline(1,'$'))
sil! %d _
" test repeating gUgn
call setline('.', ['', '1', 'Depp', '2', 'Depp', '3'])
let @/ = 'Depp'
exe "norm! gUgn."
call assert_equal(['', '1', 'DEPP', '2', 'DEPP', '3'], getline(1,'$'))
sil! %d _
" test using look-ahead assertions
call setline('.', ['a:10', '', 'a:1', '', 'a:20'])
let @/ = 'a:0\@!\zs\d\+'
exe "norm! 2nygno\<esc>p"
call assert_equal(['a:10', '', 'a:1', '1', '', 'a:20'], getline(1,'$'))
sil! %d _
" test using nowrapscan
set nowrapscan
call setline(1, 'foo bar baz')
exe "norm! /bar/e\<cr>"
exe "norm! gnd"
call assert_equal(['foo baz'], getline(1,'$'))
sil! %d_
" search upwards with nowrapscan set
call setline('.', ['foo', 'bar', 'foo', 'baz'])
set nowrapscan
let @/ = 'foo'
$
norm! dgN
call assert_equal(['foo', 'bar', '', 'baz'], getline(1,'$'))
sil! %d_
" search using the \zs atom
call setline(1, [' nnoremap', '' , 'nnoremap'])
set wrapscan&vim
let @/ = '\_s\zsnnoremap'
$
norm! cgnmatch
call assert_equal([' nnoremap', '', 'match'], getline(1,'$'))
sil! %d_
set wrapscan&vim
endfu
func Test_gn_multi_line()
new
call setline(1, [
\ 'func Tm1()',
\ ' echo "one"',
\ 'endfunc',
\ 'func Tm2()',
\ ' echo "two"',
\ 'endfunc',
\ 'func Tm3()',
\ ' echo "three"',
\ 'endfunc',
\])
/\v^func Tm\d\(\)\n.*\zs".*"\ze$
normal jgnrx
call assert_equal(' echo xxxxx', getline(5))
bwipe!
endfunc
" vim: shiftwidth=2 sts=2 expandtab
|