7
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

vim-sandwich とその周辺の設定

Last updated at Posted at 2015-07-27

よさげプラグインの machakann/vim-sandwich を使ってみました。

代わりに vim-textobj-multiblock, vim-operator-surround を削除しました。
vim-expand-region, machakann/vim-textobj-delimited (machakann さんにコメントを頂いて設定できました) も使っています。

以下のように # にカーソルがあったときに「vad」で「, fuga」を選択できるように設定しています。
expand-region を使うことで「,eee」で同じく「, fuga」を選択します。

hoge, fuga, homu
        #

.vimrc の抜粋を記載します。
NeoBundle がエラーとならない適切な箇所に記載してください。

.vimrc抜粋1
" neobundle#begin, neobundle#end 間
NeoBundleLazy 'terryma/vim-expand-region', {
      \   'autoload': {
      \     'mappings': ['<Plug>(expand_region']}}
NeoBundle 'machakann/vim-sandwich'
NeoBundleLazy 'machakann/vim-textobj-delimited', {
      \   'autoload': {'on_source': 'vim-expand-region'}}

.vimrc抜粋2
" neobundle#end 後
if neobundle#tap('vim-sandwich')
  nmap s <Nop>
  xmap s <Nop>

  let g:textobj#sandwich#stimeoutlen = 100
  let g:sandwich#recipes = deepcopy(g:sandwich#default_recipes)
  let g:sandwich#recipes += [{'buns' : ['「', '」']}]
  let g:sandwich#recipes += [{'buns' : ['【', '】']}]
  let g:sandwich#recipes += [{'buns' : ['(', ')']}]
  let g:sandwich#recipes += [{'buns' : ['『', '』']}]

  call neobundle#untap()
endif

if neobundle#tap('vim-expand-region')
  " ad: delimited
  " ib: sandwich
  let g:expand_region_text_objects = {
        \ 'iw'  : 0,
        \ 'iW'  : 0,
        \ 'iu'  : 0,
        \ 'ad' : 0,
        \ 'ib'  : 1,
        \ }

  call submode#enter_with('expand-region', 'nv', 'r', ',e', '<Plug>(expand_region_expand)')
  call submode#map('expand-region', 'nv', 'r', 'e', '<Plug>(expand_region_expand)')
  call submode#map('expand-region', 'nv', 'r', 's', '<Plug>(expand_region_shrink)')
  call submode#map('expand-region', 'nv', 'r', 'E', '<Plug>(expand_region_shrink)')

  call neobundle#untap()
endif

if neobundle#tap('vim-textobj-delimited')
  let g:textobj_delimited_patterns = [[', *', '\m\%(, *\)\?\%([^,[\]{}]\+, *\)\+\%([^,[\]{}]\+\)\?']]

  call neobundle#untap()
endif

sandwich.vim を書きました - 書いたものなど

7
6
5

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?