New Feature: Fly Mode
This commit is contained in:
parent
b6a478f891
commit
331060ff4b
56
README.md
56
README.md
@ -78,6 +78,47 @@ Features
|
|||||||
output:
|
output:
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
* Fly Mode
|
||||||
|
|
||||||
|
input: if(a[3)
|
||||||
|
output: if(a[3])| (In Fly Mode)
|
||||||
|
output: if(a[3)]) (Without Fly Mode)
|
||||||
|
|
||||||
|
input:
|
||||||
|
{
|
||||||
|
hello();|
|
||||||
|
world();
|
||||||
|
}
|
||||||
|
|
||||||
|
(press } at |)
|
||||||
|
|
||||||
|
output:
|
||||||
|
{
|
||||||
|
hello();
|
||||||
|
world();
|
||||||
|
}|
|
||||||
|
|
||||||
|
(then press <M-b> at | to do backinsert)
|
||||||
|
output:
|
||||||
|
{
|
||||||
|
hello();}|
|
||||||
|
world();
|
||||||
|
}
|
||||||
|
|
||||||
|
See Fly Mode section for details
|
||||||
|
|
||||||
|
Fly Mode
|
||||||
|
--------
|
||||||
|
|
||||||
|
Fly Mode will always force closed-pair jumping instead of inserting. only for ")", "}", "]"
|
||||||
|
If jumps in mistake, could use AutoPairsBackInsert(Default Key: <M-b>) to jump back and insert closed pair.
|
||||||
|
the most situation maybe want to insert single closed pair in the string, eg ")"
|
||||||
|
|
||||||
|
Default Options:
|
||||||
|
|
||||||
|
let g:AutoPairs_FlyMode = 1
|
||||||
|
let g:AutoPairsShortcutBackInsert = '<M-b>'
|
||||||
|
|
||||||
Shortcuts
|
Shortcuts
|
||||||
---------
|
---------
|
||||||
|
|
||||||
@ -87,10 +128,11 @@ Shortcuts
|
|||||||
<M-p> : Toggle Autopairs (g:AutoPairsShortcutToggle)
|
<M-p> : Toggle Autopairs (g:AutoPairsShortcutToggle)
|
||||||
<M-e> : Fast Wrap (g:AutoPairsShortcutFastWrap)
|
<M-e> : Fast Wrap (g:AutoPairsShortcutFastWrap)
|
||||||
<M-n> : Jump to next closed pair (g:AutoPairsShortcutJump)
|
<M-n> : Jump to next closed pair (g:AutoPairsShortcutJump)
|
||||||
|
<M-b> : BackInsert
|
||||||
|
|
||||||
If <M-p> <M-e> or <M-n> conflict with another keys or want to bind to another keys, add
|
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>'
|
let g:AutoPairShortcutToggle = '<another key>'
|
||||||
|
|
||||||
to .vimrc, it the key is empty string '', then the shortcut will be disabled.
|
to .vimrc, it the key is empty string '', then the shortcut will be disabled.
|
||||||
|
|
||||||
@ -147,6 +189,18 @@ Options
|
|||||||
Map <space> to insert a space after the opening character and before the closing one.
|
Map <space> to insert a space after the opening character and before the closing one.
|
||||||
execute 'inoremap <buffer> <silent> <CR> <C-R>=AutoPairsSpace()<CR>'
|
execute 'inoremap <buffer> <silent> <CR> <C-R>=AutoPairsSpace()<CR>'
|
||||||
|
|
||||||
|
* g:AutoPairsFlyMode
|
||||||
|
|
||||||
|
Default : 1
|
||||||
|
|
||||||
|
see FlyMode section for details.
|
||||||
|
|
||||||
|
* g:AutoPairsShortcutBackInsert
|
||||||
|
|
||||||
|
Default : <M-b>
|
||||||
|
|
||||||
|
Work with FlyMode, insert the key at the Fly Mode jumped postion
|
||||||
|
|
||||||
TroubleShooting
|
TroubleShooting
|
||||||
---------------
|
---------------
|
||||||
The script will remap keys ([{'"}]) <BS>,
|
The script will remap keys ([{'"}]) <BS>,
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
" Insert or delete brackets, parens, quotes in pairs.
|
" Insert or delete brackets, parens, quotes in pairs.
|
||||||
" Maintainer: JiangMiao <jiangfriend@gmail.com>
|
" Maintainer: JiangMiao <jiangfriend@gmail.com>
|
||||||
" Contributor: camthompson
|
" Contributor: camthompson
|
||||||
" Last Change: 2012-03-22
|
" Last Change: 2012-05-14
|
||||||
" Version: 1.1.6
|
" Version: 1.2.0
|
||||||
" Homepage: http://www.vim.org/scripts/script.php?script_id=3599
|
" Homepage: http://www.vim.org/scripts/script.php?script_id=3599
|
||||||
" Repository: https://github.com/jiangmiao/auto-pairs
|
" Repository: https://github.com/jiangmiao/auto-pairs
|
||||||
|
|
||||||
@ -11,14 +11,6 @@ if exists('g:AutoPairsLoaded') || &cp
|
|||||||
end
|
end
|
||||||
let g:AutoPairsLoaded = 1
|
let g:AutoPairsLoaded = 1
|
||||||
|
|
||||||
" Shortcurs for
|
|
||||||
" <M-o> newline with indetation
|
|
||||||
" <M-a> jump to of line
|
|
||||||
" <M-n> jmup to next pairs
|
|
||||||
if !exists('g:AutoPairsShortcuts')
|
|
||||||
let g:AutoPairsShortcuts = 1
|
|
||||||
end
|
|
||||||
|
|
||||||
if !exists('g:AutoPairs')
|
if !exists('g:AutoPairs')
|
||||||
let g:AutoPairs = {'(':')', '[':']', '{':'}',"'":"'",'"':'"', '`':'`'}
|
let g:AutoPairs = {'(':')', '[':']', '{':'}',"'":"'",'"':'"', '`':'`'}
|
||||||
end
|
end
|
||||||
@ -58,8 +50,20 @@ if !exists('g:AutoPairsShortcutJump')
|
|||||||
let g:AutoPairsShortcutJump = '<M-n>'
|
let g:AutoPairsShortcutJump = '<M-n>'
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let g:AutoPairsClosedPairs = {}
|
" Fly mode will for closed pair to jump to closed pair instead of insert.
|
||||||
|
" also support AutoPairsBackInsert to insert pairs where jumped.
|
||||||
|
if !exists('g:AutoPairsFlyMode')
|
||||||
|
let g:AutoPairsFlyMode = 1
|
||||||
|
endif
|
||||||
|
|
||||||
|
" Work with Fly Mode, insert pair where jumped
|
||||||
|
if !exists('g:AutoPairsShortcutBackInsert')
|
||||||
|
let g:AutoPairsShortcutBackInsert = '<M-b>'
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
" Will auto generated {']' => 1, ..., '}' => 1}in initialize.
|
||||||
|
let g:AutoPairsClosedPairs = {}
|
||||||
|
|
||||||
|
|
||||||
function! AutoPairsInsert(key)
|
function! AutoPairsInsert(key)
|
||||||
@ -82,6 +86,7 @@ function! AutoPairsInsert(key)
|
|||||||
return a:key
|
return a:key
|
||||||
end
|
end
|
||||||
|
|
||||||
|
" The key is difference open-pair, then it means only for ) ] } by default
|
||||||
if !has_key(g:AutoPairs, a:key)
|
if !has_key(g:AutoPairs, a:key)
|
||||||
" Skip the character if next character is space
|
" Skip the character if next character is space
|
||||||
if current_char == ' ' && next_char == a:key
|
if current_char == ' ' && next_char == a:key
|
||||||
@ -103,6 +108,15 @@ function! AutoPairsInsert(key)
|
|||||||
return "\<Right>"
|
return "\<Right>"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
" Fly Mode, and the key is closed-pairs, search closed-pair and jump
|
||||||
|
if g:AutoPairsFlyMode && has_key(g:AutoPairsClosedPairs, a:key)
|
||||||
|
let b:autopairs_saved_pair = [a:key, getpos('.')]
|
||||||
|
" Use 's' flag to overwritee '' or not is a question
|
||||||
|
if(search(a:key, 'W'))
|
||||||
|
return "\<Right>"
|
||||||
|
end
|
||||||
|
endif
|
||||||
|
|
||||||
" Input directly if the key is not an open key
|
" Input directly if the key is not an open key
|
||||||
return a:key
|
return a:key
|
||||||
end
|
end
|
||||||
@ -181,7 +195,7 @@ function! AutoPairsFastWrap()
|
|||||||
end
|
end
|
||||||
|
|
||||||
normal! x
|
normal! x
|
||||||
if match(next_char, '\s') != -1
|
if next_char =~ '\s'
|
||||||
call search('\S', 'W')
|
call search('\S', 'W')
|
||||||
let next_char = getline('.')[col('.')-1]
|
let next_char = getline('.')[col('.')-1]
|
||||||
end
|
end
|
||||||
@ -191,7 +205,7 @@ function! AutoPairsFastWrap()
|
|||||||
call search(close, 'W')
|
call search(close, 'W')
|
||||||
return "\<RIGHT>".current_char."\<LEFT>"
|
return "\<RIGHT>".current_char."\<LEFT>"
|
||||||
else
|
else
|
||||||
if match(next_char, '\w') != -1
|
if next_char =~ '\w'
|
||||||
execute "normal! he"
|
execute "normal! he"
|
||||||
end
|
end
|
||||||
execute "normal! a".current_char
|
execute "normal! a".current_char
|
||||||
@ -228,7 +242,7 @@ function! AutoPairsReturn()
|
|||||||
" conflict with javascript and coffee
|
" conflict with javascript and coffee
|
||||||
" javascript need indent new line
|
" javascript need indent new line
|
||||||
" coffeescript forbid indent new line
|
" coffeescript forbid indent new line
|
||||||
if &filetype == 'coffeescript'
|
if &filetype == 'coffeescript' || &filetype == 'coffee'
|
||||||
return "\<ESC>k==o".cmd
|
return "\<ESC>k==o".cmd
|
||||||
else
|
else
|
||||||
return "\<ESC>=ko".cmd
|
return "\<ESC>=ko".cmd
|
||||||
@ -248,6 +262,16 @@ function! AutoPairsSpace()
|
|||||||
return "\<SPACE>".cmd
|
return "\<SPACE>".cmd
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! AutoPairsBackInsert()
|
||||||
|
if exists('b:autopairs_saved_pair')
|
||||||
|
let pair = b:autopairs_saved_pair[0]
|
||||||
|
let pos = b:autopairs_saved_pair[1]
|
||||||
|
call setpos('.', pos)
|
||||||
|
return pair
|
||||||
|
endif
|
||||||
|
return ''
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! AutoPairsInit()
|
function! AutoPairsInit()
|
||||||
let b:autopairs_loaded = 1
|
let b:autopairs_loaded = 1
|
||||||
let b:autopairs_enabled = 1
|
let b:autopairs_enabled = 1
|
||||||
@ -274,6 +298,10 @@ function! AutoPairsInit()
|
|||||||
execute 'inoremap <buffer> <silent> '.g:AutoPairsShortcutFastWrap.' <C-R>=AutoPairsFastWrap()<CR>'
|
execute 'inoremap <buffer> <silent> '.g:AutoPairsShortcutFastWrap.' <C-R>=AutoPairsFastWrap()<CR>'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if g:AutoPairsShortcutBackInsert != ''
|
||||||
|
execute 'inoremap <buffer> <silent> '.g:AutoPairsShortcutBackInsert.' <C-R>=AutoPairsBackInsert()<CR>'
|
||||||
|
end
|
||||||
|
|
||||||
if g:AutoPairsShortcutToggle != ''
|
if g:AutoPairsShortcutToggle != ''
|
||||||
" use <expr> to ensure showing the status when toggle
|
" use <expr> to ensure showing the status when toggle
|
||||||
execute 'inoremap <buffer> <silent> <expr> '.g:AutoPairsShortcutToggle.' AutoPairsToggle()'
|
execute 'inoremap <buffer> <silent> <expr> '.g:AutoPairsShortcutToggle.' AutoPairsToggle()'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user