Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Clone in Desktop Download ZIP
Automatically insert pairs (brackets, quotes) where they are supposed to be
Python VimL
Branch: master
Failed to load latest commit information.
plugin intial commit
pythonx intial commit
.gitignore intial commit
README.md README.md: fix imap call

README.md

Plugin will automatically add enclosing ) or } (or any other) at appropriate place to be.

gif

Currently, two cases are supported:

  • adding pair after call-like construction:

    |something()        type: test( ->
    test(|something())
    
  • adding pair after string:

    |"blah"       type: test( ->
    test("blah")
    

Undo will remove added pair and leaving cursor in-place:

|(blah)        type: test(  ->
test(|(blah))  type: <Esc>u ->
test(|(blah)

Installation & Usage

Plugin provides only one function, named AutoSurround(pair). pair is character, which will be inserted at position, determined by internal algorithms, described above, or user-registered functions.

Plug 'vim-autosurround'
    inoremap  ( (<C-O>:call AutoSurround(")")<CR>

In case of using matchem or similar surrounding plugins things are going to be little bit harder:

augroup run_after_plug_end
    au!

call plug#begin('~/.vim/bundle')

" ...

Plug 'vim-autosurround'
    au User _OverwriteMatchemMappings
        \ autocmd VimEnter,BufEnter,FileType *
            \ inoremap <buffer> ( (<C-R>=AutoSurround(")")?'':g:MatchemMatchStart()<CR>

    au User _VimrcRunAfterPlugEnd doautocmd User _OverwriteMatchemMappings

    doautocmd User _OverwriteMatchemMappings

" ...

augroup end

call plug#end()

au VimEnter * doautocmd User _VimrcRunAfterPlugEnd
au VimEnter * au! run_after_plug_end

Extension

Plugin provides API, which can be used to extend surround logic:

  • index = autosurround.register_finder(callback), callback is a function of one argument cursor, which is vim.current.window.cursor; callback should return tuple (line, column) with position, which will be used for inserting pair character or None, if callback is not able to find position.

    index can be used for unregister_finder(index)

  • autosurround.unregister_finder(index) will remove previously added callback.

Something went wrong with that request. Please try again.