
當我在 .vimrc 中將檔案限制為 tw=80 時,當我稍後回來編輯它們時,行長度最終會到處都是。例如
lets say for the sake of argument that this line hits 80 characters
there and continues on the next line as normal
編輯後...
lets say for the sake of argument (edit edit edit edit) that this
line hits 80 characters
there and continues on the next line as normal
代替
lets say for the sake of argument (edit edit edit edit) that this
line hits 80 characters there and continues on the next line as
normal
有人知道我可以做什麼來解決這個問題嗎?
答案1
您可以使用「gq
」正常模式指令重新格式化文字。它適用於視覺選擇或動作。例如,您可以使用文字物件「ap
」(可以用來代替動作),這表示「段落」(遊標所在的當前段落):
gqap
或者您可以直觀地選擇要重新格式化的段落,然後只需鍵入“ gq
”。
另一個技巧是將“a”和可選的“w”添加到“formatoptions”選項中:
:set formatoptions+=aw
這將在您鍵入時自動重新格式化段落,而無需求助於“ gq
”。
看:
:help gq
:help auto-format
:help 'formatoptions'
:help motion.txt