mirror of
https://github.com/Raimondi/delimitMate.git
synced 2025-12-08 05:34:45 +08:00
Compare commits
36 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
860c45ab2a | ||
|
|
8686edfc63 | ||
|
|
5e7a7c4738 | ||
|
|
928cc1146a | ||
|
|
d420afdacd | ||
|
|
f6015300a0 | ||
|
|
e183064744 | ||
|
|
40849c94ef | ||
|
|
4c1424f9bd | ||
|
|
0783f97fc0 | ||
|
|
e551885c24 | ||
|
|
4891a04258 | ||
|
|
ad77a9a75e | ||
|
|
5bf35a6b31 | ||
|
|
49044099dd | ||
|
|
7c423067a8 | ||
|
|
d08fa765b9 | ||
|
|
f47bcd8e3f | ||
|
|
873e79ec37 | ||
|
|
589b2ae85a | ||
|
|
f9f2b5f177 | ||
|
|
4157dc8a88 | ||
|
|
d0fc1456b7 | ||
|
|
86f70a7d9c | ||
|
|
f7b53f045d | ||
|
|
f3d140e363 | ||
|
|
93a1770f37 | ||
|
|
859a732509 | ||
|
|
eb778be64b | ||
|
|
2b2ae65182 | ||
|
|
e1b52d3676 | ||
|
|
ff4745b191 | ||
|
|
2ba694830d | ||
|
|
12c5c96ca2 | ||
|
|
a97af1fb97 | ||
|
|
5bf6a1e30c |
@@ -1,10 +1,10 @@
|
||||
" ============================================================================
|
||||
" File: autoload/delimitMate.vim
|
||||
" Version: 2.5.1
|
||||
" Modified: 2010-09-30
|
||||
" Version: 2.6
|
||||
" Modified: 2011-01-14
|
||||
" Description: This plugin provides auto-completion for quotes, parens, etc.
|
||||
" Maintainer: Israel Chauca F. <israelchauca@gmail.com>
|
||||
" Manual: Read ":help delimitMate".
|
||||
" ============================================================================
|
||||
|
||||
" Utilities {{{
|
||||
|
||||
@@ -215,6 +215,13 @@ function! delimitMate#BalancedParens(char) "{{{
|
||||
return opening - closing
|
||||
endfunction "}}}
|
||||
|
||||
function! delimitMate#RmBuffer(num) " {{{
|
||||
if len(b:_l_delimitMate_buffer) > 0
|
||||
call remove(b:_l_delimitMate_buffer, 0, (a:num-1))
|
||||
endif
|
||||
return ""
|
||||
endfunction " }}}
|
||||
|
||||
" }}}
|
||||
|
||||
" Doers {{{
|
||||
@@ -252,13 +259,21 @@ function! delimitMate#ParenDelim(char) " {{{
|
||||
if delimitMate#IsForbidden(a:char)
|
||||
return ''
|
||||
endif
|
||||
" Try to balance matchpairs
|
||||
if b:_l_delimitMate_balance_matchpairs &&
|
||||
\ delimitMate#BalancedParens(a:char) <= 0
|
||||
return ''
|
||||
endif
|
||||
let line = getline('.')
|
||||
let col = col('.')-2
|
||||
if (col) < 0
|
||||
let left = b:_l_delimitMate_left_delims[index(b:_l_delimitMate_right_delims,a:char)]
|
||||
let smart_matchpairs = substitute(b:_l_delimitMate_smart_matchpairs, '\\!', left, 'g')
|
||||
let smart_matchpairs = substitute(smart_matchpairs, '\\#', a:char, 'g')
|
||||
"echom left.':'.smart_matchpairs . ':' . matchstr(line[col+1], smart_matchpairs)
|
||||
if b:_l_delimitMate_smart_matchpairs != '' &&
|
||||
\ line[col+1:] =~ smart_matchpairs
|
||||
return ''
|
||||
elseif (col) < 0
|
||||
call setline('.',a:char.line)
|
||||
call insert(b:_l_delimitMate_buffer, a:char)
|
||||
else
|
||||
@@ -282,10 +297,10 @@ function! delimitMate#QuoteDelim(char) "{{{
|
||||
\ index(b:_l_delimitMate_nesting_quotes, a:char) < 0
|
||||
" Get out of the string.
|
||||
return a:char . delimitMate#Del()
|
||||
elseif (line[col] =~ '[[:alnum:]]' && a:char == "'") ||
|
||||
elseif (line[col] =~ '\w' && a:char == "'") ||
|
||||
\ (b:_l_delimitMate_smart_quotes &&
|
||||
\ (line[col] =~ '[[:alnum:]]' ||
|
||||
\ line[col + 1] =~ '[[:alnum:]]'))
|
||||
\ (line[col] =~ '\w' ||
|
||||
\ line[col + 1] =~ '\w'))
|
||||
" Seems like an apostrophe or a smart quote case, insert a single quote.
|
||||
return a:char
|
||||
elseif (line[col] == a:char && line[col + 1 ] != a:char) && b:_l_delimitMate_smart_quotes
|
||||
@@ -338,11 +353,31 @@ function! delimitMate#JumpAny(key) " {{{
|
||||
endif
|
||||
endfunction " delimitMate#JumpAny() }}}
|
||||
|
||||
function! delimitMate#MapMsg(msg) "{{{
|
||||
redraw
|
||||
echomsg a:msg
|
||||
return ""
|
||||
endfunction "}}}
|
||||
function! delimitMate#JumpMany() " {{{
|
||||
let line = getline('.')[col('.') - 1 : ]
|
||||
let len = len(line)
|
||||
let rights = ""
|
||||
let found = 0
|
||||
let i = 0
|
||||
while i < len
|
||||
let char = line[i]
|
||||
if index(b:_l_delimitMate_quotes_list, char) >= 0 ||
|
||||
\ index(b:_l_delimitMate_right_delims, char) >= 0
|
||||
let rights .= "\<Right>"
|
||||
let found = 1
|
||||
elseif found == 0
|
||||
let rights .= "\<Right>"
|
||||
else
|
||||
break
|
||||
endif
|
||||
let i += 1
|
||||
endwhile
|
||||
if found == 1
|
||||
return rights
|
||||
else
|
||||
return ''
|
||||
endif
|
||||
endfunction " delimitMate#JumpMany() }}}
|
||||
|
||||
function! delimitMate#ExpandReturn() "{{{
|
||||
if delimitMate#IsForbidden("")
|
||||
@@ -401,7 +436,7 @@ function! delimitMate#Del() " {{{
|
||||
endif
|
||||
endfunction " }}}
|
||||
|
||||
function! delimitMate#Finish() " {{{
|
||||
function! delimitMate#Finish(move_back) " {{{
|
||||
let len = len(b:_l_delimitMate_buffer)
|
||||
if len > 0
|
||||
let buffer = join(b:_l_delimitMate_buffer, '')
|
||||
@@ -417,8 +452,8 @@ function! delimitMate#Finish() " {{{
|
||||
call setline('.', line[:col] . line[col+len2+1:])
|
||||
endif
|
||||
let i = 1
|
||||
let lefts = "\<Left>"
|
||||
while i < len
|
||||
let lefts = ""
|
||||
while i <= len && a:move_back
|
||||
let lefts = lefts . "\<Left>"
|
||||
let i += 1
|
||||
endwhile
|
||||
@@ -427,21 +462,14 @@ function! delimitMate#Finish() " {{{
|
||||
return ''
|
||||
endfunction " }}}
|
||||
|
||||
function! delimitMate#RmBuffer(num) " {{{
|
||||
if len(b:_l_delimitMate_buffer) > 0
|
||||
call remove(b:_l_delimitMate_buffer, 0, (a:num-1))
|
||||
endif
|
||||
return ""
|
||||
endfunction " }}}
|
||||
|
||||
" }}}
|
||||
|
||||
" Tools: {{{
|
||||
function! delimitMate#TestMappings() "{{{
|
||||
let options = sort(keys(delimitMate#OptionsList()))
|
||||
let optoutput = ['delimitMate Report', '==================', '', '* Options: (-) unset, (g) global, (b) buffer','']
|
||||
let optoutput = ['delimitMate Report', '==================', '', '* Options: ( ) default, (g) global, (b) buffer','']
|
||||
for option in options
|
||||
exec 'call add(optoutput, ''('.(exists('b:delimitMate_'.option) ? 'b' : exists('g:delimitMate_'.option) ? 'g' : '-').') delimitMate_''.option.'' = ''.string(b:_l_delimitMate_'.option.'))'
|
||||
exec 'call add(optoutput, ''('.(exists('b:delimitMate_'.option) ? 'b' : exists('g:delimitMate_'.option) ? 'g' : ' ').') delimitMate_''.option.'' = ''.string(b:_l_delimitMate_'.option.'))'
|
||||
endfor
|
||||
call append(line('$'), optoutput + ['--------------------',''])
|
||||
|
||||
@@ -453,7 +481,7 @@ function! delimitMate#TestMappings() "{{{
|
||||
\ b:_l_delimitMate_apostrophes_list +
|
||||
\ ['<BS>', '<S-BS>', '<Del>', '<S-Tab>', '<Esc>'] +
|
||||
\ ['<Up>', '<Down>', '<Left>', '<Right>', '<LeftMouse>', '<RightMouse>'] +
|
||||
\ ['<Home>', '<End>', '<PageUp>', '<PageDown>', '<S-Down>', '<S-Up>']
|
||||
\ ['<Home>', '<End>', '<PageUp>', '<PageDown>', '<S-Down>', '<S-Up>', '<C-G>g']
|
||||
let imaps = imaps + ( b:_l_delimitMate_expand_cr ? ['<CR>'] : [] )
|
||||
let imaps = imaps + ( b:_l_delimitMate_expand_space ? ['<Space>'] : [] )
|
||||
|
||||
@@ -473,7 +501,6 @@ function! delimitMate#TestMappings() "{{{
|
||||
let ibroken = ibroken + [map.": is not set:"] + split(output, '\n')
|
||||
endif
|
||||
endfor
|
||||
let ibroken = len(ibroken) > 0 ? ['IMAP'] + ibroken : []
|
||||
|
||||
unlet! output
|
||||
if ibroken == []
|
||||
@@ -486,49 +513,73 @@ function! delimitMate#TestMappings() "{{{
|
||||
if b:_l_delimitMate_autoclose
|
||||
" {{{
|
||||
for i in range(len(b:_l_delimitMate_left_delims))
|
||||
exec "normal GGoOpen: " . b:_l_delimitMate_left_delims[i]. "|"
|
||||
exec "normal oDelete: " . b:_l_delimitMate_left_delims[i] . "\<BS>|"
|
||||
exec "normal oExit: " . b:_l_delimitMate_left_delims[i] . b:_l_delimitMate_right_delims[i] . "|"
|
||||
exec "normal oSpace: " . b:_l_delimitMate_left_delims[i] . " |"
|
||||
exec "normal oDelete space: " . b:_l_delimitMate_left_delims[i] . " \<BS>|"
|
||||
exec "normal oCar return: " . b:_l_delimitMate_left_delims[i] . "\<CR>|"
|
||||
exec "normal GGoDelete car return: " . b:_l_delimitMate_left_delims[i] . "\<CR>\<BS>|\<Esc>GG\<Esc>o"
|
||||
exec "normal Go0\<C-D>Open: " . b:_l_delimitMate_left_delims[i]. "|"
|
||||
exec "normal o0\<C-D>Delete: " . b:_l_delimitMate_left_delims[i] . "\<BS>|"
|
||||
exec "normal o0\<C-D>Exit: " . b:_l_delimitMate_left_delims[i] . b:_l_delimitMate_right_delims[i] . "|"
|
||||
if b:_l_delimitMate_expand_space == 1
|
||||
exec "normal o0\<C-D>Space: " . b:_l_delimitMate_left_delims[i] . " |"
|
||||
exec "normal o0\<C-D>Delete space: " . b:_l_delimitMate_left_delims[i] . " \<BS>|"
|
||||
endif
|
||||
if b:_l_delimitMate_expand_cr == 1
|
||||
exec "normal o0\<C-D>Car return: " . b:_l_delimitMate_left_delims[i] . "\<CR>|"
|
||||
exec "normal Go0\<C-D>Delete car return: " . b:_l_delimitMate_left_delims[i] . "\<CR>0\<C-D>\<BS>|"
|
||||
endif
|
||||
call append(line('$'), '')
|
||||
endfor
|
||||
for i in range(len(b:_l_delimitMate_quotes_list))
|
||||
exec "normal GGAOpen: " . b:_l_delimitMate_quotes_list[i] . "|"
|
||||
exec "normal oDelete: " . b:_l_delimitMate_left_delims[i] . b:_l_delimitMate_right_delims[i] . "\<BS>|"
|
||||
exec "normal oExit: " . b:_l_delimitMate_quotes_list[i] . b:_l_delimitMate_quotes_list[i] . "|"
|
||||
exec "normal oSpace: " . b:_l_delimitMate_quotes_list[i] . " |"
|
||||
exec "normal oDelete space: " . b:_l_delimitMate_quotes_list[i] . " \<BS>|"
|
||||
exec "normal oCar return: " . b:_l_delimitMate_quotes_list[i] . "\<CR>|"
|
||||
exec "normal GGoDelete car return: " . b:_l_delimitMate_quotes_list[i] . "\<CR>\<BS>|\<Esc>GG\<Esc>o"
|
||||
exec "normal Go0\<C-D>Open: " . b:_l_delimitMate_quotes_list[i] . "|"
|
||||
exec "normal o0\<C-D>Delete: " . b:_l_delimitMate_quotes_list[i] . "\<BS>|"
|
||||
exec "normal o0\<C-D>Exit: " . b:_l_delimitMate_quotes_list[i] . b:_l_delimitMate_quotes_list[i] . "|"
|
||||
if b:_l_delimitMate_expand_space == 1
|
||||
exec "normal o0\<C-D>Space: " . b:_l_delimitMate_quotes_list[i] . " |"
|
||||
exec "normal o0\<C-D>Delete space: " . b:_l_delimitMate_quotes_list[i] . " \<BS>|"
|
||||
endif
|
||||
if b:_l_delimitMate_expand_cr == 1
|
||||
exec "normal o0\<C-D>Car return: " . b:_l_delimitMate_quotes_list[i] . "\<CR>|"
|
||||
exec "normal Go0\<C-D>Delete car return: " . b:_l_delimitMate_quotes_list[i] . "\<CR>\<BS>|"
|
||||
endif
|
||||
call append(line('$'), '')
|
||||
endfor
|
||||
"}}}
|
||||
else
|
||||
"{{{
|
||||
for i in range(len(b:_l_delimitMate_left_delims))
|
||||
exec "normal GGoOpen & close: " . b:_l_delimitMate_left_delims[i] . b:_l_delimitMate_right_delims[i] . "|"
|
||||
exec "normal GoOpen & close: " . b:_l_delimitMate_left_delims[i] . b:_l_delimitMate_right_delims[i] . "|"
|
||||
exec "normal oDelete: " . b:_l_delimitMate_left_delims[i] . b:_l_delimitMate_right_delims[i] . "\<BS>|"
|
||||
exec "normal oExit: " . b:_l_delimitMate_left_delims[i] . b:_l_delimitMate_right_delims[i] . b:_l_delimitMate_right_delims[i] . "|"
|
||||
exec "normal oSpace: " . b:_l_delimitMate_left_delims[i] . b:_l_delimitMate_right_delims[i] . " |"
|
||||
exec "normal oDelete space: " . b:_l_delimitMate_left_delims[i] . b:_l_delimitMate_right_delims[i] . " \<BS>|"
|
||||
exec "normal oCar return: " . b:_l_delimitMate_left_delims[i] . b:_l_delimitMate_right_delims[i] . "\<CR>|"
|
||||
exec "normal GGoDelete car return: " . b:_l_delimitMate_left_delims[i] . b:_l_delimitMate_right_delims[i] . "\<CR>\<BS>|\<Esc>GG\<Esc>o"
|
||||
if b:_l_delimitMate_expand_space == 1
|
||||
exec "normal oSpace: " . b:_l_delimitMate_left_delims[i] . b:_l_delimitMate_right_delims[i] . " |"
|
||||
exec "normal oDelete space: " . b:_l_delimitMate_left_delims[i] . b:_l_delimitMate_right_delims[i] . " \<BS>|"
|
||||
endif
|
||||
if b:_l_delimitMate_expand_cr == 1
|
||||
exec "normal oCar return: " . b:_l_delimitMate_left_delims[i] . b:_l_delimitMate_right_delims[i] . "\<CR>|"
|
||||
exec "normal GoDelete car return: " . b:_l_delimitMate_left_delims[i] . b:_l_delimitMate_right_delims[i] . "\<CR>\<BS>|"
|
||||
endif
|
||||
call append(line('$'), '')
|
||||
endfor
|
||||
for i in range(len(b:_l_delimitMate_quotes_list))
|
||||
exec "normal GGoOpen & close: " . b:_l_delimitMate_quotes_list[i] . b:_l_delimitMate_quotes_list[i] . "|"
|
||||
exec "normal GoOpen & close: " . b:_l_delimitMate_quotes_list[i] . b:_l_delimitMate_quotes_list[i] . "|"
|
||||
exec "normal oDelete: " . b:_l_delimitMate_quotes_list[i] . b:_l_delimitMate_quotes_list[i] . "\<BS>|"
|
||||
exec "normal oExit: " . b:_l_delimitMate_quotes_list[i] . b:_l_delimitMate_quotes_list[i] . b:_l_delimitMate_quotes_list[i] . "|"
|
||||
exec "normal oSpace: " . b:_l_delimitMate_quotes_list[i] . b:_l_delimitMate_quotes_list[i] . " |"
|
||||
exec "normal oDelete space: " . b:_l_delimitMate_quotes_list[i] . b:_l_delimitMate_quotes_list[i] . " \<BS>|"
|
||||
exec "normal oCar return: " . b:_l_delimitMate_quotes_list[i] . b:_l_delimitMate_quotes_list[i] . "\<CR>|"
|
||||
exec "normal GGoDelete car return: " . b:_l_delimitMate_quotes_list[i] . b:_l_delimitMate_quotes_list[i] . "\<CR>\<BS>|\<Esc>GG\<Esc>o"
|
||||
if b:_l_delimitMate_expand_space == 1
|
||||
exec "normal oSpace: " . b:_l_delimitMate_quotes_list[i] . b:_l_delimitMate_quotes_list[i] . " |"
|
||||
exec "normal oDelete space: " . b:_l_delimitMate_quotes_list[i] . b:_l_delimitMate_quotes_list[i] . " \<BS>|"
|
||||
endif
|
||||
if b:_l_delimitMate_expand_cr == 1
|
||||
exec "normal oCar return: " . b:_l_delimitMate_quotes_list[i] . b:_l_delimitMate_quotes_list[i] . "\<CR>|"
|
||||
exec "normal GoDelete car return: " . b:_l_delimitMate_quotes_list[i] . b:_l_delimitMate_quotes_list[i] . "\<CR>\<BS>|"
|
||||
endif
|
||||
call append(line('$'), '')
|
||||
endfor
|
||||
endif "}}}
|
||||
redir => setoptions | set | filetype | redir END
|
||||
call append(line('$'), split(setoptions,"\n")
|
||||
\ + ['--------------------'])
|
||||
setlocal nowrap
|
||||
endfunction "}}}
|
||||
|
||||
function! delimitMate#OptionsList() "{{{
|
||||
return {'autoclose' : 1,'matchpairs': &matchpairs, 'quotes' : '" '' `', 'nesting_quotes' : [], 'expand_cr' : 0, 'expand_space' : 0, 'smart_quotes' : 1, 'balance_matchpairs' : 0, 'excluded_regions' : 'Comment', 'excluded_ft' : '', 'apostrophes' : ''}
|
||||
return {'autoclose' : 1,'matchpairs': &matchpairs, 'quotes' : '" '' `', 'nesting_quotes' : [], 'expand_cr' : 0, 'expand_space' : 0, 'smart_quotes' : 1, 'smart_matchpairs' : '\w', 'balance_matchpairs' : 0, 'excluded_regions' : 'Comment', 'excluded_ft' : '', 'apostrophes' : ''}
|
||||
endfunction " delimitMate#OptionsList }}}
|
||||
"}}}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ function! delimitMateTests#Main()
|
||||
echoerr "delimitMateTests#Main(): If you really want to use me, you must set delimitMate_testing to any value."
|
||||
return
|
||||
elseif g:delimitMate_testing == "fork"
|
||||
!gvim -N -u NONE -U NONE -c "set backspace=eol,start" -c "set background=light" -c "syntax on" -c "let delimitMate_testing = 1" -c "so autoload/delimitMate.vim" -c "so autoload/delimitMateTests.vim" -c "so plugin/delimitMate.vim" -c "call delimitMateTests\#Main()"
|
||||
!gvim -N -u NONE -U NONE -c "set runtimepath+=~/.vim/bundle/pathogen" -c "call pathogen\#runtime_append_all_bundles('bundle','symlinks')" -c "set backspace=eol,start" -c "set background=light" -c "syntax on" -c "let delimitMate_testing = 1" -c "ru autoload/delimitMate.vim" -c "ru autoload/delimitMateTests.vim" -c "ru plugin/delimitMate.vim" -c "call delimitMateTests\#Main()"
|
||||
return ""
|
||||
endif
|
||||
nmap <F1> :qall!<CR>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
*delimitMate.txt* Trying to keep those beasts at bay! v2.5.1 *delimitMate*
|
||||
*delimitMate.txt* Trying to keep those beasts at bay! v2.6 *delimitMate*
|
||||
|
||||
|
||||
|
||||
@@ -93,6 +93,8 @@ specific file types, see |delimitMateOptionDetails| for examples.
|
||||
|
||||
|'delimitMate_smart_quotes'| Turns on/off the "smart quotes" feature.
|
||||
|
||||
|'delimitMate_smart_matchpairs'| Turns on/off the "smart matchpairs" feature.
|
||||
|
||||
|'delimitMate_balance_matchpairs'|Turns on/off the "balance matching pairs"
|
||||
feature.
|
||||
|
||||
@@ -182,7 +184,8 @@ Values: 1 or 0 ~
|
||||
Default: 0 ~
|
||||
|
||||
This option turns on/off the expansion of <CR>. Read |delimitMateExpansion|
|
||||
for details.
|
||||
for details. NOTE This feature requires that 'backspace' is either set to 2 or
|
||||
has "eol" and "start" as part of its value.
|
||||
e.g.: >
|
||||
let delimitMate_expand_cr = 1
|
||||
au FileType mail let b:delimitMate_expand_cr = 1
|
||||
@@ -192,7 +195,6 @@ e.g.: >
|
||||
*'b:delimitMate_expand_space'*
|
||||
Values: 1 or 0 ~
|
||||
Default: 0 ~
|
||||
|
||||
This option turns on/off the expansion of <Space>. Read |delimitMateExpansion|
|
||||
for details.
|
||||
e.g.: >
|
||||
@@ -203,13 +205,28 @@ e.g.: >
|
||||
*'delimitMate_smart_quotes'*
|
||||
*'b:delimitMate_smart_quotes'*
|
||||
Values: 1 or 0 ~
|
||||
Default: 1 ~
|
||||
Default: 1 ~
|
||||
|
||||
This option turns on/off the smart quotes feature. Read
|
||||
|delimitMateSmartQuotes| for details.
|
||||
e.g.: >
|
||||
let delimitMate_smart_quotes = 0
|
||||
au FileType tcl let b:delimitMate_smart_quotes = 0
|
||||
au FileType tcl let b:delimitMate_smart_quotes = 1
|
||||
<
|
||||
------------------------------------------------------------------------------
|
||||
*'delimitMate_smart_matchpairs'*
|
||||
*'b:delimitMate_smart_matchpairs'*
|
||||
Values: Regexp ~
|
||||
Default: '^\%(\w\|\!\|£\|\$\|_\|["'']\s*\S\)' ~
|
||||
|
||||
This regex is matched against the text to the right of cursor, if it's not
|
||||
empty and there is a match delimitMate will not autoclose the pair. At the
|
||||
moment to match the text, an escaped bang (\!) in the regex will be replaced
|
||||
by the character being inserted, while an escaped number symbol (\#) will be
|
||||
replaced by the closing pair.
|
||||
e.g.: >
|
||||
let delimitMate_smart_matchpairs = ''
|
||||
au FileType tcl let b:delimitMate_smart_matchpairs = '^\%(\w\|\$\)'
|
||||
<
|
||||
------------------------------------------------------------------------------
|
||||
*'delimitMate_balance_matchpairs'*
|
||||
@@ -274,31 +291,42 @@ When the cursor is inside an empty pair or located next to the left of a
|
||||
closing delimiter, the cursor is placed outside the pair to the right of the
|
||||
closing delimiter.
|
||||
|
||||
Unless |'delimitMate_matchpairs'| or |'delimitMate_quotes'|are set, this
|
||||
When |'delimitMate_smart_matchpairs'| is not empty and it matches the text to
|
||||
the right of the cursor, delimitMate will not automatically insert the closing
|
||||
pair.
|
||||
|
||||
Unless |'delimitMate_matchpairs'| or |'delimitMate_quotes'| are set, this
|
||||
script uses the values in '&matchpairs' to identify the pairs, and ", ' and `
|
||||
for quotes respectively.
|
||||
|
||||
<S-Tab> will jump over a single closing delimiter or quote, <C-G>g will jump
|
||||
over contiguous delimiters and/or quotes.
|
||||
|
||||
The following table shows the behaviour, this applies to quotes too (the final
|
||||
position of the cursor is represented by a "|"):
|
||||
|
||||
With auto-close: >
|
||||
Type | You get
|
||||
====================
|
||||
( | (|)
|
||||
–––––––––|––––––––––
|
||||
() | ()|
|
||||
–––––––––|––––––––––
|
||||
(<S-Tab> | ()|
|
||||
Type | You get
|
||||
=======================
|
||||
( | (|)
|
||||
–––––––––––|–––––––––––
|
||||
() | ()|
|
||||
–––––––––––|–––––––––––
|
||||
(<S-Tab> | ()|
|
||||
–––––––––––|–––––––––––
|
||||
{("<C-G>g | {("")}|
|
||||
<
|
||||
Without auto-close: >
|
||||
|
||||
Type | You get
|
||||
=====================
|
||||
() | (|)
|
||||
–––––––––-|––––––––––
|
||||
()) | ()|
|
||||
–––––––––-|––––––––––
|
||||
()<S-Tab> | ()|
|
||||
Type | You get
|
||||
=========================
|
||||
() | (|)
|
||||
–––––––––-----|––––––––––
|
||||
()) | ()|
|
||||
–––––––––-----|––––––––––
|
||||
()<S-Tab> | ()|
|
||||
––––––––––––––|–––––––––––
|
||||
{}()""<C-G>g | {("")}|
|
||||
<
|
||||
NOTE: Abbreviations will not be expanded by delimiters used on delimitMate,
|
||||
you should use <C-]> (read |i_CTRL-]|) to expand them on the go.
|
||||
@@ -361,7 +389,7 @@ e.g. typing at the "|": >
|
||||
3.4 SMART QUOTES *delimitMateSmartQuotes*
|
||||
|
||||
Only one quote will be inserted following a quote, a "\" or, following or
|
||||
preceding an alphanumeric character. This should cover closing quotes after a
|
||||
preceding a keyword character. This should cover closing quotes after a
|
||||
string, opening quotes before a string, escaped quotes and apostrophes. Except
|
||||
for apostrophes, this feature can be disabled setting the option
|
||||
|'delimitMate_smart_quotes'| to 0.
|
||||
@@ -375,6 +403,22 @@ e.g. typing at the "|": >
|
||||
" | let i = "| | let i = "|"
|
||||
'm | I| | I'm|
|
||||
<
|
||||
------------------------------------------------------------------------------
|
||||
3.4 SMART MATCHPAIRS *delimitMateSmartMatchpairs*
|
||||
|
||||
This is similar to "smart quotes", but applied to the characters in
|
||||
|'delimitMate_matchpairs'|. The difference is that delimitMate will not
|
||||
auto-close the pair when the regex matches the text on the right of the
|
||||
cursor. See |'delimitMate_smart_matchpairs'| for more details.
|
||||
|
||||
|
||||
e.g. typing at the "|": >
|
||||
|
||||
What | Before | After
|
||||
=======================================
|
||||
( | function| | function(|)
|
||||
( | |var | (|var
|
||||
<
|
||||
------------------------------------------------------------------------------
|
||||
3.5 BALANCING MATCHING PAIRS *delimitMateBalance*
|
||||
|
||||
@@ -386,9 +430,9 @@ e.g. typing at the "|": >
|
||||
|
||||
What | Before | After
|
||||
=======================================
|
||||
( | |) | (|)
|
||||
( | | | (|)
|
||||
( | (|) | ((|))
|
||||
( | |) | (|)
|
||||
(( | |) | ((|))
|
||||
<
|
||||
------------------------------------------------------------------------------
|
||||
3.6 FILE TYPE BASED CONFIGURATION *delimitMateFileType*
|
||||
@@ -521,11 +565,12 @@ In order to make custom mappings easier and prevent overwritting existing
|
||||
ones, delimitMate uses the |<Plug>| + |hasmapto()| (|usr_41.txt|) construct
|
||||
for its mappings.
|
||||
|
||||
The following are the mappings alway set by delimitMate:
|
||||
These are the default mappings:
|
||||
|
||||
<BS> is mapped to <Plug>delimitMateBS
|
||||
<S-BS> is mapped to <Plug>delimitMateS-BS
|
||||
<S-Tab> is mapped to <Plug>delimitMateS-Tab
|
||||
<C-G>g is mapped to <Plug>delimitMateJumpMany
|
||||
<Del> is mapped to <Plug>delimitMateDel
|
||||
<Esc> is mapped to <Plug>delimitMateEsc
|
||||
<Left> is mapped to <Plug>delimitMateLeft
|
||||
@@ -562,7 +607,7 @@ menus:
|
||||
6. FUNCTIONS *delimitMateFunctions*
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
delimitMate#WithinEmptyPair() *delimitMate_WithinEmptyPair()*
|
||||
delimitMate#WithinEmptyPair() *delimitMate#WithinEmptyPair()*
|
||||
|
||||
Returns 1 if the cursor is inside an empty pair, 0 otherwise.
|
||||
e.g.: >
|
||||
@@ -606,28 +651,36 @@ be very pleased to read them.
|
||||
==============================================================================
|
||||
9. CREDITS *delimitMateCredits*
|
||||
|
||||
Some of the code that make this script is modified or just shamelessly copied
|
||||
from the following sources:
|
||||
Contributors: ~
|
||||
|
||||
- Ian McCracken
|
||||
Post titled: Vim, Part II: Matching Pairs:
|
||||
http://concisionandconcinnity.blogspot.com/
|
||||
- Kim Silkebækken ~
|
||||
Fixed mappings being echoed in the terminal.
|
||||
|
||||
- Aristotle Pagaltzis
|
||||
From the comments on the previous blog post and from:
|
||||
http://gist.github.com/144619
|
||||
- Eric Van Dewoestine ~
|
||||
Implemented smart matchpairs.
|
||||
|
||||
- Karl Guertin
|
||||
AutoClose:
|
||||
http://www.vim.org/scripts/script.php?script_id=1849
|
||||
Some of the code that makes this script was modified or just shamelessly
|
||||
copied from the following sources:
|
||||
|
||||
- Thiago Alves
|
||||
AutoClose:
|
||||
http://www.vim.org/scripts/script.php?script_id=2009
|
||||
- Ian McCracken ~
|
||||
Post titled: Vim, Part II: Matching Pairs:
|
||||
http://concisionandconcinnity.blogspot.com/
|
||||
|
||||
- Edoardo Vacchi
|
||||
ClosePairs:
|
||||
http://www.vim.org/scripts/script.php?script_id=2373
|
||||
- Aristotle Pagaltzis ~
|
||||
From the comments on the previous blog post and from:
|
||||
http://gist.github.com/144619
|
||||
|
||||
- Karl Guertin ~
|
||||
AutoClose:
|
||||
http://www.vim.org/scripts/script.php?script_id=1849
|
||||
|
||||
- Thiago Alves ~
|
||||
AutoClose:
|
||||
http://www.vim.org/scripts/script.php?script_id=2009
|
||||
|
||||
- Edoardo Vacchi ~
|
||||
ClosePairs:
|
||||
http://www.vim.org/scripts/script.php?script_id=2373
|
||||
|
||||
This script was inspired by the auto-completion of delimiters on TextMate.
|
||||
|
||||
@@ -636,8 +689,12 @@ This script was inspired by the auto-completion of delimiters on TextMate.
|
||||
|
||||
Version Date Release notes ~
|
||||
|---------|------------|-----------------------------------------------------|
|
||||
2.5.1 2010-09-30 * Current release:
|
||||
- Remove visual wrapping. Surround.vim offers a much
|
||||
2.6 2011-01-14 * Current release:
|
||||
- Add smart_matchpairs feature.
|
||||
- Add mapping to jump over contiguous delimiters.
|
||||
- Fix behaviour of b:loaded_delimitMate.
|
||||
|---------|------------|-----------------------------------------------------|
|
||||
2.5.1 2010-09-30 * - Remove visual wrapping. Surround.vim offers a much
|
||||
better implementation.
|
||||
- Minor mods to DelimitMateTest.
|
||||
|---------|------------|-----------------------------------------------------|
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
" ============================================================================
|
||||
" File: plugin/delimitMate.vim
|
||||
" Version: 2.5.1
|
||||
" Modified: 2010-09-30
|
||||
" Version: 2.6
|
||||
" Modified: 2011-01-14
|
||||
" Description: This plugin provides auto-completion for quotes, parens, etc.
|
||||
" Maintainer: Israel Chauca F. <israelchauca@gmail.com>
|
||||
" Manual: Read ":help delimitMate".
|
||||
" ============================================================================
|
||||
|
||||
" Initialization: {{{
|
||||
|
||||
@@ -27,7 +27,7 @@ if v:version < 700
|
||||
endif
|
||||
|
||||
let s:loaded_delimitMate = 1
|
||||
let delimitMate_version = "2.5.1"
|
||||
let delimitMate_version = "2.6"
|
||||
|
||||
function! s:option_init(name, default) "{{{
|
||||
let b = exists("b:delimitMate_" . a:name)
|
||||
@@ -104,14 +104,16 @@ function! s:init() "{{{
|
||||
unlet g:delimitMate_expand_cr
|
||||
let g:delimitMate_expand_cr = 1
|
||||
endif
|
||||
if (&backspace !~ 'eol' || &backspace !~ 'start') &&
|
||||
if ((&backspace !~ 'eol' || &backspace !~ 'start') && &backspace != 2) &&
|
||||
\ ((exists('b:delimitMate_expand_cr') && b:delimitMate_expand_cr == 1) ||
|
||||
\ (exists('g:delimitMate_expand_cr') && g:delimitMate_expand_cr == 1))
|
||||
echom "delimitMate: In order to use the <CR> expansion, you need to have 'eol' and 'start' in your backspace option. Read :help 'backspace'."
|
||||
let b:delimitMate_expand_cr = 0
|
||||
echom "delimitMate: There seems to be some incompatibility with your settings that may interfer with the expansion of <CR>. See :help 'delimitMate_expand_cr' for details."
|
||||
endif
|
||||
call s:option_init("expand_cr", 0)
|
||||
|
||||
" smart_matchpairs
|
||||
call s:option_init("smart_matchpairs", '^\%(\w\|\!\|£\|\$\|_\|["'']\s*\S\)')
|
||||
|
||||
" smart_quotes
|
||||
call s:option_init("smart_quotes", 1)
|
||||
|
||||
@@ -127,8 +129,6 @@ function! s:init() "{{{
|
||||
|
||||
let b:_l_delimitMate_buffer = []
|
||||
|
||||
let b:loaded_delimitMate = 1
|
||||
|
||||
endfunction "}}} Init()
|
||||
|
||||
"}}}
|
||||
@@ -169,7 +169,7 @@ function! s:Unmap() " {{{
|
||||
\ b:_l_delimitMate_apostrophes_list +
|
||||
\ ['<BS>', '<S-BS>', '<Del>', '<CR>', '<Space>', '<S-Tab>', '<Esc>'] +
|
||||
\ ['<Up>', '<Down>', '<Left>', '<Right>', '<LeftMouse>', '<RightMouse>'] +
|
||||
\ ['<Home>', '<End>', '<PageUp>', '<PageDown>', '<S-Down>', '<S-Up>']
|
||||
\ ['<Home>', '<End>', '<PageUp>', '<PageDown>', '<S-Down>', '<S-Up>', '<C-G>g']
|
||||
|
||||
for map in imaps
|
||||
if maparg(map, "i") =~? 'delimitMate'
|
||||
@@ -202,7 +202,7 @@ function! s:TestMappingsDo() "{{{
|
||||
call s:Unmap()
|
||||
call s:Map()
|
||||
call delimitMate#TestMappings()
|
||||
normal o
|
||||
call append(line('$'),'')
|
||||
endfor
|
||||
endfor
|
||||
let b:delimitMate_expand_space = temp_varsDM[0]
|
||||
@@ -215,25 +215,28 @@ function! s:TestMappingsDo() "{{{
|
||||
endfunction "}}}
|
||||
|
||||
function! s:DelimitMateDo(...) "{{{
|
||||
" Initialize settings:
|
||||
call s:init()
|
||||
|
||||
" Check if this file type is excluded:
|
||||
if exists("g:delimitMate_excluded_ft") &&
|
||||
\ index(split(g:delimitMate_excluded_ft, ','), &filetype, 0, 1) >= 0
|
||||
|
||||
" Remove any magic:
|
||||
call s:Unmap()
|
||||
|
||||
" Finish here:
|
||||
return 1
|
||||
endif
|
||||
|
||||
" First, remove all magic, if needed:
|
||||
if exists("b:delimitMate_enabled") && b:delimitMate_enabled == 1
|
||||
call s:Unmap()
|
||||
endif
|
||||
|
||||
" Check if this file type is excluded:
|
||||
if exists("g:delimitMate_excluded_ft") &&
|
||||
\ index(split(g:delimitMate_excluded_ft, ','), &filetype, 0, 1) >= 0
|
||||
|
||||
" Finish here:
|
||||
return 1
|
||||
endif
|
||||
|
||||
" Check if user tried to disable using b:loaded_delimitMate
|
||||
if exists("b:loaded_delimitMate")
|
||||
return 1
|
||||
endif
|
||||
|
||||
" Initialize settings:
|
||||
call s:init()
|
||||
|
||||
" Now, add magic:
|
||||
call s:Map()
|
||||
|
||||
@@ -243,30 +246,30 @@ function! s:DelimitMateDo(...) "{{{
|
||||
endfunction "}}}
|
||||
|
||||
function! s:DelimitMateSwitch() "{{{
|
||||
call s:init()
|
||||
if exists("b:delimitMate_enabled") && b:delimitMate_enabled
|
||||
call s:Unmap()
|
||||
echo "delimitMate has been disabled."
|
||||
else
|
||||
call s:Unmap()
|
||||
call s:init()
|
||||
call s:Map()
|
||||
echo "delimitMate has been enabled."
|
||||
endif
|
||||
endfunction "}}}
|
||||
|
||||
function! s:Finish()
|
||||
function! s:Finish() " {{{
|
||||
if exists('g:delimitMate_loaded')
|
||||
return delimitMate#Finish()
|
||||
return delimitMate#Finish(1)
|
||||
endif
|
||||
return ''
|
||||
endfunction
|
||||
endfunction " }}}
|
||||
|
||||
function! s:FlushBuffer()
|
||||
function! s:FlushBuffer() " {{{
|
||||
if exists('g:delimitMate_loaded')
|
||||
return delimitMate#FlushBuffer()
|
||||
endif
|
||||
return ''
|
||||
endfunction
|
||||
endfunction " }}}
|
||||
|
||||
"}}}
|
||||
|
||||
@@ -321,16 +324,34 @@ endfunction "}}}
|
||||
function! s:ExtraMappings() "{{{
|
||||
" If pair is empty, delete both delimiters:
|
||||
inoremap <silent> <Plug>delimitMateBS <C-R>=delimitMate#BS()<CR>
|
||||
if !hasmapto('<Plug>delimitMateBS','i')
|
||||
silent! imap <unique> <buffer> <BS> <Plug>delimitMateBS
|
||||
endif
|
||||
" If pair is empty, delete closing delimiter:
|
||||
inoremap <silent> <expr> <Plug>delimitMateS-BS delimitMate#WithinEmptyPair() ? "\<C-R>=delimitMate#Del()\<CR>" : "\<S-BS>"
|
||||
if !hasmapto('<Plug>delimitMateS-BS','i')
|
||||
silent! imap <unique> <buffer> <S-BS> <Plug>delimitMateS-BS
|
||||
endif
|
||||
" Expand return if inside an empty pair:
|
||||
inoremap <silent> <Plug>delimitMateCR <C-R>=delimitMate#ExpandReturn()<CR>
|
||||
if b:_l_delimitMate_expand_cr != 0 && !hasmapto('<Plug>delimitMateCR', 'i')
|
||||
silent! imap <unique> <buffer> <CR> <Plug>delimitMateCR
|
||||
endif
|
||||
" Expand space if inside an empty pair:
|
||||
inoremap <silent> <Plug>delimitMateSpace <C-R>=delimitMate#ExpandSpace()<CR>
|
||||
" Jump out ot any empty pair:
|
||||
if b:_l_delimitMate_expand_space != 0 && !hasmapto('<Plug>delimitMateSpace', 'i')
|
||||
silent! imap <unique> <buffer> <Space> <Plug>delimitMateSpace
|
||||
endif
|
||||
" Jump over any delimiter:
|
||||
inoremap <silent> <Plug>delimitMateS-Tab <C-R>=delimitMate#JumpAny("\<S-Tab>")<CR>
|
||||
if b:_l_delimitMate_tab2exit && !hasmapto('<Plug>delimitMateS-Tab', 'i')
|
||||
silent! imap <unique> <buffer> <S-Tab> <Plug>delimitMateS-Tab
|
||||
endif
|
||||
" Change char buffer on Del:
|
||||
inoremap <silent> <Plug>delimitMateDel <C-R>=delimitMate#Del()<CR>
|
||||
if !hasmapto('<Plug>delimitMateDel', 'i')
|
||||
silent! imap <unique> <buffer> <Del> <Plug>delimitMateDel
|
||||
endif
|
||||
" Flush the char buffer on movement keystrokes or when leaving insert mode:
|
||||
for map in ['Esc', 'Left', 'Right', 'Home', 'End']
|
||||
exec 'inoremap <silent> <Plug>delimitMate'.map.' <C-R>=<SID>Finish()<CR><'.map.'>'
|
||||
@@ -347,31 +368,18 @@ function! s:ExtraMappings() "{{{
|
||||
endfor
|
||||
" Avoid ambiguous mappings:
|
||||
for map in ['LeftMouse', 'RightMouse']
|
||||
exec 'inoremap <silent> <Plug>delimitMateM'.map.' <C-R>=delimitMate#Finish()<CR><'.map.'>'
|
||||
exec 'inoremap <silent> <Plug>delimitMateM'.map.' <C-R>=delimitMate#Finish(1)<CR><'.map.'>'
|
||||
if !hasmapto('<Plug>delimitMate'.map, 'i')
|
||||
exec 'silent! imap <unique> <buffer> <'.map.'> <Plug>delimitMateM'.map
|
||||
endif
|
||||
endfor
|
||||
|
||||
" Map away!
|
||||
if !hasmapto('<Plug>delimitMateDel', 'i')
|
||||
silent! imap <unique> <buffer> <Del> <Plug>delimitMateDel
|
||||
endif
|
||||
if !hasmapto('<Plug>delimitMateBS','i')
|
||||
silent! imap <unique> <buffer> <BS> <Plug>delimitMateBS
|
||||
endif
|
||||
if !hasmapto('<Plug>delimitMateS-BS','i')
|
||||
silent! imap <unique> <buffer> <S-BS> <Plug>delimitMateS-BS
|
||||
endif
|
||||
if b:_l_delimitMate_expand_cr != 0 && !hasmapto('<Plug>delimitMateCR', 'i')
|
||||
silent! imap <unique> <buffer> <CR> <Plug>delimitMateCR
|
||||
endif
|
||||
if b:_l_delimitMate_expand_space != 0 && !hasmapto('<Plug>delimitMateSpace', 'i')
|
||||
silent! imap <unique> <buffer> <Space> <Plug>delimitMateSpace
|
||||
endif
|
||||
if b:_l_delimitMate_tab2exit && !hasmapto('<Plug>delimitMateS-Tab', 'i')
|
||||
silent! imap <unique> <buffer> <S-Tab> <Plug>delimitMateS-Tab
|
||||
" Jump over next delimiters
|
||||
inoremap <buffer> <Plug>delimitMateJumpMany <C-R>=len(b:_l_delimitMate_buffer) ? delimitMate#Finish(0) : delimitMate#JumpMany()<CR>
|
||||
if !hasmapto('<Plug>delimitMateJumpMany')
|
||||
imap <silent> <buffer> <C-G>g <Plug>delimitMateJumpMany
|
||||
endif
|
||||
|
||||
" The following simply creates an ambiguous mapping so vim fully processes
|
||||
" the escape sequence for terminal keys, see 'ttimeout' for a rough
|
||||
" explanation, this just forces it to work
|
||||
@@ -406,8 +414,9 @@ augroup delimitMate
|
||||
|
||||
" Run on new buffers.
|
||||
autocmd BufNewFile,BufRead,BufEnter *
|
||||
\ if !exists("b:loaded_delimitMate") |
|
||||
\ if !exists('b:delimitMate_was_here') |
|
||||
\ call <SID>DelimitMateDo() |
|
||||
\ let b:delimitMate_was_here = 1 |
|
||||
\ endif
|
||||
|
||||
" Flush the char buffer:
|
||||
|
||||
Reference in New Issue
Block a user