48232b5e3d
REMOVE g:AutoPairsShortcuts ADD g:AutoPairsShortcutJump
3.7 KiB
3.7 KiB
Auto Pairs
Insert or delete brackets, parens, quotes in pair.
Installation
copy plugin/auto-pairs.vim to ~/.vim/plugin
Features
-
Insert in pair
input: [ output: [|]
-
Delete in pair
input: foo[<BS> output: foo
-
Insert new indented line after Return
input: {|} (press <CR> at |) output: { | }
-
Insert spaces before closing characters, only for [], (), {}
input: {|} (press <SPACE> at |) output: { | } input: {|} (press <SPACE>foo} at |) output: { foo }| input: '|' (press <SPACE> at |) output: ' |'
-
Skip ' when inside a word
input: foo| (press ' at |) output: foo'
-
Skip closed bracket.
input: [] output: []
-
Ignore auto pair when previous character is \
input: "\' output: "\'"
-
Fast Wrap
input: |'hello' (press (<M-e> at|) output: ('hello')
-
Quick jump to closed pair.
input: { something;| } (press } at |) output: { }|
-
Support ``` ''' and """
input: ''' output: '''
Shortcuts
System Shortcuts:
<CR> : Insert new indented line after return if cursor in blank brackets or quotes.
<BS> : Delete brackets in pair
<M-p> : Toggle Autopairs (g:AutoPairsShortcutToggle)
<M-e> : Fast Wrap (g:AutoPairsShortcutFastWrap)
<M-n> : Jump to next closed pair (g:AutoPairsShortcutJump)
If <M-p> <M-e> or <M-n> conflict with another keys or want to bind to another keys, add
let g:AutoPairscutToggle = '<another key>'
to .vimrc, it the key is empty string '', then the shortcut will be disabled.
Options
-
g:AutoPairs
Default: {'(':')', '[':']', '{':'}',"'":"'",'"':'"', '`':'`'}
-
g:AutoPairsShortcutToggle
Default: '<M-p>' The shortcut to toggle autopairs.
-
g:AutoPairsShortcutFastWrap
Default: '<M-e>' Fast wrap the word. all pairs will be consider as a block (include <>). (|)'hello' after fast wrap at |, the word will be ('hello') (|)<hello> after fast wrap at |, the word will be (<hello>)
-
g:AutoPairsShortcutJump
Default: '<M-n>' Jump to the next closed pair
-
g:AutoPairsMapBS
Default : 1 Map <BS> to delete brackets, quotes in pair execute 'inoremap <buffer> <silent> <BS> <C-R>=AutoPairsDelete()<CR>'
-
g:AutoPairsMapCR
Default : 1 Map <CR> to insert a new indented line if cursor in (|), {|} [|], '|', "|" execute 'inoremap <buffer> <silent> <CR> <C-R>=AutoPairsReturn()<CR>'
-
g:AutoPairsCenterLine
Default : 1 When g:AutoPairsMapCR is on, center current line after return if the line is at the bottom 1/3 of the window.
-
g:AutoPairsMapSpace
Default : 1 Map <space> to insert a space after the opening character and before the closing one. execute 'inoremap <buffer> <silent> <CR> <C-R>=AutoPairsSpace()<CR>'
TroubleShooting
The script will remap keys ([{'"}]) <BS>,
If auto pairs cannot work, use :imap ( to check if the map is corrected.
The correct map should be <C-R>=AutoPairsInsert("\(")<CR>
Or the plugin conflict with some other plugins.
use command :call AutoPairsInit() to remap the keys.
-
How to insert parens purely
There are 3 ways
-
use Ctrl-V ) to insert paren without trigger the plugin.
-
use Alt-P to turn off the plugin.
-
use DEL or x to delete the character insert by plugin.
-