2012-04-02 70 views
2

我有一個文本文件:如何包裝上欄#文本2

Function  Description 

concat   Returns the concatenation of the arguments. 

contains  Returns true if the first argument string contains the second argument string; otherwise returns false. 

我想換就列#2的文字,結果應該是:

Function  Description 

concat   Returns the concatenation 
       of the arguments. 

contains  Returns true if the first 
       argument string contains 
       the second argument 
       string; otherwise returns 
       false. 

如何在vimshell快速嗎?謝謝你的任何建議。

回答

3

這個問題可以通過使用indentexpr選項在Vim中輕鬆解決。設置 它指定爲第一列的字符數,

:set inde=16 

然後格式化文本像往常一樣與gqgw家庭命令。

+1

我知道必須有比我更好的方法! – weronika 2012-04-02 09:00:19

0
:set tw=80 #or :set textwidth=80 

會自動換行80個字符。

然後你可以在命令模式下鍵入:

gg #go to the top 

然後

gqG #apply reformat to the end 

參考: http://www.cs.swarthmore.edu/help/vim/reformatting.html

+1

我不認爲'gq'在這種情況下會達到OP的目標。 – Kent 2012-04-02 08:30:46

+1

據我所知,這使得第二列的行不會被縮進,不像第二列那樣排列在第二列...... – weronika 2012-04-02 08:32:18

1

我不認爲這有資格作爲 「快」,我希望有人有更好的答案,但這是最好的,我可以在VIM中提出:

1)設置文本寬度,以你的第二列的所需寬度:

:set tw=60 

2)嘜頭列一些特別的東西(也就是說稍後刪除 - 任何非正常的文本會做什麼,我使用(使用g!/^$/忽略空行)這裏JJJ):

:%g!/^$/s/^/jjj/ 

3)將在單獨的行第二列文本:

:%s/ \</ \r/ 

4)所有重新包裹第二列線至所需寬度:

:%g!/^jjj/normal gqq 

5)加入,其第一列字每個第二柱段的第一行(應該保留這是一階後的空間在開頭列字):

:%g/^jjj/join 

6)縮進所有剩餘的第二列線的適當量排隊起來(使用,但是許多需要>>秒 - 有可能是一種方法,使VIM檢查最後一列行的長度並插入該空格數而不是使用此方法):

:%g!/^jjj/normal >>>>>>>> 

7)最後從第一列中刪除第一列標記:

:%s/^jjj// 

不值得爲你的榜樣,但如果該文件的足夠大,它比手工做的更好.. 。