Go to end of long list of repeating pattern

I have a large file with a lot of lines that have the same template, 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 go to where the dbp.py:206 sequence dbp.py:206 ?

+4
source share
3 answers

/ ^\(dbn.py\)\@!

Matches the first line that does not start with text inside chamfered brackets.

If you need quick access to this, you can add a vmap that grabs the visually selected text and inserts it in the right place (but first avoiding it with escape(var, '/') .

Try this vmap: vmap <leader>n "hy<Esc>/^\(<CR>=escape(@h,'/')<CR>\)\@!<CR>
Press n when visually select the text you want to skip, and you should be placed on the next first line, which does not start with highlighting.

+5
source

I just write a function to select identical strings:

 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 strings (feel free to change the key binding)
  • type zf to collapse them.
  • type za to switch folding

This is useful if you want to compress multiple blank lines. It acts like Cx Co in emacs.

+1
source

One option is to go to the bottom of the file and search backward for the last line you want, and then go down:

G ?^dbn\.py:206?+1

0
source

All Articles