有没有办法检查光标当前在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. 如何在netbeans编辑器中获取当前行号
- 2. 如何在vi/vim编辑器中获取用户名?
- 3. vi编辑器如何记住前一个文件的当前行
- 4. 获取当前行的长度
- 5. vi编辑器:读取
- 6. Java在前台打开vi编辑器
- 7. 在一行中vi编辑器
- 8. 在Vi编辑器中替换多行
- 9. 如何在ItemUpdating时获取Listitem的当前编辑器?
- 10. 如何编辑VI中的很多行
- 11. 在vi编辑器中从当前光标位置删除给定的行号
- 12. WPF如何在datagrid中获取当前编辑的内容?
- 13. 如何获取ace编辑器的当前字体大小?
- 14. 如何从屏幕上的当前编辑器获取ICopmpilationUnit - Eclipse
- 15. 如何使用组合框编辑器获取网格中的当前行
- 16. 如何获取data.table分组中的当前组的长度?
- 17. 如何在vi编辑器中删除多行特殊字符
- 18. 如何删除vi编辑器中的特定行号?
- 19. 如何在Umbraco数据编辑器中获取当前文档的ID?
- 20. 如何在插件中获取Java编辑器的当前令牌
- 21. UITextField获取当前编辑的字
- 22. 如何使用vi编辑器
- 23. 从wysihtml5编辑器中获取当前选定的文本
- 24. 温度如何。从Vi编辑器退出并返回?
- 25. vi编辑器查询
- 26. 任何VI像windows下的编辑器?
- 27. Xcode 5中的VI编辑器
- 28. gridview:如何从当前编辑行的数据库单元中获取值?
- 29. 使用JQuery获取文本区域当前行的长度
- 30. 在'VI'编辑器中对行进行排序
您好,我应该使用它开在VI和紧迫'文件后:'键? – Mistu4u
@ Mistu4u是的,这是一个'ex'命令,所以你需要一个冒号。 – DJMcMayhem