auto-pairs/README.md

328 lines
8.9 KiB
Markdown
Raw Normal View History

2011-05-22 13:11:23 -04:00
Auto Pairs
==========
Insert or delete brackets, parens, quotes in pair.
Installation
------------
copy plugin/auto-pairs.vim to ~/.vim/plugin
or if you are using `pathogen`:
```git clone git://github.com/jiangmiao/auto-pairs.git ~/.vim/bundle/auto-pairs```
2011-05-22 13:11:23 -04:00
Features
--------
2011-06-09 14:32:17 -04:00
* Insert in pair
2012-05-13 21:54:25 -04:00
2011-06-09 14:32:17 -04:00
input: [
output: [|]
2011-05-22 13:11:23 -04:00
2011-06-09 14:32:17 -04:00
* Delete in pair
2012-05-13 21:54:25 -04:00
2011-06-09 14:32:17 -04:00
input: foo[<BS>
output: foo
2011-05-22 13:11:23 -04:00
2011-06-09 14:32:17 -04:00
* Insert new indented line after Return
2011-05-22 13:11:23 -04:00
2011-06-09 14:32:17 -04:00
input: {|} (press <CR> at |)
output: {
|
}
2011-05-22 13:11:23 -04:00
* Insert spaces before closing characters, only for [], (), {}
input: {|} (press <SPACE> at |)
output: { | }
input: {|} (press <SPACE>foo} at |)
output: { foo }|
input: '|' (press <SPACE> at |)
output: ' |'
2011-12-29 08:42:43 -05:00
* Skip ' when inside a word
input: foo| (press ' at |)
output: foo'
2011-06-09 14:32:17 -04:00
* Skip closed bracket.
2011-05-22 13:11:23 -04:00
2011-06-09 14:32:17 -04:00
input: []
output: []
2011-05-22 13:11:23 -04:00
2011-06-09 14:32:17 -04:00
* Ignore auto pair when previous character is \
2011-05-22 13:11:23 -04:00
2011-06-09 14:32:17 -04:00
input: "\'
output: "\'"
* Fast Wrap
input: |'hello' (press (<M-e> at |)
2011-06-09 14:32:17 -04:00
output: ('hello')
2011-06-09 14:23:47 -04:00
2012-07-15 10:50:09 -04:00
wrap string, only support c style string
input: |'h\\el\'lo' (press (<M-e> at |)
output ('h\\ello\'')
2012-07-15 10:50:09 -04:00
input: |[foo, bar()] (press (<M-e> at |)
output: ([foo, bar()])
2011-12-21 23:30:04 -05:00
* Quick jump to closed pair.
2012-05-13 21:54:25 -04:00
input:
2011-12-21 23:30:04 -05:00
{
something;|
}
(press } at |)
output:
{
}|
2012-01-17 00:17:21 -05:00
* Support ``` ''' and """
input:
'''
output:
2013-02-16 01:02:13 -05:00
'''|'''
* Delete Repeated Pairs in one time
input: """|""" (press <BS> at |)
output: |
input: {{|}} (press <BS> at |)
output: |
input: [[[[[[|]]]]]] (press <BS> at |)
output: |
2012-01-17 00:17:21 -05:00
2012-05-13 21:54:25 -04:00
* Fly Mode
2012-05-14 02:23:08 -04:00
input: if(a[3)
output: if(a[3])| (In Fly Mode)
output: if(a[3)]) (Without Fly Mode)
2012-05-13 21:54:25 -04:00
2012-05-14 02:23:08 -04:00
input:
{
hello();|
world();
}
2012-05-13 21:54:25 -04:00
2012-05-14 02:23:08 -04:00
(press } at |)
2012-05-13 21:54:25 -04:00
2012-05-14 02:23:08 -04:00
output:
{
hello();
world();
}|
2012-05-13 21:54:25 -04:00
2012-05-14 02:23:08 -04:00
(then press <M-b> at | to do backinsert)
output:
{
hello();}|
world();
}
2012-05-13 21:54:25 -04:00
2012-05-14 02:23:08 -04:00
See Fly Mode section for details
2012-05-13 21:54:25 -04:00
Fly Mode
--------
2012-05-16 12:16:58 -04:00
Fly Mode will always force closed-pair jumping instead of inserting. only for ")", "}", "]"
2012-05-13 21:54:25 -04:00
2013-03-05 00:28:18 -05:00
If jumps in mistake, could use AutoPairsBackInsert(Default Key: `<M-b>`) to jump back and insert closed pair.
2012-05-13 21:54:25 -04:00
2012-05-16 12:16:58 -04:00
the most situation maybe want to insert single closed pair in the string, eg ")"
2012-05-13 21:54:25 -04:00
2012-05-16 12:16:58 -04:00
Fly Mode is DISABLED by default.
add **let g:AutoPairsFlyMode = 1** .vimrc to turn it on
Default Options:
let g:AutoPairsFlyMode = 0
let g:AutoPairsShortcutBackInsert = '<M-b>'
2012-05-13 21:54:25 -04:00
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)
2013-03-05 00:28:18 -05:00
<M-b> : BackInsert (g:AutoPairsShortcutBackInsert)
If <M-p> <M-e> or <M-n> conflict with another keys or want to bind to another keys, add
2012-05-13 21:54:25 -04:00
let g:AutoPairShortcutToggle = '<another key>'
2013-03-05 00:28:18 -05:00
to .vimrc, if the key is empty string '', then the shortcut will be disabled.
2011-05-22 13:11:23 -04:00
Options
-------
* g:AutoPairs
2012-01-17 00:17:21 -05:00
Default: {'(':')', '[':']', '{':'}',"'":"'",'"':'"', '`':'`'}
* b:AutoPairs
Default: g:AutoPairs
Buffer level pairs set.
* g:AutoPairsShortcutToggle
Default: '<M-p>'
The shortcut to toggle autopairs.
2011-05-22 13:11:23 -04:00
2011-06-09 14:23:47 -04:00
* g:AutoPairsShortcutFastWrap
2012-05-13 21:54:25 -04:00
2011-06-09 14:23:47 -04:00
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>'
2011-05-22 13:11:23 -04:00
Jump to the next closed pair
2011-05-22 13:11:23 -04:00
* 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>'
2012-05-14 02:23:08 -04:00
* g:AutoPairsFlyMode
2012-05-13 21:54:25 -04:00
2012-05-16 12:16:58 -04:00
Default : 0
2012-05-13 21:54:25 -04:00
2012-05-16 12:16:58 -04:00
set it to 1 to enable FlyMode.
2012-05-14 02:23:08 -04:00
see FlyMode section for details.
2012-05-13 21:54:25 -04:00
2012-05-14 02:23:08 -04:00
* g:AutoPairsShortcutBackInsert
2012-05-13 21:54:25 -04:00
2012-05-14 02:23:08 -04:00
Default : <M-b>
2012-05-13 21:54:25 -04:00
2012-05-14 02:23:08 -04:00
Work with FlyMode, insert the key at the Fly Mode jumped postion
2012-05-13 21:54:25 -04:00
Buffer Level Pairs Setting
--------------------------
Set b:AutoPairs before BufEnter
eg:
" When the filetype is FILETYPE then make AutoPairs only match for parenthesis
au Filetype FILETYPE let b:AutoPairs = {"(": ")"}
2011-05-22 13:11:23 -04:00
TroubleShooting
---------------
2012-05-13 21:54:25 -04:00
The script will remap keys ([{'"}]) <BS>,
2011-05-22 13:11:23 -04:00
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
2011-12-21 23:30:04 -05:00
1. use Ctrl-V ) to insert paren without trigger the plugin.
2. use Alt-P to turn off the plugin.
3. use DEL or <C-O>x to delete the character insert by plugin.
2011-12-29 08:42:43 -05:00
2012-07-15 10:50:09 -04:00
Known Issues
-----------------------
There are the issues I cannot fix.
Compatible with Vimwiki - [issue #19](https://github.com/jiangmiao/auto-pairs/issues/19)
Description: When works with vimwiki `<CR>` will output `<SNR>xx_CR()`
Reason: vimwiki uses `<expr>` on mapping `<CR>` that auto-pairs cannot expanding.
2012-10-29 02:50:45 -04:00
Solution A: Add
2013-02-16 01:02:13 -05:00
2012-10-29 02:50:45 -04:00
" Copy from vimwiki.vim s:CR function for CR remapping
function! VimwikiCR()
let res = vimwiki#lst#kbd_cr()
if res == "\<CR>" && g:vimwiki_table_mappings
let res = vimwiki#tbl#kbd_cr()
endif
return res
endfunction
autocmd filetype vimwiki inoremap <buffer> <silent> <CR> <C-R>=VimwikiCR()<CR><C-R>=AutoPairsReturn()<CR>
2013-02-16 01:02:13 -05:00
2012-10-29 02:50:45 -04:00
to .vimrc, it will make vimwiki and auto-pairs 'Return' feature works together.
2012-07-15 10:50:09 -04:00
2012-10-29 02:50:45 -04:00
Solution B: add `let g:AutoPairsMapCR = 0` to .vimrc to disable `<CR>` mapping.
2013-02-16 01:02:13 -05:00
2012-10-24 12:59:21 -04:00
Compatible with viki - [issue #25](https://github.com/jiangmiao/auto-pairs/issues/25)
2013-02-16 01:02:13 -05:00
2012-10-24 12:59:21 -04:00
Description: When works with viki `<CR>` will output viki#ExprMarkInexistentInElement('ParagraphVisible','<CR>')
Reason: viki uses `<expr>` on mapping `<CR>` that auto-pairs cannot expanding.
2013-02-16 01:02:13 -05:00
Solution A: Add
autocmd filetype viki inoremap <buffer> <silent> <CR> <C-R>=viki#ExprMarkInexistentInElement('ParagraphVisible',"\n")<CR><C-R>=AutoPairsReturn()<CR>`
2012-10-29 02:50:45 -04:00
to .vimrc, it will make viki and auto-pairs works together.
2013-02-16 01:02:13 -05:00
2012-10-24 13:13:24 -04:00
Solution B: add `let g:AutoPairsMapCR = 0` to .vimrc to disable `<CR>` mapping.
2013-02-16 01:02:13 -05:00
2012-10-24 13:13:24 -04:00
Remarks: Solution A need NOT add `let g:AutoPairsMapCR = 0` to .vimrc, if Solution A still cannot work, then have to use Solution B to disable auto-pairs `<CR>`.
2012-10-24 12:59:21 -04:00
2012-07-15 10:50:09 -04:00
Breaks '.' - [issue #3](https://github.com/jiangmiao/auto-pairs/issues/3)
2012-08-11 10:30:11 -04:00
Description: After entering insert mode and inputing `[hello` then leave insert
mode by `<ESC>`. press '.' will insert 'hello' instead of '[hello]'.
2012-07-15 10:50:09 -04:00
Reason: `[` actually equals `[]\<LEFT>` and \<LEFT> will break '.'
Solution: none
2011-12-29 08:42:43 -05:00
Contributors
------------
* [camthompson](https://github.com/camthompson)
2012-07-15 10:50:09 -04:00
2013-03-17 07:32:25 -04:00
License
-------
Copyright (C) 2011-2013 Miao Jiang
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.