auto closing parenthesis @vim conf2014
TRANSCRIPT
Auto-closing parenthesis2014/11/5 VimConf 2014
cohama / @c0hama
About mecohama❖ Twitter @c0hama
❖ from Nagoya➢ Nagoya.vim
❖ Agit.vim, the-ocamlspot.vim
❖ JavaScript, Haskell
Introduction
How many ) do we need to type?
reverse(range(1, winnr('$'
Introduction
How about } ?
while (true) { if (p == 1) { foo(); break;
Introduction❖ We need auto-closing.
reverse(range(1, winnr('$')))
while (true) { if (p == 1) { foo(); break;
}}
For example❖ Atom
For example❖ Sublime Text
For example❖ Eclipse
In Vim...
Table of Contents❖ Pure Vim way
❖ Some Plugins
❖ About lexima.vim
Table of Contents❖ Pure Vim way
❖ Some Plugins
❖ About lexima.vim
Pure Vim way
inoremap ( ()<Left>inoremap [ []<Left>inoremap " ""<Left>
Very easy but ...
Pure Vim way but ...
let w = winnr)
We need Plugin Power!
let leftparen = "()"
I'm'
let w = winnr())
Auto-closing requirementsBefore Input After
| ( (|)
(|) ) ()|
(|) <BS> |
I| 'm I'm|
syntax-specific rulesfiletype-specific rules
Table of Contents❖ Pure Vim way
❖ Some Plugins
❖ About lexima.vim
delimitMateRaimondi/delimitMate
❖ some useful features
❖ unable to dot-repeat
("foo|") ("foo")|<C-G>g
Unable to dot-repeat
"foo""bar"
A, "x"<Esc>
"foo, "x""bar"
Unable to dot-repeat
j.
"foo", "x""barx"
"foo, "x""bar"
vim-smartinputkana/vim-smartinput❖ highly customizable
❖ unable to dot-repeat
call smartinput#define_rule({\ 'at': '<\%#',\ 'char': '%',\ 'input': '% %><Left><Left><Left>'})
<% | %>%
<|
Table of Contents❖ Pure Vim way
❖ Some Plugins
❖ About lexima.vim
About lexima.vimcohama/lexima.vim
❖ highly customizable (inspired by vim-smartinput)
❖ dot-repeatable
❖ unstable
lexima.vim's rule definitioninspired by kana/vim-smartinput
compatible with vim-smartinput
call lexima#add_rule({\ 'at': '<\%#',\ 'char': '%',\ 'input': '% ',\ 'input_after': ' %>'})
<% | %>%
<|
lexima.vim's endwise-rule❖ inspired by tpope/vim-endwise
❖ Of course, dot-repeatable
def foo |end
<CR>def foo|
Mechanism
(|(|)(foo|)
In case of (foo<Esc>
(foo|(foo)|(foo|)
input (
call setline()
input foo
call setline()
input )
call setpos()
Demo
Thanks