Add custom fold functions for json
This commit is contained in:
parent
5dda38ebeb
commit
7bfa6da603
24
after/ftplugin/json.vim
Normal file
24
after/ftplugin/json.vim
Normal file
@ -0,0 +1,24 @@
|
||||
" Set custom fold expression
|
||||
setlocal foldmethod=expr
|
||||
setlocal foldexpr=JsonFold(v:lnum)
|
||||
|
||||
" Custom fold function
|
||||
function! JsonFold(lnum)
|
||||
let l:line = getline(a:lnum)
|
||||
|
||||
if l:line =~ '{' && l:line !~ '}' && l:line !~ '".*{.*"'
|
||||
return 'a1'
|
||||
elseif l:line =~ '[' && l:line !~ ']' && l:line !~ '".*].*"'
|
||||
return 'a1'
|
||||
elseif l:line =~ '}' && l:line !~ '{' && l:line !~ '".*}.*"'
|
||||
return 's1'
|
||||
elseif l:line =~ ']' && l:line !~ '[' && l:line !~ '".*[.*"'
|
||||
return 's1'
|
||||
endif
|
||||
|
||||
return '='
|
||||
endfunction
|
||||
|
||||
" Override default group names
|
||||
hi link jsonQuote Operator
|
||||
hi link jsonKeyword Keyword
|
Loading…
x
Reference in New Issue
Block a user