summaryrefslogtreecommitdiff
path: root/config/nvim-2/nvim/vscript/scp.vim
diff options
context:
space:
mode:
Diffstat (limited to 'config/nvim-2/nvim/vscript/scp.vim')
-rw-r--r--config/nvim-2/nvim/vscript/scp.vim29
1 files changed, 29 insertions, 0 deletions
diff --git a/config/nvim-2/nvim/vscript/scp.vim b/config/nvim-2/nvim/vscript/scp.vim
new file mode 100644
index 0000000..6824c18
--- /dev/null
+++ b/config/nvim-2/nvim/vscript/scp.vim
@@ -0,0 +1,29 @@
+function! Sc(char)
+ let closing = {'(': ')', '[': ']', '{': '}', '<': '>', '"': '"', "'": "'"}
+
+ if has_key(closing, a:char)
+ let line = getline('.')
+ let col = col('.') - 1
+ let before = col > 0 ? line[col-1] : ''
+ let after = col < len(line) ? line[col] : ''
+ if before =~ '\w' && after =~ '\w'
+ return a:char
+ endif
+ if (a:char == '"' || a:char == "'") && before == a:char
+ return a:char
+ endif
+ if after == closing[a:char]
+ return "\<Right>"
+ endif
+ return a:char . closing[a:char] . "\<Left>"
+ endif
+
+ return a:char
+endfunction
+
+inoremap ( <C-R>=Sc('(')<CR>
+inoremap [ <C-R>=Sc('[')<CR>
+inoremap { <C-R>=Sc('{')<CR>
+inoremap < <C-R>=Sc('<')<CR>
+inoremap " <C-R>=Sc('"')<CR>
+inoremap ' <C-R>=Sc("'")<CR>