From 866ee025c73c4c779f18747775b5c8c83b90a956 Mon Sep 17 00:00:00 2001 From: Andrew Date: Thu, 1 Sep 2022 23:29:12 +0400 Subject: [PATCH] Add list token after press Enter Close #1, #11 --- ftplugin/markdown.vim | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/ftplugin/markdown.vim b/ftplugin/markdown.vim index c93ad9d..fda3413 100644 --- a/ftplugin/markdown.vim +++ b/ftplugin/markdown.vim @@ -20,6 +20,10 @@ vnoremap r :call winrestview(toggleState('(', '( nnoremap c :call winrestview(toggleState('[', '[ ] '))A vnoremap c :call winrestview(toggleState('[', '[ ] ')) +inoremap :call auto_list()A +nnoremap o o:call auto_list()A +nnoremap O O:call auto_list()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