How do I jump to lines with the same indentation in gVim (or any other text editing tools)?

How to jump to next and previous lines with the same indentation in gVim (or any other text editing tool). For example:

This is first line
    Second line
          Third Line
    Fourth Line
          Fifth Line
Another Line
    Last Line

      

Here, if I place the cursor on the 'S' of the second line and press some keys, I need to move to the fourth and last lines (with the same indentation as the second line).

+3


source to share


1 answer


In Vim, I think the easiest way is to rip out the indentation and search for it. You can map the key to this. Something like:

:nnoremap <F3> 0y^/^<C-R>0\s\@!<CR>

      

  • 0y^

    moves to the beginning of the line and takes the first text on the line
  • /^

    starts searching from the beginning of the string
  • <C-R>0

    puts yanked text (indentation) in the search pattern
  • \s\@!

    requires that the text after the matching indentation does not become extra space (see :help

    /zero-width

    )
  • <CR>

    searches


Note that this will fail for non-indented lines, as there is nothing to copy between the beginning of the line and the first text on the line.

It will also stop working when you go to the only indented line, although it might reach those lines.

+5


source







All Articles