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