mirror of
https://github.com/Raimondi/delimitMate.git
synced 2025-12-06 20:54:31 +08:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
11b08278fa |
@@ -20,7 +20,7 @@
|
|||||||
5. TODO list_______________________________|delimitMateTodo|
|
5. TODO list_______________________________|delimitMateTodo|
|
||||||
6. Maintainer______________________________|delimitMateMaintainer|
|
6. Maintainer______________________________|delimitMateMaintainer|
|
||||||
7. Credits_________________________________|delimitMateCredits|
|
7. Credits_________________________________|delimitMateCredits|
|
||||||
|
8. History_________________________________|delimitMateHistory|
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
1.- INTRODUCTION *delimitMate*
|
1.- INTRODUCTION *delimitMate*
|
||||||
@@ -133,38 +133,47 @@ e.g. (selection represented between square brackets): >
|
|||||||
3.1 OPTIONS SUMMARY *delimitMateOptionSummary*
|
3.1 OPTIONS SUMMARY *delimitMateOptionSummary*
|
||||||
|
|
||||||
The behaviour of this script can be customized setting the following options
|
The behaviour of this script can be customized setting the following options
|
||||||
in your vimrc file.
|
in your vimrc file. You can use local options to set the configuration for
|
||||||
|
specific file types, see |delimitMateOptionDetails| for examples.
|
||||||
|
|
||||||
|'loaded_delimitMate'| Turns off the script.
|
|'loaded_delimitMate'| Turns off the script.
|
||||||
|
|
||||||
|'delimitMate_autoclose'| Tells delimitMate whether to automagically
|
|'delimitMate_autoclose'| Tells delimitMate whether to automagically
|
||||||
insert the closing delimiter.
|
insert the closing delimiter.
|
||||||
|
|
||||||
|'b:delimitMate_matchpairs'| Tells delimitMate which characters are
|
|'delimitMate_matchpairs'| Tells delimitMate which characters are
|
||||||
matching pairs.
|
matching pairs.
|
||||||
|
|
||||||
|'b:delimitMate_quotes'| Tells delimitMate which quotes should be
|
|'delimitMate_quotes'| Tells delimitMate which quotes should be
|
||||||
used.
|
used.
|
||||||
|
|
||||||
|'delimitMate_visual_leader'| Sets the leader to be used in visual mode.
|
|'delimitMate_visual_leader'| Sets the leader to be used in visual mode.
|
||||||
|
|
||||||
|'b:delimitMate_expand_cr'| Sets the expansion for <CR> inside an empty
|
|'delimitMate_expand_cr'| Sets the expansion for <CR> inside an empty
|
||||||
pair of matching delimiters or quotes.
|
pair of matching delimiters or quotes.
|
||||||
|
|
||||||
|'b:delimitMate_expand_space'| Sets the expansion for <Space> inside an
|
|'delimitMate_expand_space'| Sets the expansion for <Space> inside an
|
||||||
empty pair of matching delimiters or quotes.
|
empty pair of matching delimiters or quotes.
|
||||||
|
|
||||||
|
|'delimitMate_excluded_ft'| Turns off the script for the given file types.
|
||||||
|
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
3.2 OPTIONS DETAILS *delimitMateOptionDetails*
|
3.2 OPTIONS DETAILS *delimitMateOptionDetails*
|
||||||
|
|
||||||
Add the shown lines to your vimrc files in order to set the below options.
|
Add the shown lines to your vimrc files in order to set the below options.
|
||||||
|
Local options take precedence over global ones and can be used along with
|
||||||
|
autocmd to modify delimitMate's behavior for specific file types.
|
||||||
|
|
||||||
*'loaded_delimitMate'*
|
*'loaded_delimitMate'*
|
||||||
You can turn off this plugin using this line in your vimrc: >
|
*'b:loaded_delimitMate'*
|
||||||
|
This option prevents delimitMate from loading.
|
||||||
|
e.g.: >
|
||||||
let loaded_delimitMate = 1
|
let loaded_delimitMate = 1
|
||||||
|
au FileType mail let b:loaded_delimitMate = 1
|
||||||
<
|
<
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
*'delimitMate_autoclose'*
|
*'delimitMate_autoclose'*
|
||||||
|
*'b:delimitMate_autoclose'*
|
||||||
Values: 0 or 1.
|
Values: 0 or 1.
|
||||||
Default: 1
|
Default: 1
|
||||||
|
|
||||||
@@ -172,9 +181,11 @@ If this option is set to 0, delimitMate will not add a closing delimiter
|
|||||||
automagically. See |delimitMateAutoClose| for details.
|
automagically. See |delimitMateAutoClose| for details.
|
||||||
e.g.: >
|
e.g.: >
|
||||||
let delimitMate_autoclose = 0
|
let delimitMate_autoclose = 0
|
||||||
|
au FileType mail let b:delimitMate_autoclose = 0
|
||||||
<
|
<
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
*'b:delimitMate_matchpairs'*
|
*'delimitMate_matchpairs'*
|
||||||
|
*'b:delimitMate_matchpairs'*
|
||||||
Values: A string with |matchpairs| syntax.
|
Values: A string with |matchpairs| syntax.
|
||||||
Default: &matchpairs
|
Default: &matchpairs
|
||||||
|
|
||||||
@@ -182,8 +193,10 @@ Use this option to tell delimitMate which characters should be considered
|
|||||||
matching pairs. Read |delimitMateAutoClose| for details.
|
matching pairs. Read |delimitMateAutoClose| for details.
|
||||||
e.g: >
|
e.g: >
|
||||||
let delimitMate = "(:),[:],{:},<:>"
|
let delimitMate = "(:),[:],{:},<:>"
|
||||||
|
au FileType vim,html let b:delimitMate_matchpairs = "(:),[:],{:},<:>"
|
||||||
<
|
<
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
|
*'delimitMate_quotes'*
|
||||||
*'b:delimitMate_quotes'*
|
*'b:delimitMate_quotes'*
|
||||||
Values: A string of characters separated by spaces.
|
Values: A string of characters separated by spaces.
|
||||||
Default: "\" ' `"
|
Default: "\" ' `"
|
||||||
@@ -192,9 +205,11 @@ Use this option to tell delimitMate which characters should be considered as
|
|||||||
quotes. Read |delimitMateAutoClose| for details.
|
quotes. Read |delimitMateAutoClose| for details.
|
||||||
e.g.: >
|
e.g.: >
|
||||||
let b:delimitMate_quotes = "\" ' ` *"
|
let b:delimitMate_quotes = "\" ' ` *"
|
||||||
|
au FileType html let b:delimitMate_quotes = "\" '"
|
||||||
<
|
<
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
*'delimitMate_visual_leader'*
|
*'delimitMate_visual_leader'*
|
||||||
|
*'b:delimitMate_visual_leader'*
|
||||||
Values: Any character.
|
Values: Any character.
|
||||||
Default: q
|
Default: q
|
||||||
|
|
||||||
@@ -202,8 +217,10 @@ The value of this option will be used to wrap the selection in visual mode
|
|||||||
when followed by a delimiter. Read |delimitMateVisualWrap| for details.
|
when followed by a delimiter. Read |delimitMateVisualWrap| for details.
|
||||||
e.g: >
|
e.g: >
|
||||||
let delimitMate_visual_leader = "f"
|
let delimitMate_visual_leader = "f"
|
||||||
|
au FileType html let b:delimitMate_visual_leader = "f"
|
||||||
<
|
<
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
|
*'delimitMate_expand_cr'*
|
||||||
*'b:delimitMate_expand_cr'*
|
*'b:delimitMate_expand_cr'*
|
||||||
Values: A key mapping.
|
Values: A key mapping.
|
||||||
Default: "\<CR>"
|
Default: "\<CR>"
|
||||||
@@ -212,8 +229,10 @@ The value of this option will be used to expand the car return character when
|
|||||||
typed inside an empty delimiter pair. Read |delimitMateExpansion| for details.
|
typed inside an empty delimiter pair. Read |delimitMateExpansion| for details.
|
||||||
e.g.: >
|
e.g.: >
|
||||||
let b:delimitMate_expand_cr = "\<CR>\<CR>\<Up>"
|
let b:delimitMate_expand_cr = "\<CR>\<CR>\<Up>"
|
||||||
|
au FileType mail let b:delimitMate_expand_cr = "\<CR>
|
||||||
<
|
<
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
|
*'delimitMate_expand_space'*
|
||||||
*'b:delimitMate_expand_space'*
|
*'b:delimitMate_expand_space'*
|
||||||
Values: A key mapping.
|
Values: A key mapping.
|
||||||
Default: "\<Space>"
|
Default: "\<Space>"
|
||||||
@@ -221,9 +240,19 @@ Default: "\<Space>"
|
|||||||
The value of this option will be used to expand the space character when typed
|
The value of this option will be used to expand the space character when typed
|
||||||
inside an empty delimiter pair. Read |delimitMateExpansion| for details.
|
inside an empty delimiter pair. Read |delimitMateExpansion| for details.
|
||||||
e.g.: >
|
e.g.: >
|
||||||
let b:delimitMate_expand_space = "\<Space>\<Space>\<Left>"
|
let delimitMate_expand_space = "\<Space>\<Space>\<Left>"
|
||||||
|
au filetype tcl let b:delimitMate_expand_space = "\<Space>"
|
||||||
<
|
<
|
||||||
|
------------------------------------------------------------------------------
|
||||||
|
*'delimitMate_excluded_ft'*
|
||||||
|
Values: A string of file type names separated by single commas.
|
||||||
|
Defaul: Empty.
|
||||||
|
|
||||||
|
This options turns delimitMate off for the listed file types, use this option
|
||||||
|
only if don't want any of the features it provides.
|
||||||
|
e.g.: >
|
||||||
|
let delimitMate_excluded_ft = "mail,txt"
|
||||||
|
<
|
||||||
==============================================================================
|
==============================================================================
|
||||||
4. PUBLIC COMMANDS *delimitMatePublicCommands*
|
4. PUBLIC COMMANDS *delimitMatePublicCommands*
|
||||||
|
|
||||||
@@ -231,7 +260,7 @@ e.g.: >
|
|||||||
:DelimitMateReload *:DelimitMateReload*
|
:DelimitMateReload *:DelimitMateReload*
|
||||||
|
|
||||||
Re-sets all the mappings used for this script, use it if any option has been
|
Re-sets all the mappings used for this script, use it if any option has been
|
||||||
changed.
|
changed or if the filetype option hasn't been set yet.
|
||||||
|
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
:DelimitMateTest *:DelimitMateTest*
|
:DelimitMateTest *:DelimitMateTest*
|
||||||
@@ -310,7 +339,6 @@ represented by an "|": >
|
|||||||
- Automatic set-up by file type.
|
- Automatic set-up by file type.
|
||||||
- Make visual wrapping work on blockwise visual mode.
|
- Make visual wrapping work on blockwise visual mode.
|
||||||
- Limit behaviour by region.
|
- Limit behaviour by region.
|
||||||
- Fix some problems wrapping a single empty line in visual mode.
|
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
6. MAINTAINER *delimitMateMaintainer*
|
6. MAINTAINER *delimitMateMaintainer*
|
||||||
@@ -340,4 +368,35 @@ from the following sources:
|
|||||||
|
|
||||||
This script was inspired by the auto-completion of delimiters of TextMate.
|
This script was inspired by the auto-completion of delimiters of TextMate.
|
||||||
|
|
||||||
|
==============================================================================
|
||||||
|
8. HISTORY *delimitMateHistory*
|
||||||
|
|
||||||
|
Version Date Release notes
|
||||||
|
|---------|------------|-----------------------------------------------------|
|
||||||
|
1.3 2009-09-24 Now local options can be used along with autocmd
|
||||||
|
for specific file type configurations.
|
||||||
|
Fixes:
|
||||||
|
- Unnamed register content is not lost on visual
|
||||||
|
mode.
|
||||||
|
- Use noremap where appropiate.
|
||||||
|
- Wrapping a single empty line works as expected.
|
||||||
|
|
||||||
|
|---------|------------|-----------------------------------------------------|
|
||||||
|
1.2 2009-09-07 Fixes:
|
||||||
|
- When inside nested empty pairs, deleting the
|
||||||
|
innermost left delimiter would delete all right
|
||||||
|
contiguous delimiters.
|
||||||
|
- When inside an empty pair, inserting a left
|
||||||
|
delimiter wouldn't insert the right one, instead
|
||||||
|
the cursor would jump to the right.
|
||||||
|
- New buffer inside the current window wouldn't
|
||||||
|
have the mappings set.
|
||||||
|
|---------|------------|-----------------------------------------------------|
|
||||||
|
1.1 2009-08-25 Fixed an error that ocurred when mapleader wasn't
|
||||||
|
set and added support for GetLatestScripts
|
||||||
|
auto-detection.
|
||||||
|
|---------|------------|-----------------------------------------------------|
|
||||||
|
1.0 2009-08-23 Initial upload.
|
||||||
|
|---------|------------|-----------------------------------------------------|
|
||||||
|
|
||||||
vim:tw=78:ts=8:ft=help:norl:
|
vim:tw=78:ts=8:ft=help:norl:
|
||||||
|
|||||||
269
delimitMate.vim
269
delimitMate.vim
@@ -1,6 +1,6 @@
|
|||||||
" ============================================================================
|
" ============================================================================
|
||||||
" File: delimitMate.vim
|
" File: delimitMate.vim
|
||||||
" Version: 1.1
|
" Version: 1.3
|
||||||
" Description: This plugin tries to emulate the auto-completion of delimiters
|
" Description: This plugin tries to emulate the auto-completion of delimiters
|
||||||
" that TextMate provides.
|
" that TextMate provides.
|
||||||
" Maintainer: Israel Chauca F. <israelchauca@gmail.com>
|
" Maintainer: Israel Chauca F. <israelchauca@gmail.com>
|
||||||
@@ -21,6 +21,7 @@ if exists("g:loaded_delimitMate") "{{{1
|
|||||||
" User doesn't want this plugin, let's get out!
|
" User doesn't want this plugin, let's get out!
|
||||||
finish
|
finish
|
||||||
endif
|
endif
|
||||||
|
let g:loaded_delimitMate = 1
|
||||||
|
|
||||||
if exists("s:loaded_delimitMate") && !exists("g:delimitMate_testing")
|
if exists("s:loaded_delimitMate") && !exists("g:delimitMate_testing")
|
||||||
" Don't define the functions if they already exist: just do the work
|
" Don't define the functions if they already exist: just do the work
|
||||||
@@ -34,24 +35,26 @@ if v:version < 700
|
|||||||
finish
|
finish
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let s:loaded_delimitMate = 1
|
let s:loaded_delimitMate = 1 " }}}1
|
||||||
|
|
||||||
function! s:Init() "{{{1
|
function! s:Init() "{{{1
|
||||||
|
|
||||||
if !exists("g:delimitMate_autoclose")
|
if !exists("b:delimitMate_autoclose") && !exists("g:delimitMate_autoclose") " {{{
|
||||||
let s:autoclose = 1
|
let s:autoclose = 1
|
||||||
|
elseif exists("b:delimitMate_autoclose")
|
||||||
|
let s:autoclose = b:delimitMate_autoclose
|
||||||
else
|
else
|
||||||
let s:autoclose = g:delimitMate_autoclose
|
let s:autoclose = g:delimitMate_autoclose
|
||||||
endif
|
endif " }}}
|
||||||
|
|
||||||
if !exists("b:delimitMate_matchpairs")
|
if !exists("b:delimitMate_matchpairs") && !exists("g:delimitMate_matchpairs") " {{{
|
||||||
if s:ValidMatchpairs(&matchpairs) == 1
|
if s:ValidMatchpairs(&matchpairs) == 1
|
||||||
let s:matchpairs_temp = &matchpairs
|
let s:matchpairs_temp = &matchpairs
|
||||||
else
|
else
|
||||||
echoerr "delimitMate: There seems to be a problem with 'matchpairs', read ':help matchpairs' and fix it or notify the maintainer of this script if this is a bug."
|
echoerr "delimitMate: There seems to be a problem with 'matchpairs', read ':help matchpairs' and fix it or notify the maintainer of this script if this is a bug."
|
||||||
finish
|
finish
|
||||||
endif
|
endif
|
||||||
else
|
elseif exists("b:delimitMate_matchpairs")
|
||||||
if s:ValidMatchpairs(b:delimitMate_matchpairs) || b:delimitMate_matchpairs == ""
|
if s:ValidMatchpairs(b:delimitMate_matchpairs) || b:delimitMate_matchpairs == ""
|
||||||
let s:matchpairs_temp = b:delimitMate_matchpairs
|
let s:matchpairs_temp = b:delimitMate_matchpairs
|
||||||
else
|
else
|
||||||
@@ -63,51 +66,93 @@ function! s:Init() "{{{1
|
|||||||
let s:matchpairs_temp = ""
|
let s:matchpairs_temp = ""
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
endif
|
else
|
||||||
|
if s:ValidMatchpairs(g:delimitMate_matchpairs) || g:delimitMate_matchpairs == ""
|
||||||
|
let s:matchpairs_temp = g:delimitMate_matchpairs
|
||||||
|
else
|
||||||
|
echoerr "delimitMate: Invalid format in 'g:delimitMate_matchpairs', falling back to matchpairs. Fix the error and use the command :DelimitMateReload to try again."
|
||||||
|
if s:ValidMatchpairs(&matchpairs) == 1
|
||||||
|
let s:matchpairs_temp = &matchpairs
|
||||||
|
else
|
||||||
|
echoerr "delimitMate: There seems to be a problem with 'matchpairs', read ':help matchpairs' and fix it or notify the maintainer of this script if this is a bug."
|
||||||
|
let s:matchpairs_temp = ""
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
if exists("b:delimitMate_quotes")
|
endif " }}}
|
||||||
|
|
||||||
|
if exists("b:delimitMate_quotes") " {{{
|
||||||
if b:delimitMate_quotes =~ '^\(\S\)\(\s\S\)*$' || b:delimitMate_quotes == ""
|
if b:delimitMate_quotes =~ '^\(\S\)\(\s\S\)*$' || b:delimitMate_quotes == ""
|
||||||
let s:quotes = split(b:delimitMate_quotes)
|
let s:quotes = split(b:delimitMate_quotes)
|
||||||
else
|
else
|
||||||
let s:quotes = split("\" ' `")
|
let s:quotes = split("\" ' `")
|
||||||
echoerr "delimitMate: There is a problem with the format of 'b:delimitMate_quotes', it should be a string of single characters separated by spaces. Falling back to default values."
|
echoerr "delimitMate: There is a problem with the format of 'b:delimitMate_quotes', it should be a string of single characters separated by spaces. Falling back to default values."
|
||||||
endif
|
endif
|
||||||
|
elseif exists("g:delimitMate_quotes")
|
||||||
|
if g:delimitMate_quotes =~ '^\(\S\)\(\s\S\)*$' || g:delimitMate_quotes == ""
|
||||||
|
let s:quotes = split(g:delimitMate_quotes)
|
||||||
|
else
|
||||||
|
let s:quotes = split("\" ' `")
|
||||||
|
echoerr "delimitMate: There is a problem with the format of 'g:delimitMate_quotes', it should be a string of single characters separated by spaces. Falling back to default values."
|
||||||
|
endif
|
||||||
else
|
else
|
||||||
let s:quotes = split("\" ' `")
|
let s:quotes = split("\" ' `")
|
||||||
endif
|
endif " }}}
|
||||||
|
|
||||||
if !exists("g:delimitMate_visual_leader")
|
if !exists("b:delimitMate_visual_leader") && !exists("g:delimitMate_visual_leader") " {{{
|
||||||
if !exists("g:mapleader")
|
if !exists("g:mapleader")
|
||||||
let s:visual_leader = "\\"
|
let s:visual_leader = "\\"
|
||||||
else
|
else
|
||||||
let s:visual_leader = g:mapleader
|
let s:visual_leader = g:mapleader
|
||||||
endif
|
endif
|
||||||
|
elseif exists("b:delimitMate_visual_leader")
|
||||||
|
let s:visual_leader = b:delimitMate_visual_leader
|
||||||
else
|
else
|
||||||
let s:visual_leader = g:delimitMate_visual_leader
|
let s:visual_leader = g:delimitMate_visual_leader
|
||||||
endif
|
endif " }}}
|
||||||
|
|
||||||
if !exists("b:delimitMate_expand_space")
|
if !exists("b:delimitMate_expand_space") && !exists("g:delimitMate_expand_space") " {{{
|
||||||
let s:expand_space = "\<Space>"
|
let s:expand_space = "\<Space>"
|
||||||
elseif b:delimitMate_expand_space == ""
|
elseif b:delimitMate_expand_space == ""
|
||||||
let s:expand_space = "\<Space>"
|
let s:expand_space = "\<Space>"
|
||||||
else
|
elseif exists("b:delimitMate_expand_space")
|
||||||
let s:expand_space = b:delimitMate_expand_space
|
let s:expand_space = b:delimitMate_expand_space
|
||||||
endif
|
|
||||||
|
|
||||||
if !exists("b:delimitMate_expand_cr")
|
|
||||||
let s:expand_return = "\<CR>"
|
|
||||||
elseif b:delimitMate_expand_cr == ""
|
|
||||||
let s:expand_return = "\<CR>"
|
|
||||||
else
|
else
|
||||||
let s:expand_return = b:delimitMate_expand_cr
|
let s:expand_space = g:delimitMate_expand_space
|
||||||
endif
|
endif " }}}
|
||||||
|
|
||||||
|
if !exists("b:delimitMate_expand_cr") && !exists("g:delimitMate_expand_cr") " {{{
|
||||||
|
let s:expand_return = "\<CR>"
|
||||||
|
elseif exists("b:delimitMate_expand_cr")
|
||||||
|
if b:delimitMate_expand_cr == ""
|
||||||
|
let s:expand_return = "\<CR>"
|
||||||
|
else
|
||||||
|
let s:expand_return = b:delimitMate_expand_cr
|
||||||
|
endif
|
||||||
|
else
|
||||||
|
if g:delimitMate_expand_cr == ""
|
||||||
|
let s:expand_return = "\<CR>"
|
||||||
|
else
|
||||||
|
let s:expand_return = g:delimitMate_expand_cr
|
||||||
|
endif
|
||||||
|
|
||||||
|
endif " }}}
|
||||||
|
|
||||||
let s:matchpairs = split(s:matchpairs_temp, ',')
|
let s:matchpairs = split(s:matchpairs_temp, ',')
|
||||||
let s:left_delims = split(s:matchpairs_temp, ':.,\=')
|
let s:left_delims = split(s:matchpairs_temp, ':.,\=')
|
||||||
let s:right_delims = split(s:matchpairs_temp, ',\=.:')
|
let s:right_delims = split(s:matchpairs_temp, ',\=.:')
|
||||||
let s:VMapMsg = "delimitMate: delimitMate is disabled on blockwise visual mode."
|
let s:VMapMsg = "delimitMate: delimitMate is disabled on blockwise visual mode."
|
||||||
|
|
||||||
endfunction
|
call s:ResetMappings()
|
||||||
|
if s:autoclose
|
||||||
|
call s:AutoClose()
|
||||||
|
else
|
||||||
|
call s:NoAutoClose()
|
||||||
|
endif
|
||||||
|
call s:ExtraMappings()
|
||||||
|
let b:loaded_delimitMate = 1
|
||||||
|
|
||||||
|
endfunction "}}}1
|
||||||
|
|
||||||
function! s:ValidMatchpairs(str) "{{{1
|
function! s:ValidMatchpairs(str) "{{{1
|
||||||
if a:str !~ '^\(.:.\)\+\(,.:.\)*$'
|
if a:str !~ '^\(.:.\)\+\(,.:.\)*$'
|
||||||
@@ -119,7 +164,7 @@ function! s:ValidMatchpairs(str) "{{{1
|
|||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
return 1
|
return 1
|
||||||
endfunc
|
endfunction "}}}1
|
||||||
|
|
||||||
function! s:IsEmptyPair(str) "{{{1
|
function! s:IsEmptyPair(str) "{{{1
|
||||||
for pair in s:matchpairs
|
for pair in s:matchpairs
|
||||||
@@ -133,12 +178,12 @@ function! s:IsEmptyPair(str) "{{{1
|
|||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
return 0
|
return 0
|
||||||
endfunc
|
endfunction "}}}1
|
||||||
|
|
||||||
function! s:WithinEmptyPair() "{{{1
|
function! s:WithinEmptyPair() "{{{1
|
||||||
let cur = strpart( getline('.'), col('.')-2, 2 )
|
let cur = strpart( getline('.'), col('.')-2, 2 )
|
||||||
return s:IsEmptyPair( cur )
|
return s:IsEmptyPair( cur )
|
||||||
endfunc
|
endfunction "}}}1
|
||||||
|
|
||||||
function! s:SkipDelim(char) "{{{1
|
function! s:SkipDelim(char) "{{{1
|
||||||
let cur = strpart( getline('.'), col('.')-2, 3 )
|
let cur = strpart( getline('.'), col('.')-2, 3 )
|
||||||
@@ -154,7 +199,7 @@ function! s:SkipDelim(char) "{{{1
|
|||||||
else
|
else
|
||||||
return a:char
|
return a:char
|
||||||
endif
|
endif
|
||||||
endfunc
|
endfunction "}}}1
|
||||||
|
|
||||||
function! s:QuoteDelim(char) "{{{1
|
function! s:QuoteDelim(char) "{{{1
|
||||||
let line = getline('.')
|
let line = getline('.')
|
||||||
@@ -169,7 +214,7 @@ function! s:QuoteDelim(char) "{{{1
|
|||||||
"Starting a string
|
"Starting a string
|
||||||
return a:char.a:char."\<Left>"
|
return a:char.a:char."\<Left>"
|
||||||
endif
|
endif
|
||||||
endf
|
endfunction "}}}1
|
||||||
|
|
||||||
function! s:ClosePair(char) "{{{1
|
function! s:ClosePair(char) "{{{1
|
||||||
if getline('.')[col('.') - 1] == a:char
|
if getline('.')[col('.') - 1] == a:char
|
||||||
@@ -177,7 +222,7 @@ function! s:ClosePair(char) "{{{1
|
|||||||
else
|
else
|
||||||
return a:char
|
return a:char
|
||||||
endif
|
endif
|
||||||
endf
|
endfunction "}}}1
|
||||||
|
|
||||||
function! s:ResetMappings() "{{{1
|
function! s:ResetMappings() "{{{1
|
||||||
for delim in s:right_delims + s:left_delims + s:quotes
|
for delim in s:right_delims + s:left_delims + s:quotes
|
||||||
@@ -186,77 +231,99 @@ function! s:ResetMappings() "{{{1
|
|||||||
endfor
|
endfor
|
||||||
silent! iunmap <buffer> <CR>
|
silent! iunmap <buffer> <CR>
|
||||||
silent! iunmap <buffer> <Space>
|
silent! iunmap <buffer> <Space>
|
||||||
endfunction
|
endfunction "}}}1
|
||||||
|
|
||||||
function! s:MapMsg(msg) "{{{1
|
function! s:MapMsg(msg) "{{{1
|
||||||
redraw
|
redraw
|
||||||
echomsg a:msg
|
echomsg a:msg
|
||||||
return ""
|
return ""
|
||||||
endfunction
|
endfunction "}}}1
|
||||||
|
|
||||||
function! s:NoAutoClose() "{{{1
|
function! s:NoAutoClose() "{{{1
|
||||||
" imap <buffer> ) <C-R>=<SID>SkipDelim('\)')<CR>
|
" inoremap <buffer> ) <C-R>=<SID>SkipDelim('\)')<CR>
|
||||||
for delim in s:right_delims + s:quotes
|
for delim in s:right_delims + s:quotes
|
||||||
exec 'imap <buffer> ' . delim . ' <C-R>=<SID>SkipDelim("' . escape(delim,'"') . '")<CR>'
|
exec 'inoremap <buffer> ' . delim . ' <C-R>=<SID>SkipDelim("' . escape(delim,'"') . '")<CR>'
|
||||||
endfor
|
|
||||||
|
|
||||||
" Wrap the selection with delimiters, but do nothing if blockwise visual mode is active:
|
|
||||||
for i in range(len(s:matchpairs))
|
|
||||||
" Map left delimiter:
|
|
||||||
" vmap <buffer> <expr> q( visualmode() == "<C-V>" ? <SID>MapMsg(VMapMsg) : "s(\<C-R>\")\<Esc>"
|
|
||||||
exec 'vmap <buffer> <expr> ' . s:visual_leader . s:left_delims[i] . ' visualmode() == "<C-V>" ? <SID>MapMsg("' . s:VMapMsg . '") : "s' . s:left_delims[i] . '\<C-R>\"' . s:right_delims[i] . '\<Esc>"'
|
|
||||||
|
|
||||||
" Map right delimiter:
|
|
||||||
" vmap <buffer> <expr> q) visualmode() == "<C-V>" ? <SID>MapMsg(VMapMsg) : "s(\<C-R>\")\<Esc>"
|
|
||||||
exec 'vmap <buffer> <expr> ' . s:visual_leader . s:right_delims[i] . ' visualmode() == "<C-V>" ? <SID>MapMsg("' . s:VMapMsg . '") : "s' . s:left_delims[i] . '\<C-R>\"' . s:right_delims[i] . '"'
|
|
||||||
endfor
|
|
||||||
|
|
||||||
for quote in s:quotes
|
|
||||||
" vmap <buffer> <expr> q" visualmode() == "<C-V>" ? <SID>MapMsg(VMapMsg) : "s'\<C-R>\"'\<Esc>"
|
|
||||||
exec 'vmap <buffer> <expr> ' . s:visual_leader . quote . ' visualmode() == "<C-V>" ? <SID>MapMsg("' . s:VMapMsg . '") : "s' . escape(quote,'"') . '\<C-R>\"' . escape(quote,'"') . '\<Esc>"'
|
|
||||||
endfor
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! s:AutoClose() "{{{1
|
|
||||||
" Add matching pair and jump to the midle:
|
|
||||||
" imap <buffer> ( ()<Left>
|
|
||||||
let s:i = 0
|
|
||||||
while s:i < len(s:matchpairs)
|
|
||||||
exec 'imap <buffer> ' . s:left_delims[s:i] . ' ' . s:left_delims[s:i] . '_<Left>' . s:right_delims[s:i] . '<Del><Left>'
|
|
||||||
let s:i += 1
|
|
||||||
endwhile
|
|
||||||
|
|
||||||
" Add matching quote and jump to the midle, or exit if inside a pair of matching quotes:
|
|
||||||
" imap <buffer> " <C-R>=<SID>QuoteDelim("\"")<CR>
|
|
||||||
for delim in s:quotes
|
|
||||||
exec 'imap <buffer> ' . delim . ' <C-R>=<SID>QuoteDelim("\' . delim . '")<CR>'
|
|
||||||
endfor
|
|
||||||
|
|
||||||
" Exit from inside the matching pair:
|
|
||||||
" imap <buffer> ) <C-R>=<SID>ClosePair(')')<CR>
|
|
||||||
for delim in s:right_delims
|
|
||||||
exec 'imap <buffer> ' . delim . ' <C-R>=<SID>ClosePair("\' . delim . '")<CR>'
|
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
" Wrap the selection with matching pairs, but do nothing if blockwise visual mode is active:
|
" Wrap the selection with matching pairs, but do nothing if blockwise visual mode is active:
|
||||||
let s:i = 0
|
let s:i = 0
|
||||||
while s:i < len(s:matchpairs)
|
while s:i < len(s:matchpairs)
|
||||||
" Map left delimiter:
|
" Map left delimiter:
|
||||||
" vmap <buffer> <expr> q( visualmode() == "<C-V>" ? <SID>MapMsg("Message") : "s(\<C-R>\"\<Esc>"
|
" vnoremap <buffer> <expr> q( visualmode() == "<C-V>" ? <SID>MapMsg("Message") : "s(\<C-R>\"\<Esc>"
|
||||||
exec 'vmap <buffer> <expr> ' . s:visual_leader . s:left_delims[s:i] . ' visualmode() == "<C-V>" ? <SID>MapMsg("' . s:VMapMsg . '") : "s' . s:left_delims[s:i] . '\<C-R>\"\<Esc>"'
|
exec 'vnoremap <buffer> <expr> ' . s:visual_leader . s:left_delims[s:i] . ' <SID>IsBlockVisual() ? <SID>MapMsg("' . s:VMapMsg . '") : "s' . s:left_delims[s:i] . '\<C-R>\"' . s:right_delims[s:i] . '\<Esc>:call <SID>RestoreRegister()<CR>"'
|
||||||
|
|
||||||
" Map right delimiter:
|
" Map right delimiter:
|
||||||
" vmap <buffer> <expr> q) visualmode() == "<C-V>" ? <SID>MapMsg("Message") : "s(\<C-R>\""\<Esc>"
|
" vnoremap <buffer> <expr> q) visualmode() == "<C-V>" ? <SID>MapMsg("Message") : "s(\<C-R>\""\<Esc>"
|
||||||
exec 'vmap <buffer> <expr> ' . s:visual_leader . s:right_delims[s:i] . ' visualmode() == "<C-V>" ? <SID>MapMsg("' . s:VMapMsg . '") : "s' . s:left_delims[s:i] . '\<C-R>\""'
|
exec 'vnoremap <buffer> <expr> ' . s:visual_leader . s:right_delims[s:i] . ' <SID>IsBlockVisual() ? <SID>MapMsg("' . s:VMapMsg . '") : "s' . s:left_delims[s:i] . '\<C-R>\"' . s:right_delims[s:i] . '\<Esc>:call <SID>RestoreRegister()<CR>"'
|
||||||
let s:i += 1
|
let s:i += 1
|
||||||
endwhile
|
endwhile
|
||||||
|
|
||||||
" Wrap the selection with matching quotes, but do nothing if blockwise visual mode is active:
|
" Wrap the selection with matching quotes, but do nothing if blockwise visual mode is active:
|
||||||
for quote in s:quotes
|
for quote in s:quotes
|
||||||
" vmap <buffer> <expr> q' visualmode() == "<C-V>" ? <SID>MapMsg("Message") : "s'\<C-R>\"'\<Esc>"
|
" vnoremap <buffer> <expr> q' visualmode() == "<C-V>" ? <SID>MapMsg("Message") : "s'\<C-R>\"'\<Esc>"
|
||||||
exec 'vmap <buffer> <expr> ' . s:visual_leader . quote . ' visualmode() == "<C-V>" ? <SID>MapMsg("' . s:VMapMsg . '") : "s' . escape(quote,'"') .'\<C-R>\"' . escape(quote,'"') . '\<Esc>"'
|
exec 'vnoremap <buffer> <expr> ' . s:visual_leader . quote . ' <SID>IsBlockVisual() ? <SID>MapMsg("' . s:VMapMsg . '") : "s' . escape(quote,'"') .'\<C-R>\"' . escape(quote,'"') . '\<Esc>:call <SID>RestoreRegister()<CR>"'
|
||||||
endfor
|
endfor
|
||||||
endfunction
|
endfunction "}}}1
|
||||||
|
|
||||||
|
function! s:AutoClose() "{{{1
|
||||||
|
" Add matching pair and jump to the midle:
|
||||||
|
" inoremap <buffer> ( ()<Left>
|
||||||
|
let s:i = 0
|
||||||
|
while s:i < len(s:matchpairs)
|
||||||
|
exec 'inoremap <buffer> ' . s:left_delims[s:i] . ' ' . s:left_delims[s:i] . s:right_delims[s:i] . '<Left>'
|
||||||
|
let s:i += 1
|
||||||
|
endwhile
|
||||||
|
|
||||||
|
" Add matching quote and jump to the midle, or exit if inside a pair of matching quotes:
|
||||||
|
" inoremap <buffer> " <C-R>=<SID>QuoteDelim("\"")<CR>
|
||||||
|
for delim in s:quotes
|
||||||
|
exec 'inoremap <buffer> ' . delim . ' <C-R>=<SID>QuoteDelim("\' . delim . '")<CR>'
|
||||||
|
endfor
|
||||||
|
|
||||||
|
" Exit from inside the matching pair:
|
||||||
|
" inoremap <buffer> ) <C-R>=<SID>ClosePair(')')<CR>
|
||||||
|
for delim in s:right_delims
|
||||||
|
exec 'inoremap <buffer> ' . delim . ' <C-R>=<SID>ClosePair("\' . delim . '")<CR>'
|
||||||
|
endfor
|
||||||
|
|
||||||
|
" Wrap the selection with matching pairs, but do nothing if blockwise visual mode is active:
|
||||||
|
let s:i = 0
|
||||||
|
while s:i < len(s:matchpairs)
|
||||||
|
" Map left delimiter:
|
||||||
|
" vnoremap <buffer> <expr> q( visualmode() == "<C-V>" ? <SID>MapMsg("Message") : "s(\<C-R>\"\<Esc>"
|
||||||
|
exec 'vnoremap <buffer> <expr> ' . s:visual_leader . s:left_delims[s:i] . ' <SID>IsBlockVisual() ? <SID>MapMsg("' . s:VMapMsg . '") : "s' . s:left_delims[s:i] . '\<C-R>\"' . s:right_delims[s:i] . '\<Esc>:call <SID>RestoreRegister()<CR>"'
|
||||||
|
|
||||||
|
" Map right delimiter:
|
||||||
|
" vnoremap <buffer> <expr> q) visualmode() == "<C-V>" ? <SID>MapMsg("Message") : "s(\<C-R>\""\<Esc>"
|
||||||
|
exec 'vnoremap <buffer> <expr> ' . s:visual_leader . s:right_delims[s:i] . ' <SID>IsBlockVisual() ? <SID>MapMsg("' . s:VMapMsg . '") : "s' . s:left_delims[s:i] . '\<C-R>\"' . s:right_delims[s:i] . '\<Esc>:call <SID>RestoreRegister()<CR>"'
|
||||||
|
let s:i += 1
|
||||||
|
endwhile
|
||||||
|
|
||||||
|
" Wrap the selection with matching quotes, but do nothing if blockwise visual mode is active:
|
||||||
|
for quote in s:quotes
|
||||||
|
" vnoremap <buffer> <expr> q' visualmode() == "<C-V>" ? <SID>MapMsg("Message") : "s'\<C-R>\"'\<Esc>"
|
||||||
|
exec 'vnoremap <buffer> <expr> ' . s:visual_leader . quote . ' <SID>IsBlockVisual() ? <SID>MapMsg("' . s:VMapMsg . '") : "s' . escape(quote,'"') .'\<C-R>\"' . escape(quote,'"') . '\<Esc>:call <SID>RestoreRegister()<CR>"'
|
||||||
|
endfor
|
||||||
|
endfunction "}}}1
|
||||||
|
|
||||||
|
function! s:IsBlockVisual() " {{{1
|
||||||
|
if visualmode() == "<C-V>"
|
||||||
|
return 1
|
||||||
|
endif
|
||||||
|
let s:save_reg = getreg('"')
|
||||||
|
echomsg s:save_reg
|
||||||
|
let s:save_reg_mode = getregtype('"')
|
||||||
|
echomsg s:save_reg_mode
|
||||||
|
if len(getline('.')) == 0
|
||||||
|
let @" = "\n"
|
||||||
|
endif
|
||||||
|
return 0
|
||||||
|
endfunction " }}}1
|
||||||
|
|
||||||
|
function! s:RestoreRegister() " {{{1
|
||||||
|
call setreg('"', s:save_reg, s:save_reg_mode)
|
||||||
|
echo ""
|
||||||
|
endfunction " }}}1
|
||||||
|
|
||||||
function! s:ExpandReturn() "{{{1
|
function! s:ExpandReturn() "{{{1
|
||||||
if s:WithinEmptyPair()
|
if s:WithinEmptyPair()
|
||||||
@@ -264,7 +331,7 @@ function! s:ExpandReturn() "{{{1
|
|||||||
else
|
else
|
||||||
return "\<CR>"
|
return "\<CR>"
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction "}}}1
|
||||||
|
|
||||||
function! s:ExpandSpace() "{{{1
|
function! s:ExpandSpace() "{{{1
|
||||||
if s:WithinEmptyPair()
|
if s:WithinEmptyPair()
|
||||||
@@ -272,18 +339,18 @@ function! s:ExpandSpace() "{{{1
|
|||||||
else
|
else
|
||||||
return "\<Space>"
|
return "\<Space>"
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction "}}}1
|
||||||
|
|
||||||
function! s:ExtraMappings() "{{{1
|
function! s:ExtraMappings() "{{{1
|
||||||
" If pair is empty, delete both delimiters:
|
" If pair is empty, delete both delimiters:
|
||||||
imap <buffer> <expr> <BS> <SID>WithinEmptyPair() ? "\<Left>\<Del>\<Del>" : "\<BS>"
|
inoremap <buffer> <expr> <BS> <SID>WithinEmptyPair() ? "<Right><BS><BS>" : "\<BS>"
|
||||||
|
|
||||||
" Expand return if inside an empty pair:
|
" Expand return if inside an empty pair:
|
||||||
imap <buffer> <CR> <C-R>=<SID>ExpandReturn()<CR>
|
inoremap <buffer> <CR> <C-R>=<SID>ExpandReturn()<CR>
|
||||||
|
|
||||||
" Expand space if inside an empty pair:
|
" Expand space if inside an empty pair:
|
||||||
imap <buffer> <Space> <C-R>=<SID>ExpandSpace()<CR>
|
inoremap <buffer> <Space> <C-R>=<SID>ExpandSpace()<CR>
|
||||||
endfunction
|
endfunction "}}}1
|
||||||
|
|
||||||
function! s:TestMappings() "{{{1
|
function! s:TestMappings() "{{{1
|
||||||
if s:autoclose
|
if s:autoclose
|
||||||
@@ -326,7 +393,7 @@ function! s:TestMappings() "{{{1
|
|||||||
endfor
|
endfor
|
||||||
endif
|
endif
|
||||||
exec "normal \<Esc>"
|
exec "normal \<Esc>"
|
||||||
endfunction
|
endfunction "}}}1
|
||||||
|
|
||||||
function! s:SwitchAutoclose() "{{{1
|
function! s:SwitchAutoclose() "{{{1
|
||||||
if !exists("g:delimitMate_autoclose")
|
if !exists("g:delimitMate_autoclose")
|
||||||
@@ -337,7 +404,7 @@ function! s:SwitchAutoclose() "{{{1
|
|||||||
let g:delimitMate_autoclose = 1
|
let g:delimitMate_autoclose = 1
|
||||||
endif
|
endif
|
||||||
DelimitMateReload
|
DelimitMateReload
|
||||||
endfunction
|
endfunction "}}}1
|
||||||
|
|
||||||
function! s:TestMappingsDo() "{{{1
|
function! s:TestMappingsDo() "{{{1
|
||||||
if !exists("g:delimitMate_testing")
|
if !exists("g:delimitMate_testing")
|
||||||
@@ -350,28 +417,29 @@ function! s:TestMappingsDo() "{{{1
|
|||||||
call s:SwitchAutoclose()
|
call s:SwitchAutoclose()
|
||||||
call s:TestMappings()
|
call s:TestMappings()
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction "}}}1
|
||||||
|
|
||||||
function! s:DelimitMateDo() "{{{1
|
function! s:DelimitMateDo() "{{{1
|
||||||
|
if exists("g:delimitMate_excluded_ft")
|
||||||
|
for ft in split(g:delimitMate_excluded_ft,',')
|
||||||
|
if ft ==? &filetype
|
||||||
|
echomsg "Excluded"
|
||||||
|
return 1
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
endif
|
||||||
try
|
try
|
||||||
let s:save_cpo = &cpo
|
let save_cpo = &cpo
|
||||||
set cpo&vim
|
set cpo&vim
|
||||||
call s:Init()
|
call s:Init()
|
||||||
call s:ResetMappings()
|
|
||||||
if s:autoclose
|
|
||||||
call s:AutoClose()
|
|
||||||
else
|
|
||||||
call s:NoAutoClose()
|
|
||||||
endif
|
|
||||||
call s:ExtraMappings()
|
|
||||||
let b:loaded_delimitMate = 1
|
|
||||||
finally
|
finally
|
||||||
let &cpo = s:save_cpo
|
let &cpo = save_cpo
|
||||||
endtry
|
endtry
|
||||||
endfunction
|
let &cpo = save_cpo
|
||||||
|
endfunction "}}}1
|
||||||
|
|
||||||
" Do the real work: {{{1
|
" Do the real work: {{{1
|
||||||
call s:DelimitMateDo()
|
"call s:DelimitMateDo()
|
||||||
|
|
||||||
" Let me refresh without re-loading the buffer:
|
" Let me refresh without re-loading the buffer:
|
||||||
command! DelimitMateReload call s:DelimitMateDo()
|
command! DelimitMateReload call s:DelimitMateDo()
|
||||||
@@ -379,7 +447,8 @@ command! DelimitMateReload call s:DelimitMateDo()
|
|||||||
" Quick test:
|
" Quick test:
|
||||||
command! DelimitMateTest call s:TestMappingsDo()
|
command! DelimitMateTest call s:TestMappingsDo()
|
||||||
|
|
||||||
autocmd BufNewFile,BufRead,BufEnter * if !exists("b:loaded_delimitMate") | call <SID>DelimitMateDo() | endif
|
"autocmd BufNewFile,BufRead,BufEnter * if !exists("b:loaded_delimitMate") || &filetype !=? "mailapp" | call <SID>DelimitMateDo() | endif
|
||||||
|
autocmd VimEnter * autocmd FileType * if !exists("b:loaded_delimitMate") | call <SID>DelimitMateDo() | endif
|
||||||
|
|
||||||
" GetLatestVimScripts: 2754 1 :AutoInstall: delimitMate.vim
|
" GetLatestVimScripts: 2754 1 :AutoInstall: delimitMate.vim
|
||||||
" vim:foldmethod=marker:foldcolumn=2
|
" vim:foldmethod=marker:foldcolumn=2
|
||||||
|
|||||||
Reference in New Issue
Block a user