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