有沒有辦法檢查光標當前在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