Add list token after press Enter #1

Closed
opened 2022-05-14 00:02:51 +03:00 by i · 2 comments

When adding a new line, the list token in the new line is expected.

Available tokens: -, +, *

Token must be the same as in previous line.

Same behavior for checkboxes and radio buttons.

When adding a new line, the list token in the new line is expected. Available tokens: `-`, `+`, `*` Token must be the same as in previous line. Same behavior for checkboxes and radio buttons.
i added this to the v0.2.0 milestone 2022-05-14 00:02:51 +03:00
i added the
feature:request
label 2022-05-14 00:02:51 +03:00
i self-assigned this 2022-05-14 00:58:25 +03:00
Poster
Owner
see https://gist.github.com/sedm0784/dffda43bcfb4728f8e90
Poster
Owner

possible solution

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

function! s:auto_list()
  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. ". ")
  elseif l:preceding_line =~ '^\s*\(-\s*\|+\s*\|*\s\)\?\(\[.\]\|\(.\)\)\?'
    let l:starter = matchstr(l:preceding_line, '^\s*\(-\s*\|+\s*\|*\s\)\?\(\[.\]\|(.)\)\?\s*')
    call setline(".", l:starter)
  endif
endfunction
possible solution ``` 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 function! s:auto_list() 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. ". ") elseif l:preceding_line =~ '^\s*\(-\s*\|+\s*\|*\s\)\?\(\[.\]\|\(.\)\)\?' let l:starter = matchstr(l:preceding_line, '^\s*\(-\s*\|+\s*\|*\s\)\?\(\[.\]\|(.)\)\?\s*') call setline(".", l:starter) endif endfunction ```
i referenced this issue from a commit 2022-09-01 22:30:19 +03:00
i closed this issue 2022-09-01 22:30:19 +03:00
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: i/vim-md#1
There is no content yet.