我有時希望Vim讀取製表符格式化的文件,其中最合理的格式意味着不均勻的製表符寬度。換句話說,我想在位置的製表位:在Vim中配置可變寬度的製表符間隔
5,30,50,60,70,80
我怎樣才能做到這一點的Vim的?
我有時希望Vim讀取製表符格式化的文件,其中最合理的格式意味着不均勻的製表符寬度。換句話說,我想在位置的製表位:在Vim中配置可變寬度的製表符間隔
5,30,50,60,70,80
我怎樣才能做到這一點的Vim的?
目前沒有。沒有任何官方版本。然而,如果你願意投入一點努力在你身邊,我記得有一個類似的補丁。查看vim的補丁頁面。
這個補丁? https://groups.google.com/forum/#!topic/vim_dev/eNOQO06iRZQ – 2015-01-11 03:10:48
如果你實際上並不需要改變tabstops,只需插入正確數量的空格即可離開,我建議你編寫腳本。這裏有一個快速和骯髒的版本,可以做你想做的:
let s:tabstops = [0, 5, 30, 50, 60, 70, 80]
fun! Find_next(pos)
if a:pos > min(s:tabstops) && a:pos < max(s:tabstops)
let my_count = 0
while my_count < len(s:tabstops) - 1
if a:pos > get(s:tabstops, my_count) && a:pos < get(s:tabstops, my_count+1)
return get(s:tabstops, my_count+1)
endif
let my_count = my_count + 1
endwhile
return -1
endif
return -1
endfun
fun! Tabbing()
let pos = col('.')
let next_stop = Find_next(pos)
let the_command = "normal i"
let my_count = 0
while my_count < next_stop - pos
let the_command = the_command . " "
let my_count = my_count + 1
endwhile
let the_command = the_command . ""
execute the_command
endfun
imap <TAB> j<ESC>:call Tabbing()<CR>lxi
這是一個很棒的功能,雖然這不會重新格式化一個現有的文件,這是我需要的,但協助格式化我自己的文件飛。 – Magnus 2009-09-09 12:57:42
有一個功能稱爲變量tabstops已被踢了很長一段時間vim。它在過去幾天剛剛重新融入了主分支。我已經測試了一下 - 必須修補它以避免一些算術錯誤,但現在看起來非常穩定。你很快就會很幸運。 – Cascabel 2009-10-29 19:53:20