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
Counting number of words To count the number of words in the current buffer, press g then Ctrl-g.
This makes it easy to count the number of occurrences of the word under the cursor: first press * to search for the current word, then enter :%s///gn to count all occurrences of that word.
To find a character string, type / followed by the string you want to search for, and then press Return. vi positions the cursor at the next occurrence of the string. For example, to find the string “meta,” type /meta followed by Return.
To get exact character count of string, use printf, as opposed to echo, cat, or running wc -c directly on a file, because using echo, cat, etc will count a newline character, which will give you the amount of characters including the newline character.
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With