Last active
October 8, 2018 14:38
-
-
Save veirus/096fcb7e7693902a97a851aca27c0f31 to your computer and use it in GitHub Desktop.
Quick and "smart" (not really...) insertion of current foldmarker + mostly accurate (not really...) foldlevel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function! InsertFoldMarker(...) abort | |
let l:cur_line = getline('.') | |
let l:markers = split(&l:fmr, ',') | |
let l:marker = (a:0) && len(l:markers)>1 ? l:markers[1] : l:markers[0] | |
let l:level = foldlevel('.') | |
let l:level = l:level == 0 ? '1' : l:level | |
let l:cms = split(&l:cms, '%s') | |
" TODO: handle paired comment markers | |
let l:cms = (a:0) && len(l:cms)>1 ? l:cms[1] : l:cms[0] | |
let l:marker_cnt = count(l:cur_line, l:cms) | |
let l:cms = l:marker_cnt % 2 == 0 ? l:cms.' ' : '' | |
let l:space = l:cur_line[-1:] =~ '\s' || len(l:cur_line) < 2 ? '' : ' ' | |
exe "norm! m1A".l:space.l:cms.l:marker.l:level."\<Esc>`1" | |
return '' | |
endfunction | |
nnoremap <leader><Tab> :call InsertFoldMarker()<CR> | |
nnoremap <leader>1<Tab> :call InsertFoldMarker(1)<CR> | |
inoremap <localleader><Tab> <C-r>=InsertFoldMarker()<CR> | |
inoremap <localleader>1<Tab> <C-r>=InsertFoldMarker(1)<CR> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment