简体   繁体   English

如何使用 vi 或 vim 获取字符数

[英]How to get character count using vi or vim

How do you get character location count from a text file using vi?如何使用 vi 从文本文件中获取字符位置计数?

I tried ":goto number" and it does not work in Linux.我试过 ":goto number",但它在 Linux 中不起作用。

To clarify my question, if I have a file with say 3 lines:为了澄清我的问题,如果我有一个包含 3 行的文件:

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'.我想说在位置 30 给我找一封信,它会跳到第 2 行,突出显示来自单词“today”的字母“t”。 This is similar to concept of :goto 30 in macos vi but for Linux这类似于 macos vi 中的:goto 30概念,但适用于 Linux

Use g CTRL-G使用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的位置

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) Byte 1 of 571指的是是(字节1)在文件中的字节数,或“字符”与字符(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.此外,我希望您能想到“字符”并使用“字节”一词——这将使您未来在 Google 上搜索有关vim更加富有成效。

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}用 v 可视化一个段落}
  2. visualize whole file with ggVG使用 ggVG 可视化整个文件

then type然后输入

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

I needed this to count my twitter posts (280 character limit)我需要这个来计算我的推特帖子(280 个字符限制)

I found the solution to my problem.我找到了解决我的问题的方法。 It looks like I had 'vi' and 'vim' installed on my system.看起来我的系统上安装了“vi”和“vim”。 By default, I was using 'vi' to edit the file and :goto 30 did not work.默认情况下,我使用 'vi' 来编辑文件并且:goto 30不起作用。 After a bit of digging around I found that 'vi' was part of the vim-minimal package.经过一番挖掘,我发现 'vi' 是vim-minimal包的一部分。 And 'vim' was part of the vim-enhanced package. 'vim' 是vim-enhanced包的一部分。 When I tried 'vim' instead of 'vi' the :goto 30 worked!当我尝试使用 'vim' 而不是 'vi' 时, :goto 30起作用了! So it looks like it is definitely package related.所以看起来它肯定是包相关的。 Thanks Zak, pointing in the right direction and to all for the help.感谢 Zak,指出正确的方向并感谢所有人的帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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