LINUX.ORG.RU

История изменений

Исправление habamax, (текущая версия) :

Хороший вариант, кстати, спасибо.

Ну раз пошла такая пьянка…

" Template <+placeholders+> navigation
func! s:placeholder_next(dir = 1) abort
    if search('<+.\{-}+>', a:dir ? "" : "b")
        exe "normal! va<o\<C-g>"
    endif
endfunc

func! s:placeholder_accept() abort
    if search('<+.\{-}+>', "c")
        exe 'normal! 2"_x'
        call search('+>', "c")
        exe 'normal! 2"_x'
        call s:placeholder_next()
    endif
endfunc

nnoremap <silent> <C-j> :<C-u>call <SID>placeholder_next()<CR>
inoremap <silent> <C-j> <C-\><C-o>:call <SID>placeholder_next()<CR>
snoremap <silent> <C-j> <ESC>:call <SID>placeholder_next()<CR>
nnoremap <silent> <C-k> :<C-u>call <SID>placeholder_next(0)<CR>
inoremap <silent> <C-k> <C-\><C-o>:call <SID>placeholder_next(0)<CR>
snoremap <silent> <C-k> <ESC>:call <SID>placeholder_next(0)<CR>
snoremap <silent> <CR> <ESC>:call <SID>placeholder_accept()<CR>



" <+placeholder+> highlight
augroup placeholder | au!
    au BufNew,BufRead * call matchadd('Error', '<+.\{-}+>')
augroup END

https://i.imgur.com/8qKvem9.gif

Исходная версия habamax, :

Хороший вариант, кстати, спасибо.

Ну раз пошла такая пьянка…

" Template <+placeholders+> navigation
func! s:placeholder_next(dir = 1) abort
    if search('<+.\{-}+>', a:dir ? "" : "b")
        exe "normal! va<o\<C-g>"
    endif
endfunc

func! s:placeholder_accept() abort
    if search('<+.\{-}+>', "c")
        exe 'normal! 2"_x'
        call search('+>', "c")
        exe 'normal! 2"_x'
        call s:placeholder_next()
    endif
endfunc

nnoremap <silent> <C-j> :<C-u>call <SID>placeholder_next()<CR>
inoremap <silent> <C-j> <C-o>:call <SID>placeholder_next()<CR>
snoremap <silent> <C-j> <ESC>:call <SID>placeholder_next()<CR>
nnoremap <silent> <C-k> :<C-u>call <SID>placeholder_next(0)<CR>
inoremap <silent> <C-k> <C-o>:call <SID>placeholder_next(0)<CR>
snoremap <silent> <C-k> <ESC>:call <SID>placeholder_next(0)<CR>
snoremap <silent> <CR> <ESC>:call <SID>placeholder_accept()<CR>


" <+placeholder+> highlight
augroup placeholder | au!
    au BufNew,BufRead * call matchadd('Error', '<+.\{-}+>')
augroup END

https://i.imgur.com/8qKvem9.gif