Facundo Casco
Facundo Casco

Reputation: 10605

Jump to the end of a long list of repeated pattern

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

Answers (3)

kev
kev

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

  • type vii to select identical lines (feel free to change the key-binding)
  • type zf to fold them.
  • type za to toggle folding

It's handy when you want to squeeze several empty line. It acts like C-x C-o in emacs.

Upvotes: 1

mogelbrod
mogelbrod

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

bheeshmar
bheeshmar

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

Related Questions