On Wednesday, November 17, 2021 at 4:01:00 PM UTC+1 [email protected]
wrote:
> Hello,
>
> When I set `cols=80` and enable line numbering (`number`), I lose the last
> few columns for code because MacVim uses them for the line numbers.
>
> Is it possible to make the `cols` setting account for line numbering, so
> that I get 80 columns for editing code, regardless of whether line
> numbering is on (and how many columns the line numbers themselves need)?
>
> Thank you!
>
> Cheers,
> -Felipe Gasper
>
Vim's 'columns' setting includes the line number (if any), whose width
varies according to how many lines are in the file and on the 'numberwidth'
setting. No matter which options you set, if you are running Vim in an
80-column-wide terminal, you won't be able to get 80 columns for the text
plus some additional columns for the line number. Otherwise, if your screen
is wide enough, and your Vim is compiled with +float, you can get the width
of the linenumber as (untested)
&l:nu?(max([&l:numberwidth,floor(log10(line('$')))+2])):0
floor(log10(n)) should be one less than the number of decimal digits needed
to write the number n, and +2 because we add back not only that "one less"
but also the single empty column between the line number and the text.
Add the value of the above expression to the desired textwidth (here 80),
set 'columns' to the sum of both, then check if you got what you wanted
(because setting 'columns' is limited by the actual available width: if I
try to set it to 999 it will actually be set to only the number of
characters that can be displayed onscreen).
Best regards,
Tony.
--
--
You received this message from the "vim_mac" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_mac" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_mac/baa69f20-e47d-4c1f-a210-25fc959abccan%40googlegroups.com.