278

I would like to show the current column in the statusbar, as is common in many other text editors. E.g. it's good to know if you are around column 80 or above.

How to show the current column in the statusbar?

Jonas
  • 26,874
  • 52
  • 105
  • 125
  • 2
    If you want to show the current column of cursor, then type :echo col('.'). – SibiCoder May 26 '16 at 07:21
  • See also: [Why does “set ruler” get reset to noruler?](https://vi.stackexchange.com/questions/13539/why-does-set-ruler-get-reset-to-noruler) – user Nov 01 '19 at 18:23

7 Answers7

316

Try if setting 'ruler' option is what you are looking for. On my computer at the bottom right shows the line and column where I have the cursor.

:set ruler

EDIT TO COMMENTS:

From the help of vim (command :help ruler):

If the number of characters displayed is different from the number of bytes in the text (e.g., for a TAB or a multi-byte character), both the text column (byte number) and the screen column are shown, separated with a dash.

You can try changing it with rulerformat option, like :set rulerformat=%l,%v

Birei
  • 3,612
  • 1
  • 16
  • 8
  • 1
    Yes, kind of. But that is showing a strange value e.g. `23,62-68` were 23 seem to be the line. How should I interpret `62-68` for the column? – Jonas Dec 06 '11 at 20:49
  • 11
    62 is counting tabs as one character, 68 is counting expanded tabs – RedGrittyBrick Dec 06 '11 at 20:58
  • 1
    From command ':help ruler': "If the number of characters displayed is different from the number of bytes in the text (e.g., for a TAB or a multi-byte character), both the text column (byte number) and the screen column are shown, separated with a dash." You can try changing it with 'rulerformat' option, like ':set rulerformat=%l,%v' – Birei Dec 06 '11 at 21:00
  • 1
    `ruler` doesn't work with split windows in Vim. – Mihai Nov 17 '15 at 16:03
  • 2
    @Jonas Not only tabs, as RedGrittyBrick said, but also characters versus bytes. This is very apparent in UTF-8 files where a single-character glyph has a multi-byte code point. For example, the Latin eñe (n with tilde over it, pronounced EN-yea) is a single character glyph but takes two bytes to represent the code point (\xC3B1), and one third (1/3) is a single character glyph with a three byte code point (\xE28593). – Luv2code Aug 10 '18 at 13:17
  • @ruler It does work for me in split windows. I think it always did. – Pavel Šimerda Oct 23 '20 at 06:49
  • this is not working when placed in `~/.vimrc` – Ricky Levi Sep 05 '22 at 12:17
40

See :help statusline for the many options available.

I have this in my ~/.vimrc in between a bunch of other directives:

set statusline+=col:\ %c,

which outputs

col: 64

in my statusline.

I don't have set ruler.

romainl
  • 22,554
  • 2
  • 49
  • 59
  • 1
    This doesn't work for me. I probably need some more settings. – Jonas Dec 06 '11 at 23:34
  • 4
    Jonas, You may have to use the ``set laststatus=2`` in your ``.vimrc`` to always display the status line. (0 -> never display the status line, 1 -> only if there are at least two windows, 2 -> always display the status line). – Pierre-Adrien Jan 17 '14 at 14:01
  • I used the following to provide space before this and the previous stuff on the statusline: set statusline+=\ col:\ %c, – David Baucum Feb 26 '15 at 17:36
  • I like this answer more than `ruler`,somebody else want to customize `vim` should try to edit `.vimrc` file. – zionpi Jul 16 '20 at 15:42
  • That will count bytes and not characters or columns, which means that if the line contains multi-byte characters such as `ξéã`, [the column count will be wrong](https://vi.stackexchange.com/q/27575). Using `%v` solves it. –  Nov 03 '20 at 19:35
  • with neovim, I run `:help statusline` then the first example is : `:set statusline=%<%f\ %h%m%r%=%-14.(%l,%c%V%)\ %P` which contains `%c%V` – bcag2 Jun 20 '22 at 13:24
33

Another way to do this is to do 'g Ctrl-G', which prints the current position of the cursor in five ways: Column, Line, Word, Character and Byte. (from http://vimdoc.sourceforge.net/htmldoc/editing.html#g_CTRL-G)

Peter
  • 439
  • 4
  • 4
  • This solution has something neat, that differentiates Column and VisibleColumn. Non printable characters are displayed 2 columns, but should be counted as one. If non printable characters the output looks like this: `RealColumn-VisibleColumn, Line, Word, Character and Byte`. – mxlian Mar 02 '16 at 11:44
  • This solution also works from `vi`, where `:se ruler?` gives `E519: Option not supported: ruler?` – krubo Jan 31 '21 at 01:17
20

I would depreciate using set ruler because I believe it is not compatible with the statusline options, e.g. if you set the statusline to display the full filepath in combination with set ruler

set statusline+=%F

set ruler

Then it does NOT display the column number but just the full filepath in the statusbar. However if you put the following in your .vimrc

set statusline+=%F\ %l\:%c

It will display everything correctly, namely the

[Filepath/filename] [linenumber]:[column number]

19

Or, leave 'ruler' unset, a performance gain, and press CTRL-G when you want to see the current column.

ma11hew28
  • 649
  • 1
  • 10
  • 20
  • 11
    Hitting Ctrl-Anything doesn't sound like a performance gain. We're typing characters. No human has fingers and eyes that fly fast enough to see this kind of performance difference. – macetw Apr 19 '17 at 20:30
7

For the other people that are looking for this answer and are not used to working with VIm, personally the simplest answer I've found is to add this line to the end of your .vimrc file in your home directory:

set ruler

Jay
  • 183
  • 1
  • 4
1

For permanent change you can just do:

echo "set ruler" >> ~/.vimrc
DimiDak
  • 231
  • 3
  • 11