Reputation: 17
How to skip the display of line number for commented lines? I want to skip line number for every line that starts with #
when coding python
here is what I mean:
1 print "hello"
# skiping line number for commented line
2 print "line number for next line"
3 print "now the next line number"
# again skipping another line that's commented with hash symbol
4 print "I hope you got what I meant!"
Upvotes: 0
Views: 292
Reputation: 12895
I advocate use the hybrid numbering configuration and foregoing any idea of skipping lines since you'll be giving up some of the valuable motions that depend on comments being counted as lines. First, to turn on the hybrid line numbering in vim7.4+, add to your .vimrc:
set relativenumber
set number
This gives you the absolute line numbers AND their relative line numbers from your current cursor line position. Next, work with not against vim's very sensible approach to reap its powerful ability to move lines using absolute line numbers, e.g:
:12m204
Which instructs vim to move line #204 right after line #12. Or with relative numbering:
:+12m.
Which tells vim to move the line 12 relative lines ahead to right after your current line. (The fancier variant is using marks and searches to move lines, e.g.: :/foo/m'a
)
These kinds of motion control are handy when you want toggle comments -- the very thing you wanted to skip -- since you can do something like the following:
CtrlV 10j I#Esc
Which turns on visual block, moves the block 10 lines down and Inserts a hash comment. Obviously the reverse can be done as well, affording you an fast way to toggle chunks of code as a comment, which seems almost like a necessary capability while troubleshooting and not so easy to do if commented lines were skipped.
Upvotes: -1
Reputation: 195059
How to skip the display of line number for commented lines?
The current vim version (v8.0) doesn't have built-in support for your requirement.
It is hard (impossible perhaps) to implement as well even if you write a vim plugin.
The answer is, do patch on vim source codes. If it is really important for you. I thought this would be a big effort, since you have to care about all line-based motions as well, and it will break many vim-plugins.
Or use other text processing tool (awk?) to handle your text automatically. But we have to know your final goal.
Upvotes: 2