www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - [OT] vim tip with column limits

reply Jonathan M Davis <newsgroup.d jmdavisprog.com> writes:
I've wanted this for ages and just figured out how to do it, so I figured
that I'd share for those vim users who care.

The :set cc=x command lets you put a vertical line in vim (cc standing for
colorcolumn). e.g. if there's a line limit of 80 characters, if you do
:set cc=81, then there will be a vertical red line on column 81, so anything
left of the red line is good, and if you're on the red line or beyond it,
you've gone too far. That makes it _way_ easier to deal with line limits
than it would be otherwise.

That's all well and good, and I've known that for ages. The problem is that
I've wanted two vertical lines. Phobos has a soft line limit of 80
characters and a hard line limit of 120, and we try and keep documentation
comments within 80. So, ideally, I'd have a vertical line on column 81 and
one on 121. But there's only one cc. So, I've had to keep resetting cc
depending on whether I wanted to see where the soft limit / documentation
limit was or where the hard limit was. And that's annoying.

However, I just went digging around again to see if I could find an
alternate solution, and I've now figured out that while there is only one cc
you can set, you can actually give it multiple values. e.g. :set cc=81,121
will give you vertical lines on both columns 81 and 121, which is exactly
what I've been trying to do (and you can provide more comma-separate numbers
if you have a reason for more than two lines).

So, now I can just set cc once, rather than having to adjust it
periodically.

It would be nice if I could give the lines different colors (it does look
like it's possible to change the colors of the lines but not individually),
but it's already fantastic that there's a way to have multiple at all -
particularly since I had no clue before that that was even possible.

- Jonathan M Davis
Oct 08
next sibling parent Anonymouse <asdf asdf.net> writes:
On Monday, 9 October 2017 at 00:24:02 UTC, Jonathan M Davis wrote:
 However, I just went digging around again to see if I could 
 find an alternate solution, and I've now figured out that while 
 there is only one cc you can set, you can actually give it 
 multiple values. e.g. :set cc=81,121 will give you vertical 
 lines on both columns 81 and 121, which is exactly what I've 
 been trying to do (and you can provide more comma-separate 
 numbers if you have a reason for more than two lines).
Big thanks. Still exploring vim and this is something I hadn't thought possible.
Oct 08
prev sibling next sibling parent reply lobo <swamp.lobo gmail.com> writes:
On Monday, 9 October 2017 at 00:24:02 UTC, Jonathan M Davis wrote:
 I've wanted this for ages and just figured out how to do it, so 
 I figured that I'd share for those vim users who care.

 [...]
This presentation gave me a few vim ideas, you might also like it. https://www.youtube.com/watch?v=aHm36-na4-4 bye, lobo
Oct 08
parent Jonathan M Davis <newsgroup.d jmdavisprog.com> writes:
On Monday, October 09, 2017 02:03:16 lobo via Digitalmars-d wrote:
 On Monday, 9 October 2017 at 00:24:02 UTC, Jonathan M Davis wrote:
 I've wanted this for ages and just figured out how to do it, so
 I figured that I'd share for those vim users who care.

 [...]
This presentation gave me a few vim ideas, you might also like it. https://www.youtube.com/watch?v=aHm36-na4-4
That was a good video. It's always kind of funny how much work programmers will go to, because they're lazy. :) - Jonathan M Davis
Oct 08
prev sibling next sibling parent Steven Schveighoffer <schveiguy yahoo.com> writes:
On 10/8/17 8:24 PM, Jonathan M Davis wrote:
 I've wanted this for ages and just figured out how to do it, so I figured
 that I'd share for those vim users who care.
 
 The :set cc=x command lets you put a vertical line in vim (cc standing for
 colorcolumn). e.g. if there's a line limit of 80 characters, if you do
 :set cc=81, then there will be a vertical red line on column 81, so anything
 left of the red line is good, and if you're on the red line or beyond it,
 you've gone too far. That makes it _way_ easier to deal with line limits
 than it would be otherwise.
 
 That's all well and good, and I've known that for ages. The problem is that
 I've wanted two vertical lines. Phobos has a soft line limit of 80
 characters and a hard line limit of 120, and we try and keep documentation
 comments within 80. So, ideally, I'd have a vertical line on column 81 and
 one on 121. But there's only one cc. So, I've had to keep resetting cc
 depending on whether I wanted to see where the soft limit / documentation
 limit was or where the hard limit was. And that's annoying.
 
 However, I just went digging around again to see if I could find an
 alternate solution, and I've now figured out that while there is only one cc
 you can set, you can actually give it multiple values. e.g. :set cc=81,121
 will give you vertical lines on both columns 81 and 121, which is exactly
 what I've been trying to do (and you can provide more comma-separate numbers
 if you have a reason for more than two lines).
