Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Auto-closing parenthesis 
2014/11/5 VimConf 2014 
cohama / @c0hama
About me 
cohama 
❖ Twitter @c0hama 
❖ from Nagoya 
➢ Nagoya.vim 
❖ Agit.vim, 
the-ocamlspot.vim 
❖ JavaScript, Haskell
Introduction 
reverse(range(1, winnr('$' 
How many ) do we need to type?
Introduction 
while (true) { 
if (p == 1) { 
foo(); 
break; 
How about } ?
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()) 
let w = winnr) 
let leftparen = "()" 
We need Plugin Power! 
I'm'
Auto-closing requirements 
Before Input After 
| ( (|) 
(|) ) ()| 
(|) <BS> | 
I| 'm I'm| 
syntax-specific rules 
filetype...
Table of Contents 
❖ Pure Vim way 
❖ Some Plugins 
❖ About lexima.vim
delimitMate 
Raimondi/delimitMate 
❖ some useful features 
<C-G>g 
("foo|") ("foo")| 
❖ unable to dot-repeat
Unable to dot-repeat 
"foo" 
"bar" 
A, "x"<Esc> 
"foo, "x" 
"bar"
Unable to dot-repeat 
j. 
"foo", "x" 
"barx" 
"foo, "x" 
"bar"
vim-smartinput 
kana/vim-smartinput 
❖ highly customizable 
call smartinput#define_rule({ 
 'at': '<%#', 
 'char': '%', 
 ...
Table of Contents 
❖ Pure Vim way 
❖ Some Plugins 
❖ About lexima.vim
About lexima.vim 
cohama/lexima.vim 
❖ highly customizable (inspired by vim-smartinput) 
❖ dot-repeatable 
❖ unstable
lexima.vim's rule definition 
inspired by kana/vim-smartinput 
call lexima#add_rule({ 
 'at': '<%#', 
 'char': '%', 
 'inp...
lexima.vim's endwise-rule 
❖ inspired by tpope/vim-endwise 
❖ Of course, dot-repeatable 
def foo 
| 
end 
<CR> 
def foo|
Mechanism 
In case of (foo<Esc> 
(| 
(|) 
(foo|) 
(foo| 
(foo)| 
(foo|) 
input ( 
call setline() 
input foo 
call setline(...
Demo
Thanks
Upcoming SlideShare
Loading in …5
×

Auto closing parenthesis @vim conf2014

5,291 views

Published on

Published in: Technology
  • Be the first to comment

Auto closing parenthesis @vim conf2014

  1. 1. Auto-closing parenthesis 2014/11/5 VimConf 2014 cohama / @c0hama
  2. 2. About me cohama ❖ Twitter @c0hama ❖ from Nagoya ➢ Nagoya.vim ❖ Agit.vim, the-ocamlspot.vim ❖ JavaScript, Haskell
  3. 3. Introduction reverse(range(1, winnr('$' How many ) do we need to type?
  4. 4. Introduction while (true) { if (p == 1) { foo(); break; How about } ?
  5. 5. Introduction ❖ We need auto-closing. reverse(range(1, winnr('$'))) while (true) { if (p == 1) { foo(); break; } }
  6. 6. For example ❖ Atom
  7. 7. For example ❖ Sublime Text
  8. 8. For example ❖ Eclipse
  9. 9. In Vim...
  10. 10. Table of Contents ❖ Pure Vim way ❖ Some Plugins ❖ About lexima.vim
  11. 11. Table of Contents ❖ Pure Vim way ❖ Some Plugins ❖ About lexima.vim
  12. 12. Pure Vim way inoremap ( ()<Left> inoremap [ []<Left> inoremap " ""<Left> Very easy but ...
  13. 13. Pure Vim way but ... let w = winnr()) let w = winnr) let leftparen = "()" We need Plugin Power! I'm'
  14. 14. Auto-closing requirements Before Input After | ( (|) (|) ) ()| (|) <BS> | I| 'm I'm| syntax-specific rules filetype-specific rules
  15. 15. Table of Contents ❖ Pure Vim way ❖ Some Plugins ❖ About lexima.vim
  16. 16. delimitMate Raimondi/delimitMate ❖ some useful features <C-G>g ("foo|") ("foo")| ❖ unable to dot-repeat
  17. 17. Unable to dot-repeat "foo" "bar" A, "x"<Esc> "foo, "x" "bar"
  18. 18. Unable to dot-repeat j. "foo", "x" "barx" "foo, "x" "bar"
  19. 19. vim-smartinput kana/vim-smartinput ❖ highly customizable call smartinput#define_rule({ 'at': '<%#', 'char': '%', 'input': '% %><Left><Left><Left>'}) ❖ unable to dot-repeat <% | %> % <|
  20. 20. Table of Contents ❖ Pure Vim way ❖ Some Plugins ❖ About lexima.vim
  21. 21. About lexima.vim cohama/lexima.vim ❖ highly customizable (inspired by vim-smartinput) ❖ dot-repeatable ❖ unstable
  22. 22. lexima.vim's rule definition inspired by kana/vim-smartinput call lexima#add_rule({ 'at': '<%#', 'char': '%', 'input': '% ', 'input_after': ' %>'}) compatible with vim-smartinput <% | %> % <|
  23. 23. lexima.vim's endwise-rule ❖ inspired by tpope/vim-endwise ❖ Of course, dot-repeatable def foo | end <CR> def foo|
  24. 24. Mechanism In case of (foo<Esc> (| (|) (foo|) (foo| (foo)| (foo|) input ( call setline() input foo call setline() input ) call setpos()
  25. 25. Demo
  26. 26. Thanks

×