如何在VI编辑器中获取当前行长度?

时间:2017-10-18 15:49:15

标签: vi aix

有没有办法检查光标当前在VI编辑器中的当前行的长度?我尝试在谷歌搜索,但我能找到的是如何使用“set nu”查看当前打开的文件中的行号。

3 个答案:

答案 0 :(得分:3)

将当前行写入shell命令:

:.w !wc -c

另请注意,wc -c的长度包含\n。当你不想要那个时,减去一个或使用像

这样的东西
:.w !tr -d '\n'|wc -c

答案 1 :(得分:0)

您可以使用true<Grid.Triggers> <DataTrigger Binding="{Binding IsAdmin}" TargetType="{x:Type Grid}" Value="True"> <Setter Property="IsVisible"> <Setter.Value> <x:Arguments> <x:Boolean>True</x:Boolean> </x:Arguments> </Setter.Value> </Setter> </DataTrigger> </Grid.Triggers> 获取当前行的长度。来自strwidth

getline

:h getline

                            *getline()*
getline({lnum} [, {end}])
        Without {end} the result is a String, which is line {lnum}
        from the current buffer.  Example: >
            getline(1)
<       When {lnum} is a String that doesn't start with a
        digit, line() is called to translate the String into a Number.
        To get the line under the cursor: >
            getline(".")
<       When {lnum} is smaller than 1 or bigger than the number of
        lines in the buffer, an empty string is returned.

把这些放在一起,你可以做到

:h strwidth

回显当前行的长度。当然,您也可以通过更改参数来获取特定行的长度。

strwidth({expr})                    *strwidth()*
        The result is a Number, which is the number of display cells
        String {expr} occupies.  A Tab character is counted as one
        cell, alternatively use |strdisplaywidth()|.
        When {expr} contains characters with East Asian Width Class
        Ambiguous, this function's return value depends on 'ambiwidth'.
        Also see |strlen()|, |strdisplaywidth()| and |strchars()|.

答案 2 :(得分:0)

使用$将光标移至行尾,然后使用<ctrl>g显示行和列信息(以及文件名和编辑状态),如下所示:

"big.csv" [Modified] line 400 of 866 --46%-- col 504

再往前走一步,如果使用vim,则可以通过使用:se ruler打开标尺,使行和列信息始终显示在右下角。然后,只要光标移动,您就会看到类似以下内容的更新:

400,504 46%

只要启动:se ruler,就可以将.vimrc添加到vim中,以使此设置为默认设置。