2017-01-10 08:21:48 -07:00
|
|
|
" Test for gn command
|
|
|
|
|
|
|
|
func Test_gn_command()
|
2018-06-24 01:37:59 -07:00
|
|
|
set belloff=all
|
|
|
|
noautocmd new
|
2017-01-10 08:21:48 -07:00
|
|
|
" replace a single char by itsself quoted:
|
|
|
|
call setline('.', 'abc x def x ghi x jkl')
|
2018-08-19 12:33:30 -07:00
|
|
|
let @/ = 'x'
|
2017-01-10 08:21:48 -07:00
|
|
|
exe "norm! cgn'x'\<esc>.."
|
|
|
|
call assert_equal("abc 'x' def 'x' ghi 'x' jkl", getline('.'))
|
|
|
|
sil! %d_
|
2018-06-24 01:37:59 -07:00
|
|
|
|
2017-01-10 08:21:48 -07:00
|
|
|
" simple search match
|
|
|
|
call setline('.', 'foobar')
|
2018-08-19 12:33:30 -07:00
|
|
|
let @/ = 'foobar'
|
2017-01-10 08:21:48 -07:00
|
|
|
exe "norm! gncsearchmatch"
|
|
|
|
call assert_equal('searchmatch', getline('.'))
|
|
|
|
sil! %d _
|
2018-06-24 01:37:59 -07:00
|
|
|
|
2017-01-10 08:21:48 -07:00
|
|
|
" replace a multi-line match
|
|
|
|
call setline('.', ['', 'one', 'two'])
|
2018-08-19 12:33:30 -07:00
|
|
|
let @/ = 'one\_s*two\_s'
|
2017-01-10 08:21:48 -07:00
|
|
|
exe "norm! gnceins\<CR>zwei"
|
|
|
|
call assert_equal(['','eins','zwei'], getline(1,'$'))
|
|
|
|
sil! %d _
|
2018-06-24 01:37:59 -07:00
|
|
|
|
2017-01-10 08:21:48 -07:00
|
|
|
" test count argument
|
|
|
|
call setline('.', ['', 'abcdx | abcdx | abcdx'])
|
2018-08-19 12:33:30 -07:00
|
|
|
let @/ = '[a]bcdx'
|
2017-01-10 08:21:48 -07:00
|
|
|
exe "norm! 2gnd"
|
|
|
|
call assert_equal(['','abcdx | | abcdx'], getline(1,'$'))
|
|
|
|
sil! %d _
|
2018-06-24 01:37:59 -07:00
|
|
|
|
2017-01-10 08:21:48 -07:00
|
|
|
" join lines
|
|
|
|
call setline('.', ['join ', 'lines'])
|
2018-08-19 12:33:30 -07:00
|
|
|
let @/ = '$'
|
2017-01-10 08:21:48 -07:00
|
|
|
exe "norm! 0gnd"
|
|
|
|
call assert_equal(['join lines'], getline(1,'$'))
|
|
|
|
sil! %d _
|
2018-06-24 01:37:59 -07:00
|
|
|
|
2017-01-10 08:21:48 -07:00
|
|
|
" zero-width match
|
|
|
|
call setline('.', ['', 'zero width pattern'])
|
2018-08-19 12:33:30 -07:00
|
|
|
let @/ = '\>\zs'
|
2017-01-10 08:21:48 -07:00
|
|
|
exe "norm! 0gnd"
|
|
|
|
call assert_equal(['', 'zerowidth pattern'], getline(1,'$'))
|
|
|
|
sil! %d _
|
2018-06-24 01:37:59 -07:00
|
|
|
|
2017-01-10 08:21:48 -07:00
|
|
|
" delete first and last chars
|
|
|
|
call setline('.', ['delete first and last chars'])
|
2018-08-19 12:33:30 -07:00
|
|
|
let @/ = '^'
|
2017-01-10 08:21:48 -07:00
|
|
|
exe "norm! 0gnd$"
|
2018-08-19 12:33:30 -07:00
|
|
|
let @/ = '\zs'
|
2017-01-10 08:21:48 -07:00
|
|
|
exe "norm! gnd"
|
|
|
|
call assert_equal(['elete first and last char'], getline(1,'$'))
|
|
|
|
sil! %d _
|
2018-06-24 01:37:59 -07:00
|
|
|
|
2017-01-10 08:21:48 -07:00
|
|
|
" using visual mode
|
|
|
|
call setline('.', ['', 'uniquepattern uniquepattern'])
|
|
|
|
exe "norm! /[u]niquepattern/s\<cr>vlgnd"
|
|
|
|
call assert_equal(['', ' uniquepattern'], getline(1,'$'))
|
|
|
|
sil! %d _
|
2018-06-24 01:37:59 -07:00
|
|
|
|
2017-01-10 08:21:48 -07:00
|
|
|
" backwards search
|
|
|
|
call setline('.', ['my very excellent mother just served us nachos'])
|
2018-08-19 12:33:30 -07:00
|
|
|
let @/ = 'mother'
|
2017-01-10 08:21:48 -07:00
|
|
|
exe "norm! $cgNmongoose"
|
|
|
|
call assert_equal(['my very excellent mongoose just served us nachos'], getline(1,'$'))
|
|
|
|
sil! %d _
|
2018-06-24 01:37:59 -07:00
|
|
|
|
2017-01-10 08:21:48 -07:00
|
|
|
" search for single char
|
|
|
|
call setline('.', ['','for (i=0; i<=10; i++)'])
|
2018-08-19 12:33:30 -07:00
|
|
|
let @/ = 'i'
|
2017-01-10 08:21:48 -07:00
|
|
|
exe "norm! cgnj"
|
|
|
|
call assert_equal(['','for (j=0; i<=10; i++)'], getline(1,'$'))
|
|
|
|
sil! %d _
|
2018-06-24 01:37:59 -07:00
|
|
|
|
2017-01-10 08:21:48 -07:00
|
|
|
" search hex char
|
|
|
|
call setline('.', ['','Y'])
|
|
|
|
set noignorecase
|
2018-08-19 12:33:30 -07:00
|
|
|
let @/ = '\%x59'
|
2017-01-10 08:21:48 -07:00
|
|
|
exe "norm! gnd"
|
|
|
|
call assert_equal(['',''], getline(1,'$'))
|
|
|
|
sil! %d _
|
2018-06-24 01:37:59 -07:00
|
|
|
|
2017-01-10 08:21:48 -07:00
|
|
|
" test repeating gdn
|
|
|
|
call setline('.', ['', '1', 'Johnny', '2', 'Johnny', '3'])
|
2018-08-19 12:33:30 -07:00
|
|
|
let @/ = 'Johnny'
|
2017-01-10 08:21:48 -07:00
|
|
|
exe "norm! dgn."
|
|
|
|
call assert_equal(['','1', '', '2', '', '3'], getline(1,'$'))
|
|
|
|
sil! %d _
|
2018-06-24 01:37:59 -07:00
|
|
|
|
2017-01-10 08:21:48 -07:00
|
|
|
" test repeating gUgn
|
|
|
|
call setline('.', ['', '1', 'Depp', '2', 'Depp', '3'])
|
2018-08-19 12:33:30 -07:00
|
|
|
let @/ = 'Depp'
|
2017-01-10 08:21:48 -07:00
|
|
|
exe "norm! gUgn."
|
|
|
|
call assert_equal(['', '1', 'DEPP', '2', 'DEPP', '3'], getline(1,'$'))
|
|
|
|
sil! %d _
|
2018-06-24 01:37:59 -07:00
|
|
|
|
2017-01-10 08:21:48 -07:00
|
|
|
" test using look-ahead assertions
|
|
|
|
call setline('.', ['a:10', '', 'a:1', '', 'a:20'])
|
2018-08-19 12:33:30 -07:00
|
|
|
let @/ = 'a:0\@!\zs\d\+'
|
2017-01-10 08:21:48 -07:00
|
|
|
exe "norm! 2nygno\<esc>p"
|
|
|
|
call assert_equal(['a:10', '', 'a:1', '1', '', 'a:20'], getline(1,'$'))
|
|
|
|
sil! %d _
|
2018-06-24 01:37:59 -07:00
|
|
|
|
|
|
|
" 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_
|
|
|
|
|
2018-08-19 05:39:21 -07:00
|
|
|
" search upwards with nowrapscan set
|
|
|
|
call setline('.', ['foo', 'bar', 'foo', 'baz'])
|
|
|
|
set nowrapscan
|
2018-08-19 12:33:30 -07:00
|
|
|
let @/ = 'foo'
|
2018-08-19 05:39:21 -07:00
|
|
|
$
|
|
|
|
norm! dgN
|
|
|
|
call assert_equal(['foo', 'bar', '', 'baz'], getline(1,'$'))
|
|
|
|
sil! %d_
|
|
|
|
|
2018-08-19 12:33:30 -07:00
|
|
|
" 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_
|
|
|
|
|
2018-06-24 01:37:59 -07:00
|
|
|
set wrapscan&vim
|
|
|
|
set belloff&vim
|
2017-01-10 08:21:48 -07:00
|
|
|
endfu
|
|
|
|
|
2019-05-27 03:05:11 -07:00
|
|
|
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
|
|
|
|
|
2017-03-14 01:58:13 -07:00
|
|
|
" vim: shiftwidth=2 sts=2 expandtab
|