2009-06-12 25 views
102

我想使用Vim的soft wrap功能(:set wrap)在80個字符處包裝一些代碼,無論我的實際窗口寬度如何。Vim中80個字符的軟包裝在任意寬度的窗口中

我一直沒能找到一種方法來做到這一點,但 - 所有軟包裝紙似乎綁在窗口的寬度

  • textwidthwrapmargin都是硬包裝(它們插入換行符)
  • 縱向分割爲多個窗口並使用:vertical resize 80(可能與:set breakat=允許在任何字符上打斷)其中一種作品(儘管有點冒險),但在使用:set number作爲行時會中斷數字佔用可變數量的列(取決於文件長度)和這些都是80的一部分。

有沒有什麼辦法可以在vim中做到這一點? It doesn't look promising, according to other sources

現在我的近似值只是讓/^.\{80}\zs.\+作爲我的默認搜索,所以它至少突出顯示。我想爲它增加一個:syntax項目,但是當它與其他語法項目重疊時就會崩潰,所以我放棄了這個想法。

+0

其實,你是如何設置默認搜索? – thethinman 2010-01-27 00:39:30

+2

您是否找到答案?我也有同樣的問題。 – 2010-04-12 19:37:44

+1

你找到答案了嗎?下面選擇了什麼工作? – Angela 2010-12-28 03:12:14

回答

32

您可以通過:set numberwidth=6爲行數列設置較大的最小寬度,然後您可以將:set columns=86或其他方式調整爲適當的大小。如果你編輯一個有100萬行的文件,你可能會遇到麻煩,但這不太可能。你也是這樣浪費6列屏幕房地產。所以仍然存在各種問題。

您可以使用:match來突出顯示過去的第80列,例如herehere

除此之外,我看不到任何方式來做到這一點。似乎它會是一個不錯的功能。

1

你試過'linebreak'

 *'linebreak'* *'lbr'* *'nolinebreak'* *'nolbr'* 
    'linebreak' 'lbr' boolean (default off) 
     local to window 
     {not in Vi} 
     {not available when compiled without the |+linebreak| 
     feature} 
If on Vim will wrap long lines at a character in 'breakat' rather 
than at the last character that fits on the screen. Unlike 
'wrapmargin' and 'textwidth', this does not insert <EOL>s in the file, 
it only affects the way the file is displayed, not its contents. The 
value of 'showbreak' is used to put in front of wrapped lines. 
This option is not used when the 'wrap' option is off or 'list' is on. 
Note that <Tab> characters after an <EOL> are mostly not displayed 
with the right amount of white space. 
10

試試這個:

set columns=80 
autocmd VimResized * if (&columns > 80) | set columns=80 | endif 
set wrap 
set linebreak 
set showbreak=+++ 

可以刪除if (&columns > 80) |如果總是需要80列。

相關問題