有没有办法检查光标当前在VI编辑器中的当前行的长度?我尝试在谷歌搜索,但我能找到的是如何使用“set nu”在当前打开的文件中查看行号。如何在VI编辑器中获取当前行的长度?
0
A
回答
0
您可以通过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()|.
把所有这些组合起来,你可以做
echo strwidth(getline('.'))
呼应当前行的长度。当然,你也可以通过改变参数来获得特定行的长度。
echo strwidth(getline(3)) "Length of line 3
echo strwidth(getline('$')) "Length of the last line
2
写入电流线到一个外壳命令:
:.w !wc -c
也要注意,使用wc -c
的长度包括\n
。当你不希望出现这种情况,一个。减去或使用类似
:.w !tr -d '\n'|wc -c
+0
'.w'做什么? – Mistu4u
+0
点是当前行。没有代表写入的w,当前行将被系统调用的输出替换。 –
相关问题
- 1. Java在前台打开vi编辑器
- 2. 在一行中vi编辑器
- 3. 在vi编辑器中从当前光标位置删除给定的行号
- 4. WPF如何在datagrid中获取当前编辑的内容?
- 5. 如何从屏幕上的当前编辑器获取ICopmpilationUnit - Eclipse
- 6. 如何获取ace编辑器的当前字体大小?
- 7. 如何使用组合框编辑器获取网格中的当前行
- 8. 如何在插件中获取Java编辑器的当前令牌
- 9. 如何删除vi编辑器中的特定行号?
- 10. 从wysihtml5编辑器中获取当前选定的文本
- 11. 使用JQuery获取文本区域当前行的长度
- 12. gridview:如何从当前编辑行的数据库单元中获取值?
- 13. 行编辑事件从表中获取当前值?
- 14. 在'VI'编辑器中对行进行排序
- 15. 如何在vs2008的代码编辑器中获取行号?
- 16. 在java中使用vi编辑器编辑文件
- 17. 在Eclipse中获取当前编辑文件的绝对路径
- 18. 当在WPF DataGrid中单击编辑按钮时获取当前行?
- 19. 如何在vi编辑器中输入特殊字符
- 20. 在c中获取行/列的长度#
- 21. 退出vi编辑器在unix
- 22. 如何在JavaScript中获取当前ul li的长度,当我尝试对它们进行排序?
- 23. wysiwyg contenteditable编辑器 - 如何设置富文本编辑器的最大长度
- 24. 如何获取当前元素高度?
- 25. 如何获取MYSQL中当前行之前的行的总和?
- 26. 如何替换在vi编辑器的三双引号
- 27. 如何从vi编辑器中的其他文件复制
- 28. 如何更改vi编辑器中使用的快捷键?
- 29. 剑道网格 - 获取当前编辑行
- 30. 如何在我的手机中获取当前的经纬度
您好,我应该使用它开在VI和紧迫'文件后:'键? – Mistu4u
@ Mistu4u是的,这是一个'ex'命令,所以你需要一个冒号。 – DJMcMayhem