Reputation: 10605
I have a big file with a lot of lines that share the same pattern, something like this:
dbn.py:206 ... (some other text) <-- I am here
dbn.py:206 ... (some other text)
...
(something I don't know) <-- I want to jump here
Is there a quick way in Vim to jump to the place where the succession of dbp.py:206
ends?
Upvotes: 4
Views: 98
Reputation: 161884
I just write a function to select identical lines:
nnoremap vii :call SelectIdenticalLines()<CR>
fun! SelectIdenticalLines()
let s = getline('.')
let n = line('.')
let i = n
let j = n
while getline(i)==s && i>0
let i-=1
endwhile
while getline(j)==s && j<=line('$')
let j+=1
endwhile
call cursor(i+1, 0)
norm V
call cursor(j-1, 0)
endfun
It's handy when you want to squeeze several empty line. It acts like C-x C-o in emacs.
Upvotes: 1
Reputation: 2316
/^\(dbn.py\)\@!
Matches first line which does not start with the text inside the escaped parentheses.
If you want quick access to this you could add a vmap
which yanks the visually selected text and inserts it in the right spot (but first escaping it with escape(var, '/')
.
Try this vmap: vmap <leader>n "hy<Esc>/^\(<C-R>=escape(@h,'/')<CR>\)\@!<CR>
Press n when visually selecting the text you wish to skip and you should be placed on the next first line which does not begin with the selection.
Upvotes: 5
Reputation: 3205
One option is to go to the bottom of the file and search backwards for the last line you want, then go down one:
G ?^dbn\.py:206?+1
Upvotes: 0