本文尝试解决的问题是:在使用gvim时,能够按照*的个数来缩进文本信息
定制一个filetype
- 在 C:\Vim\vim74\syntax 创建一个文件 starFold.vim;内容如下:
set fdc=2
set lsp=5
syn match head "^*.\+" "星号计算标题层级
hi head guifg=green gui=bold
set fdm=expr
set foldexpr=Myindent(v:lnum)
func! Myindent(lnum)
let s:a=strlen(matchstr(getline(v:lnum),'^\*\+'))
if s:a == 2
return '>2'
elseif s:a == 1
return '>1'
else
return '='
endif
endf
配置filetype
在 C:\Vim\vim74 目录的 filetype.vim 文件中添加
au BufNewFile,BufRead *.diary setf starFold
使用
- 重启gvim
- 创建名为test.diary的文件:
- 折叠后效果:
参考:
http://vim.wikia.com/wiki/Customize_text_for_closed_folds