简体   繁体   中英

How to get character count using vi or vim

How do you get character location count from a text file using vi?

I tried ":goto number" and it does not work in Linux.

To clarify my question, if I have a file with say 3 lines:

I am going for a walk 
because today is a 
beautiful day.

I want to say find me a letter in position 30 and it will jump to line 2 highlighting letter 't' from word 'today'. This is similar to concept of :goto 30 in macos vi but for Linux

Use g CTRL-G

The output looks like

Col 1 of 5; Line 1 of 31; Word 1 of 48; Byte 1 of 571

Col 1 of 5; refers to the position of the cursor on the line you are on

Line 1 of 31; refers to the line your cursor is currently on

Byte 1 of 571 refers to the character you are on (byte 1) vs the total bytes, or "characters" in the file (571)

UPDATE

Based on your expanded explanation, this should be what you need:

:go30

Also I'd like you to think of "characters" and use the term "bytes" -- It will make your future Google searches about vim more fruitful.

Here is what it looks like on command line:

:go30

Count characters in just part of a file (or all of file if you need) First visualise the area you want to count.

  1. visualize a paragraph with v}
  2. visualize whole file with ggVG

then type

:%s/\%V./&/g

I needed this to count my twitter posts (280 character limit)

I found the solution to my problem. It looks like I had 'vi' and 'vim' installed on my system. By default, I was using 'vi' to edit the file and :goto 30 did not work. After a bit of digging around I found that 'vi' was part of the vim-minimal package. And 'vim' was part of the vim-enhanced package. When I tried 'vim' instead of 'vi' the :goto 30 worked! So it looks like it is definitely package related. Thanks Zak, pointing in the right direction and to all for the help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM