auto closing parenthesis @vim conf2014

26
Auto-closing parenthesis 2014/11/5 VimConf 2014 cohama / @c0hama

Upload: cohama

Post on 06-Jul-2015

2.620 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Auto closing parenthesis @vim conf2014

Auto-closing parenthesis2014/11/5 VimConf 2014

cohama / @c0hama

Page 2: Auto closing parenthesis @vim conf2014

About mecohama❖ Twitter @c0hama

❖ from Nagoya➢ Nagoya.vim

❖ Agit.vim, the-ocamlspot.vim

❖ JavaScript, Haskell

Page 3: Auto closing parenthesis @vim conf2014

Introduction

How many ) do we need to type?

reverse(range(1, winnr('$'

Page 4: Auto closing parenthesis @vim conf2014

Introduction

How about } ?

while (true) { if (p == 1) { foo(); break;

Page 5: Auto closing parenthesis @vim conf2014

Introduction❖ We need auto-closing.

reverse(range(1, winnr('$')))

while (true) { if (p == 1) { foo(); break;

}}

Page 6: Auto closing parenthesis @vim conf2014

For example❖ Atom

Page 7: Auto closing parenthesis @vim conf2014

For example❖ Sublime Text

Page 8: Auto closing parenthesis @vim conf2014

For example❖ Eclipse

Page 9: Auto closing parenthesis @vim conf2014

In Vim...

Page 10: Auto closing parenthesis @vim conf2014

Table of Contents❖ Pure Vim way

❖ Some Plugins

❖ About lexima.vim

Page 11: Auto closing parenthesis @vim conf2014

Table of Contents❖ Pure Vim way

❖ Some Plugins

❖ About lexima.vim

Page 12: Auto closing parenthesis @vim conf2014

Pure Vim way

inoremap ( ()<Left>inoremap [ []<Left>inoremap " ""<Left>

Very easy but ...

Page 13: Auto closing parenthesis @vim conf2014

Pure Vim way but ...

let w = winnr)

We need Plugin Power!

let leftparen = "()"

I'm'

let w = winnr())

Page 14: Auto closing parenthesis @vim conf2014

Auto-closing requirementsBefore Input After

| ( (|)

(|) ) ()|

(|) <BS> |

I| 'm I'm|

syntax-specific rulesfiletype-specific rules

Page 15: Auto closing parenthesis @vim conf2014

Table of Contents❖ Pure Vim way

❖ Some Plugins

❖ About lexima.vim

Page 16: Auto closing parenthesis @vim conf2014

delimitMateRaimondi/delimitMate

❖ some useful features

❖ unable to dot-repeat

("foo|") ("foo")|<C-G>g

Page 17: Auto closing parenthesis @vim conf2014

Unable to dot-repeat

"foo""bar"

A, "x"<Esc>

"foo, "x""bar"

Page 18: Auto closing parenthesis @vim conf2014

Unable to dot-repeat

j.

"foo", "x""barx"

"foo, "x""bar"

Page 19: Auto closing parenthesis @vim conf2014

vim-smartinputkana/vim-smartinput❖ highly customizable

❖ unable to dot-repeat

call smartinput#define_rule({\ 'at': '<\%#',\ 'char': '%',\ 'input': '% %><Left><Left><Left>'})

<% | %>%

<|

Page 20: Auto closing parenthesis @vim conf2014

Table of Contents❖ Pure Vim way

❖ Some Plugins

❖ About lexima.vim

Page 21: Auto closing parenthesis @vim conf2014

About lexima.vimcohama/lexima.vim

❖ highly customizable (inspired by vim-smartinput)

❖ dot-repeatable

❖ unstable

Page 22: Auto closing parenthesis @vim conf2014

lexima.vim's rule definitioninspired by kana/vim-smartinput

compatible with vim-smartinput

call lexima#add_rule({\ 'at': '<\%#',\ 'char': '%',\ 'input': '% ',\ 'input_after': ' %>'})

<% | %>%

<|

Page 23: Auto closing parenthesis @vim conf2014

lexima.vim's endwise-rule❖ inspired by tpope/vim-endwise

❖ Of course, dot-repeatable

def foo |end

<CR>def foo|

Page 24: Auto closing parenthesis @vim conf2014

Mechanism

(|(|)(foo|)

In case of (foo<Esc>

(foo|(foo)|(foo|)

input (

call setline()

input foo

call setline()

input )

call setpos()

Page 25: Auto closing parenthesis @vim conf2014

Demo

Page 26: Auto closing parenthesis @vim conf2014

Thanks