Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there an equivalent for wc -l to have the number of columns of a vim file? (I have a file with several rows and columns separated by spaces)

share|improve this question
up vote 3 down vote accepted

Considering that you have equal number of columns in all the rows, this should work for you:

awk -F' ' '{print NF; exit}' <filename>

awk is a patter scanning language

-F is the field separator; ' ' tells awk that columns are space separated. This will work even if there is more than one space between two columns.

print NF; exit prints the number of fields and exits

Caveat: This will report the number of columns in the first line only.

Refer to awk manual for more options.

Source: Similar question on SO

share|improve this answer
space is default field-separator for awk. So you can use awk '{print NF; exit}' <filename> for the same. – souravc Feb 13 '14 at 13:29
Better to specify it explicitly so other users can modify it to their needs. Anyways, thanks @souravc! – i08in Feb 13 '14 at 13:30
This is absolutely fine. I just said it as OP asked in question "columns separated by spaces". never mind :) – souravc Feb 13 '14 at 14:01

Just press CTRL-W v and the file you are working one will be split to two separate independent columns. Repeat CTRL-W v as many times as you want.

Set scrollbind: set scrollbind to columns that you want to scroll in-sync.

For example:

vim afile         # Open a file
^w v              # split it
gg                # go to top
:set scrollbind   # bind this one
^w l              # go to the new split
L                 # got to bottom of this split
zt                # make it the top line
:set scrollbind   # bind with this one

Now while you move on one columnt, the other one scrolls so as if the first column overflows the text to the second column.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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