├── README.markdown ├── doc └── textobj-quoted.txt └── plugin └── textobj └── underscore.vim /README.markdown: -------------------------------------------------------------------------------- 1 | Introduction 2 | ------------ 3 | 4 | The textobj-underscore plugin provides two new text-objects which are 5 | triggered by `a_` and `i_` respectively. You can use them when you have to 6 | deal with the following type of words: 7 | 8 | - foo\_bar\_baz 9 | 10 | Now, suppose you have to change bar to qux (\* for cursor position). You can 11 | do the following: 12 | 13 | `foo_b*ar_baz` and type `ci_` to get `foo_*_baz`. Or you can type `da_` to get 14 | `foobaz` 15 | 16 | Installation 17 | ------------ 18 | 19 | I strongly recommend installing [pathogen.vim](https://github.com/tpope/vim-pathogen). 20 | 21 | cd ~/.vim/bundle 22 | git clone git://github.com/lucapette/vim-textobj-underscore.git 23 | 24 | Or you can unzip it in your `~/.vim` directory. The plugin depends on the awesome 25 | [vim-textobj-user](https://github.com/kana/vim-textobj-user) by 26 | [kana](https://github.com/kana). So you need to install it in order to use 27 | this plugin. 28 | 29 | Contributors 30 | ------------ 31 | 32 | - [kana](https://github.com/kana) 33 | Use `normal!` instead of `normal` to avoid unexpected remapping. 34 | 35 | Copyright 36 | --------- 37 | 38 | Copyright (c) Luca Pette. Distributed under the same terms as Vim itself. 39 | -------------------------------------------------------------------------------- /doc/textobj-quoted.txt: -------------------------------------------------------------------------------- 1 | *textobj-underscoere.txt* Text objects for underscored words 2 | 3 | Version 0.0.1 4 | 5 | CONTENTS *textobj-underscore-contents* 6 | 7 | Introduction |textobj-underscore-introduction| 8 | Copyright |textobj-underscore-copyright| 9 | 10 | 11 | ============================================================================== 12 | INTRODUCTION *textobj-underscore-introduction* 13 | 14 | The *textobj-underscore* plugin provides two new |text-objects| which are 15 | triggered by `a_` and `i_` respectively. You can use them when you have to 16 | deal with the following type of words: 17 | 18 | - foo_bar_baz 19 | 20 | Now, suppose you have to change bar to qux (* for cursor position). You can do 21 | the following: 22 | 23 | `foo_b*ar_bar` and type `ci_` to get `foo_*_bar`. Or you can type `da_` to 24 | get `foobar` 25 | 26 | Latest version: 27 | http://github.com/lucapette/vim-textobj-underscore 28 | 29 | ============================================================================== 30 | COPYRIGHT *textobj-underscore-copyright* 31 | 32 | Copyright (c) Luca Pette. Distributed under the same terms as Vim itself. 33 | See |license|. 34 | 35 | vim:tw=78:ts=8:ft=help:norl: 36 | -------------------------------------------------------------------------------- /plugin/textobj/underscore.vim: -------------------------------------------------------------------------------- 1 | if exists('g:loaded_textobj_underscore') 2 | finish 3 | endif 4 | 5 | call textobj#user#plugin('underscore', { 6 | \ '-': { 7 | \ '*sfile*': expand(':p'), 8 | \ 'select-a': 'a_', '*select-a-function*': 's:select_a', 9 | \ 'select-i': 'i_', '*select-i-function*': 's:select_i' 10 | \ } 11 | \ }) 12 | 13 | function! s:select_a() 14 | normal! F_ 15 | 16 | let end_pos = getpos('.') 17 | 18 | normal! f_ 19 | 20 | let start_pos = getpos('.') 21 | return ['v', start_pos, end_pos] 22 | endfunction 23 | 24 | " ciao_come_stai 25 | 26 | function! s:select_i() 27 | normal! T_ 28 | 29 | let end_pos = getpos('.') 30 | 31 | normal! t_ 32 | 33 | let start_pos = getpos('.') 34 | 35 | return ['v', start_pos, end_pos] 36 | endfunction 37 | 38 | let g:loaded_textobj_underscore = 1 39 | --------------------------------------------------------------------------------