summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitmodules3
m---------vim/pack/plugins/start/autobrace0
-rw-r--r--vim/plugin/autobrace.vim141
-rw-r--r--vimrc1
4 files changed, 4 insertions, 141 deletions
diff --git a/.gitmodules b/.gitmodules
index 9d20cdf..deb421d 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -100,3 +100,6 @@
[submodule "vim/pack/plugins/start/diff-changes"]
path = vim/pack/plugins/start/diff-changes
url = git://github.com/doy/vim-diff-changes
+[submodule "vim/pack/plugins/start/autobrace"]
+ path = vim/pack/plugins/start/autobrace
+ url = git://github.com/doy/vim-autobrace
diff --git a/vim/pack/plugins/start/autobrace b/vim/pack/plugins/start/autobrace
new file mode 160000
+Subproject 0113c56e537e0ebf5e41fadcc9fb52cb3af8e04
diff --git a/vim/plugin/autobrace.vim b/vim/plugin/autobrace.vim
deleted file mode 100644
index 09ab06c..0000000
--- a/vim/plugin/autobrace.vim
+++ /dev/null
@@ -1,141 +0,0 @@
-let s:pair_chars = {
-\ '(': ')',
-\ '[': ']',
-\ '{': '}',
-\}
-let s:pair_cr_maps = {
-\ ')': "<SID>go_up()",
-\ ']': "<SID>go_up()",
-\ '}': "<SID>go_up()",
-\}
-let s:pair_bs_maps = {
-\ '"': "<SID>maybe_remove_adjacent_char('\"')",
-\ "'": "<SID>maybe_remove_adjacent_char(\"'\")",
-\ '(': "<SID>maybe_remove_empty_pair(')')",
-\ '[': "<SID>maybe_remove_empty_pair(']')",
-\ '{': "<SID>maybe_remove_empty_pair('}')",
-\ '': "<SID>maybe_collapse_pair()",
-\}
-
-function! s:move_cursor_left()
- return "\<Esc>i"
-endfunction
-
-function! s:skip_closing_char(char)
- if s:nextchar() == a:char
- return "\<Esc>la"
- else
- return a:char
- endif
-endfunction
-
-function! s:has_bs_mapping(char)
- return has_key(s:pair_bs_maps, a:char)
-endfunction
-
-function! s:run_bs_mapping(char)
- return eval(s:pair_bs_maps[a:char])
-endfunction
-
-function! s:has_cr_mapping(char)
- return has_key(s:pair_cr_maps, a:char)
-endfunction
-
-function! s:run_cr_mapping(char)
- return eval(s:pair_cr_maps[a:char])
-endfunction
-
-function! s:go_up()
- return "\<CR>\<Esc>O"
-endfunction
-
-function! s:maybe_remove_adjacent_char(char)
- if s:nextchar() == a:char
- return "\<BS>\<Del>"
- else
- return "\<BS>"
- endif
-endfunction
-
-function! s:maybe_remove_empty_pair(char)
- let l:start = [line('.'), col('.')]
- let l:end = searchpos('[^ \t]', 'cnWz')
- if l:end == [0, 0]
- return "\<BS>"
- endif
-
- let l:next_nonblank = s:charat(l:end[0], l:end[1])
- if l:next_nonblank != a:char
- return "\<BS>"
- endif
-
- let l:diff = [l:end[0] - l:start[0], l:end[1] - l:start[1]]
- if l:diff[0] == 0
- return "\<BS>" . repeat("\<Del>", l:diff[1] + 1)
- elseif l:diff[0] == 1
- return "\<Esc>" . (l:diff[0] + 1) . "Ji" . "\<BS>\<Del>"
- else
- return "\<Esc>" . (l:diff[0] + 1) . "Ji" . "\<BS>\<BS>\<Del>"
- endif
-endfunction
-
-function! s:maybe_collapse_pair()
- let l:prev_line_idx = line('.') - 1
- if l:prev_line_idx < 1
- return "\<BS>"
- endif
-
- let l:prev_line_char = s:charat(l:prev_line_idx, col([l:prev_line_idx, '$']) - 1)
- if l:prev_line_char !~ '[([{]'
- return "\<BS>"
- endif
-
- let l:end = searchpos('[^ \t]', 'cnWz')
- if l:end == [0, 0]
- return "\<BS>"
- endif
-
- let l:next_nonblank = s:charat(l:end[0], l:end[1])
- if l:next_nonblank != s:pair_chars[l:prev_line_char]
- return "\<BS>"
- endif
-
- return "\<Esc>\<BS>" . (l:end[0] - l:prev_line_idx + 1) . "Ji\<BS>"
-endfunction
-
-function! s:prevchar()
- return s:charat(line('.'), col('.') - 1)
-endfunction
-
-function! s:nextchar()
- return s:charat(line('.'), col('.'))
-endfunction
-
-function! s:charat(line, col)
- return getline(a:line)[a:col - 1]
-endfunction
-
-for [s:start, s:end] in [['(', ')'], ['{', '}'], ['[', ']']]
- exe "inoremap <silent> ".s:start.
- \ " ".s:start.s:end."<C-R>=<SID>move_cursor_left()<CR>"
- exe "inoremap <silent> ".s:end.
- \ " <C-R>=<SID>skip_closing_char('".s:end."')<CR>"
-endfor
-inoremap <silent><expr> '
- \ <SID>nextchar() == "'"
- \ ? "\<C-R>=\<SID>skip_closing_char(\"'\")\<CR>"
- \ : col('.') == 1 \|\| match(<SID>prevchar(), '\W') != -1
- \ ? "''\<C-R>=\<SID>move_cursor_left()\<CR>"
- \ : "'"
-inoremap <silent><expr> "
- \ <SID>nextchar() == '"'
- \ ? "\<C-R>=\<SID>skip_closing_char('\"')\<CR>"
- \ : "\"\"\<C-R>=\<SID>move_cursor_left()\<CR>"
-inoremap <silent><expr> <BS>
- \ <SID>has_bs_mapping(<SID>prevchar())
- \ ? "\<C-R>=\<SID>run_bs_mapping(\<SID>prevchar())\<CR>"
- \ : "\<BS>"
-inoremap <silent><expr> <CR>
- \ <SID>has_cr_mapping(<SID>nextchar())
- \ ? "\<C-R>=\<SID>run_cr_mapping(\<SID>nextchar())\<CR>"
- \ : "\<CR>"
diff --git a/vimrc b/vimrc
index 3ca23f1..fe01d12 100644
--- a/vimrc
+++ b/vimrc
@@ -67,6 +67,7 @@ let g:ale_history_enabled = 0
let g:ale_history_log_output = 0
" }}}
" airline
+" autobrace
" commentary {{{
map <silent><Leader>x :Commentary<CR>
" }}}