Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim: highlight every Nth line?

Tags:

vim

I'm using Vim to write something where "pages" are important. Pages are a fixed number of lines.

I use :set colorcolumn to highlight the right margin. Is there anything similar to highlight every Nth line of the file?

like image 307
ggambett Avatar asked Dec 21 '13 12:12

ggambett


Video Answer


1 Answers

The solution below:

function HighlightEvery(lineNumber, lineEnd)
    highlight myhighlightpattern ctermbg=darkred guibg=darkred
    let pattern="/"
    let i = 0
    while i < a:lineEnd
        let i += a:lineNumber
        let pattern .= "\\%" . i . "l\\|"
    endwhile
    let pattern .= "\\%0l/"
    let commandToExecute = "match myhighlightpattern ".pattern
    execute commandToExecute
endfunction

command -nargs=* Highlightevery call HighlightEvery(<f-args>)

Add the code above in your .vimrc,

and call

:Highlightevery 10 1000

will highlight every 10 lines in to line number 1000.

like image 144
albusshin Avatar answered Nov 15 '22 08:11

albusshin