1

In insert mode, using beam-cursor, the column number is, at least for me, not intuitive. Having for example the text:

abcde

and using %v on statusline.

If cursor is before a it say 1, after e it say 6 etc. Perhaps only me being difficult, and at least picky, but how to show one less on status bar in Vim? I would like it to show length of line / string.

Before a = 0, after e = 5 etc. In normal mode, with block-cursor, the column number is fine.

1
  • There are 2 difficult problems in computer science: 1) cache invalidation, 2) naming things and 3) off by 1 errors Commented Feb 19, 2015 at 5:14

1 Answer 1

2

One way to solve it is to use a custom function for status line:

fun! ImColnr()
    return printf("%d", mode() == "i" ? col(".") - 1 : col("."))
endfun

set statusline=%{ImColnr()}

In my usage I have:

fun! ImColnr()
    return printf(",%04d", mode() == "i" ? col(".") - 1 : col("."))
endfun

as I like fixed with with leading zeroes. My statusline, (somewhat bloated), in full is:

set statusline=%F%m%r%h%w[%L][%{&ff}]%{(&fenc!=''?&fenc:&enc)}%y[%p%%][%04l%{ImColnr()}]\ \ \ F[%2n]:\ %t

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.