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


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.

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

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

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

set statusline=%{ImColnr()}

In my usage I have:

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

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, privacy policy and cookie policy

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