Raimondi / delimitMate

Vim plugin, provides insert mode auto-completion for quotes, parens, brackets, etc.
http://www.vim.org/scripts/script.php?script_id=2754
1.98k stars 117 forks source link

jump to the end of a paragraph #163

Closed ghost closed 10 years ago

ghost commented 10 years ago

| = current cursor postion _ = expected position after jumping

//ex.
var test = [
  1, 2, 3 |(jump)
]_

//ex.
var test = function() {
  /* body */
  ....|(jump)
  ....
}_

Vim's '}' key is jump to blank line after paragraph. So, to insert ';' above '_' positon, must put 'esc', '}', 'k', 'A', ';' . Or arrow keys and ';'.

I wrote tricky function 'ExitParagraph' and map it to (I overrided delimitMate's to to jump closing pair)

How about extending 'jumpany' to exit paragraph? ex. 'multilineJumpAny'? It's very convenient to write codes.

my .vimrc : ....

Bundle 'Valloric/YouCompleteMe'
    let g:ycm_autoclose_preview_window_after_completion = 1
    let g:ycm_key_list_select_completion = ['<C-n>', '<Down>']
    let g:ycm_key_list_previous_completion = ['<C-p>', '<Up>']

Bundle 'SirVer/ultisnips'
    let g:UltiSnipsExpandTrigger='<c-j>'
    let g:UltiSnipsJumpForwardTrigger='<c-j>'
    let g:UltiSnipsJumpBackwardTrigger='<c-k>'

Bundle 'Raimondi/delimitMate'
    let g:delimitMate_expand_cr = 1

    " map <CR> expand from complete pop list or expand pairs.
    " map <Tab> navigate downward complete pop list, or jump to exit closing pair.
    " map <S-Tab> navigate upward complete pop list, or jump to exit paragraph.

    imap <expr> <CR> pumvisible() ? "\<c-j>\<c-o>i" : "\<Plug>delimitMateCR"
    imap <expr> <Tab> pumvisible()? "\<c-n>" : (delimitMate#ShouldJump() ? "\<Right>" : "\<Tab>")
    imap <expr> <S-Tab> pumvisible() ? "\<c-p>" :  '<c-o>:call ExitParagraph()<cr>'

    function! ExitParagraph()
        execute "norm! j"
        let blank = search('^\s*$', 'W')
        if blank <= 0
            execute "norm! }"
            :startinsert!
        else
            execute "norm! h"
            :startinsert!
        endif
    endfunction

...

ghost commented 10 years ago

Maybe, I found solution for me.

imap <silent> <expr> <S-Tab> pumvisible() ? "\<c-p>" : "<C-r>=<SID>exitBlock()<CR>"
  function! s:exitBlock()
    let [l, m] = (searchpos('[)}\]]', 'cn'))
    let po = cursor(l,m+1)
    return ""
 endfunction