Add list token after press Enter

Close #1, #11
dev
Andrew 2022-09-01 23:29:12 +04:00
parent a0e586adfb
commit 866ee025c7
Signed by: i
GPG Key ID: F7107F1C9D7B9981
1 changed files with 17 additions and 0 deletions

View File

@ -20,6 +20,10 @@ vnoremap <buffer> <silent> <Leader>r :call winrestview(<SID>toggleState('(', '(
nnoremap <buffer> <silent> <Leader>c :call winrestview(<SID>toggleState('[', '[ ] '))<cr>A
vnoremap <buffer> <silent> <Leader>c :call winrestview(<SID>toggleState('[', '[ ] '))<cr>
inoremap <buffer> <CR> <CR><Esc>:call <SID>auto_list()<CR>A
nnoremap <buffer> o o<Esc>:call <SID>auto_list()<CR>A
nnoremap <buffer> O O<Esc>:call <SID>auto_list()<CR>A
set tabstop=2 softtabstop=2 shiftwidth=2 expandtab
function s:toggle(dict)
@ -34,3 +38,16 @@ function s:toggleState(search, replacement)
return view
endfunction
function! s:auto_list()
let l:current_text = getline(line("."))<
let l:preceding_line = getline(line(".") - 1)
if l:preceding_line =~ '\v^\s*\d+\.'
let l:list_index = matchstr(l:preceding_line, '\v\d+')
let l:next = l:list_index + 1
let l:whitespaces = matchstr(l:preceding_line, '\v^\s*')
call setline(".", l:whitespaces.l:next.". ".l:current_text)
elseif l:preceding_line =~ '^\s*\(-\s*\|+\s*\|*\s\)\?\(\[.\]\|\(.\)\)\?'
let l:starter = matchstr(l:preceding_line, '^\s*\(-\s*\|+\s*\|*\s\)\?\(\[.\]\|(.)\)\?\s*')
call setline(".", l:starter.l:current_text)
endif
endfunction