Very nice! I typically just format lines with :gql (I have it mapped to capital K) So I don't typically need a visual indicator, as long as I don't forget to reformat a line. But I will try with this to see how it goes. -Steve
Oct 08
prev sibling next sibling parent Anton Pastukhov <pastuhov85 gmail.com> writes:
On Monday, 9 October 2017 at 00:24:02 UTC, Jonathan M Davis wrote:
 I've wanted this for ages and just figured out how to do it, so 
 I figured that I'd share for those vim users who care.
https://github.com/nathanaelkane/vim-indent-guides allows to have two or more lines of different colors.
Oct 09
prev sibling next sibling parent mark_mcs <mark mnetcs.com> writes:
On Monday, 9 October 2017 at 00:24:02 UTC, Jonathan M Davis wrote:
 It would be nice if I could give the lines different colors (it 
 does look like it's possible to change the colors of the lines 
 but not individually), but it's already fantastic that there's 
 a way to have multiple at all - particularly since I had no 
 clue before that that was even possible.
I didn't even know about cc. I've always used a custom highlighter for this: hi LineLimit ctermbg=red ctermfg=white guibg=#be322f match LineLimit /\%121v/
Oct 09
prev sibling parent reply lithium iodate <whatdoiknow doesntexist.net> writes:
On Monday, 9 October 2017 at 00:24:02 UTC, Jonathan M Davis wrote:
[…]
Thanks for the tip!
Oct 09
parent reply Eduard Staniloiu <edi33416 gmail.com> writes:
On Monday, 9 October 2017 at 13:38:18 UTC, lithium iodate wrote:
 On Monday, 9 October 2017 at 00:24:02 UTC, Jonathan M Davis 
 wrote:
[…]
Thanks for the tip!
You might also want to use automatic word wrapping [0] for 120 chars. Cheers, Eduard [0] - http://vim.wikia.com/wiki/Automatic_word_wrapping
Oct 11
parent Jonathan M Davis <newsgroup.d jmdavisprog.com> writes:
On Wednesday, October 11, 2017 07:59:51 Eduard Staniloiu via Digitalmars-d 
wrote:
 On Monday, 9 October 2017 at 13:38:18 UTC, lithium iodate wrote:
 On Monday, 9 October 2017 at 00:24:02 UTC, Jonathan M Davis

 wrote:
[…]
Thanks for the tip!
You might also want to use automatic word wrapping [0] for 120 chars. Cheers, Eduard [0] - http://vim.wikia.com/wiki/Automatic_word_wrapping
That's also potentially a viable solution, but personally, I've never particularly liked how vim's word wrapping behaves, and I've generally avoided it. Simply knowing where the line limits are so that I know when I've gone too far works well for me. Other really useful stuff along those lines has been highlighting tabs and any trailing whitespace in red. So, I always know that it's there and needs to be removed (though that meant that I had to adjust my .vimrc when I was unlucky enough to have to use tabs where I was working). I don't generally have vim do much for me automatically (cindent is about the only automatic behavior that I have on that I can think of). Rather, I know what commands I need to do what I want or add commands that do it if that helps my productivity, and then I use the commands when I need them. - Jonathan M Davis
Oct 11