2013-03-12 41 views
2

我有一些文本文件包含數據(如cvs)和格式化選項卡,但列不具有相同的大小。Vim:不同列的不同tabstop

Vim的默認格式爲:

int1 longvalue1  string1 
int2 anotherlongvalue2  string2 

能vim用diffent製表位的不同列?顯示屏將爲

int1 longvalue1   string1 
int2 anotherlongvalue2 string2 
+0

的[對齊](HTTPS取代我的所有選項卡。 com/vim-scripts/Align)插件非常適合這一點。 – 2013-03-12 08:35:25

回答

4

此功能(由編輯器自動完成時)通常稱爲Elastic tabstop。這樣的補丁已經被包含在Vim中了(例如見here),但是它們遠未包含在Vim中(並且幾乎沒有進展)。

至於解決方法,您可以:set ts到一個較大的值(造成巨大的差距,雖然),或使用像Align - Help folks to align text, eqns, declarations, tables, etcTabular - Vim script for text filtering and alignment一個插件選項卡轉換爲空白的appropritate量(也許暫時;轉換回:write) 。

1

謝謝Ingo,插件Align是我所需要的。我想替換<tab>符號,並且插件不替換這些邊界(典型的boudary是=,不應該被替換)。

所以我創建了一個函數來替換它們:// github上:

" :DoAlign command to format the text as an array by replacing the <tabs>. 
" Requires the Align-plugin 
fun! DoAlignFunction() 
%s#\t#==motiv==#g 
%Align 
%s#==motiv==##g 
endfunction 

command! DoAlign call DoAlignFunction() 

所以我可以(不選擇任何文字)與:DoAlign