├── .github ├── dependabot.yml └── workflows │ └── ci.yml ├── .gitignore ├── .ruby-version ├── .vim-version ├── Flavorfile ├── Gemfile ├── Rakefile ├── autoload └── textobj │ └── line.vim ├── doc └── textobj-line.txt ├── plugin └── textobj │ └── line.vim └── t └── basics.vim /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "bundler" 4 | directory: "/" 5 | schedule: 6 | interval: "weekly" 7 | versioning-strategy: increase 8 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | schedule: 9 | - cron: 0 0 * * * 10 | 11 | jobs: 12 | test: 13 | runs-on: ubuntu-latest 14 | steps: 15 | - uses: actions/checkout@v2 16 | - name: Set up Ruby 17 | uses: ruby/setup-ruby@v1 18 | with: 19 | bundler-cache: true # runs 'bundle install' and caches installed gems automatically 20 | - name: Get local Vim version 21 | run: echo "local_vim_version=$(<.vim-version)" >>$GITHUB_ENV 22 | - name: Set up Vim 23 | uses: thinca/action-setup-vim@v1 24 | with: 25 | vim_version: ${{ github.event_name == 'schedule' && 'head' || env.local_vim_version }} 26 | vim_type: vim 27 | download: never # For some reason 'available' doesn't build from source as a fallback. 28 | - name: Run tests 29 | # 2>&1 required to avoid interleaved stdout and stderr in log. 30 | run: rake ci 2>&1 31 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vim-flavor 2 | Flavorfile.lock 3 | Gemfile.lock 4 | tags 5 | -------------------------------------------------------------------------------- /.ruby-version: -------------------------------------------------------------------------------- 1 | 3.0.2 2 | -------------------------------------------------------------------------------- /.vim-version: -------------------------------------------------------------------------------- 1 | v8.2.3446 2 | -------------------------------------------------------------------------------- /Flavorfile: -------------------------------------------------------------------------------- 1 | flavor 'kana/vim-textobj-user', '~> 0.4' 2 | 3 | # vim: filetype=ruby 4 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gem 'vim-flavor', '~> 4.0' 4 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | task :ci => [:dump, :test] 2 | 3 | task :dump do 4 | sh 'vim --version' 5 | end 6 | 7 | task :test do 8 | sh 'bundle exec vim-flavor test' 9 | end 10 | -------------------------------------------------------------------------------- /autoload/textobj/line.vim: -------------------------------------------------------------------------------- 1 | " textobj-line - Text objects for the current line 2 | " Version: 0.0.2 3 | " Copyright (C) 2012-2015 Kana Natsuno 4 | " License: MIT license {{{ 5 | " Permission is hereby granted, free of charge, to any person obtaining 6 | " a copy of this software and associated documentation files (the 7 | " "Software"), to deal in the Software without restriction, including 8 | " without limitation the rights to use, copy, modify, merge, publish, 9 | " distribute, sublicense, and/or sell copies of the Software, and to 10 | " permit persons to whom the Software is furnished to do so, subject to 11 | " the following conditions: 12 | " 13 | " The above copyright notice and this permission notice shall be included 14 | " in all copies or substantial portions of the Software. 15 | " 16 | " THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17 | " OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | " MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | " IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | " CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | " TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | " SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | " }}} 24 | " Interface "{{{1 25 | function! textobj#line#select_a() "{{{2 26 | if empty(getline('.')) 27 | return 0 28 | endif 29 | 30 | normal! 0 31 | let head_pos = getpos('.') 32 | 33 | normal! $ 34 | let tail_pos = getpos('.') 35 | 36 | return ['v', head_pos, tail_pos] 37 | endfunction 38 | 39 | 40 | 41 | 42 | function! textobj#line#select_i() "{{{2 43 | if empty(getline('.')) 44 | return 0 45 | endif 46 | 47 | normal! ^ 48 | let head_pos = getpos('.') 49 | 50 | normal! g_ 51 | let tail_pos = getpos('.') 52 | 53 | let non_blank_char_exists_p = getline('.')[head_pos[2] - 1] !~# '\s' 54 | return 55 | \ non_blank_char_exists_p 56 | \ ? ['v', head_pos, tail_pos] 57 | \ : 0 58 | endfunction 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | " __END__ "{{{1 68 | " vim: foldmethod=marker 69 | -------------------------------------------------------------------------------- /doc/textobj-line.txt: -------------------------------------------------------------------------------- 1 | *textobj-line.txt* Text objects for the current line 2 | 3 | Version 0.0.2 4 | Script ID: 3886 5 | Copyright (C) 2012-2015 Kana Natsuno 6 | License: MIT license {{{ 7 | Permission is hereby granted, free of charge, to any person obtaining 8 | a copy of this software and associated documentation files (the 9 | "Software"), to deal in the Software without restriction, including 10 | without limitation the rights to use, copy, modify, merge, publish, 11 | distribute, sublicense, and/or sell copies of the Software, and to 12 | permit persons to whom the Software is furnished to do so, subject to 13 | the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included 16 | in all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 21 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 | }}} 26 | 27 | CONTENTS *textobj-line-contents* 28 | 29 | Introduction |textobj-line-introduction| 30 | Interface |textobj-line-interface| 31 | Key Mappings |textobj-line-key-mappings| 32 | Bugs |textobj-line-bugs| 33 | Changelog |textobj-line-changelog| 34 | 35 | 36 | 37 | 38 | ============================================================================== 39 | INTRODUCTION *textobj-line-introduction* 40 | 41 | *textobj-line* is a Vim plugin to provide text objects to select a portion of 42 | the current line. Sometimes you want to select a portion of the current line 43 | like "^vg_" or "0v$h". This plugin provides the text objects for such ranges. 44 | 45 | For example, if the current line equals to "__foo_bar_baz__" (where "_" 46 | represents a whitespace character), you can select "foo_bar_baz" (without 47 | leading and trailing spaces) by |(textobj-line-i)| and "__foo_bar_baz__" 48 | (with leading and trailing spaces) by |(textobj-line-a)|. 49 | 50 | 51 | Requirements: 52 | - Vim 7.2 or later 53 | - |textobj-user| 0.4.0 or later (vimscript#2100) 54 | 55 | Installation: 56 | - Recommended way: Use vim-flavor . 57 | 58 | Latest version: 59 | https://github.com/kana/vim-textobj-line 60 | 61 | 62 | 63 | 64 | ============================================================================== 65 | INTERFACE *textobj-line-interface* 66 | 67 | ------------------------------------------------------------------------------ 68 | KEY MAPPINGS *textobj-line-key-mappings* 69 | 70 | DEFAULT KEY MAPPINGS *textobj-line-default-key-mappings* 71 | 72 | *g:textobj_line_no_default_key_mappings* 73 | *:TextobjLineDefaultKeyMappings* 74 | This plugin defines the following key mappings by default. If you don't want 75 | the default key mappings, define |g:textobj_line_no_default_key_mappings| 76 | before this plugin is loaded (e.g. in your |vimrc|). You can also use 77 | |:TextobjLineDefaultKeyMappings| to redefine these key mappings. This command 78 | doesn't override existing {lhs}s unless [!] is given. 79 | 80 | Modes {lhs} {rhs} 81 | ------------------------------------------------ 82 | vo al |(textobj-line-a)| 83 | vo il |(textobj-line-i)| 84 | 85 | 86 | NAMED KEY MAPPINGS *textobj-line-named-key-mappings* 87 | 88 | (textobj-line-a) *(textobj-line-a)* 89 | Select all characters in the current line without the 90 | end of line character. You can select the same 91 | portion with the following command: 0v$h 92 | 93 | Note that this text object selects nothing if 94 | 95 | * the current line does not contain any character, 96 | 97 | because there is no text to select in the current line. 98 | 99 | (textobj-line-i) *(textobj-line-i)* 100 | Select all characters in the current line without 101 | leading spaces, trailing spaces and the end of line 102 | character. You can select the same portion with the 103 | following command: ^vg_ 104 | 105 | Note that this text object selects nothing if 106 | 107 | * the current line does not contain any character, or 108 | * the current line consists only of space characters, 109 | 110 | because there is no text to select in the current line. 111 | 112 | 113 | 114 | 115 | ============================================================================== 116 | BUGS *textobj-line-bugs* 117 | 118 | - Currently there is no known issue. 119 | 120 | 121 | 122 | 123 | ============================================================================== 124 | CHANGELOG *textobj-line-changelog* 125 | 126 | 0.0.2 2015-07-16T20:56:24+09:00 *textobj-line-changelog-0.0.2* 127 | - Update for new |textobj-user| conventions. Now textobj-user 0.4 or 128 | later is required to use textobj-line. 129 | 130 | 0.0.1 2013-01-18T21:08:10+09:00 *textobj-line-changelog-0.0.1* 131 | - Support vim-flavor . 132 | - Update |textobj-line-introduction|. 133 | 134 | 0.0.0 2012-01-16T18:48:10+09:00 *textobj-line-changelog-0.0.0* 135 | - Initial version. 136 | 137 | 138 | 139 | 140 | ============================================================================== 141 | vim:tw=78:ts=8:ft=help:norl:fen:fdl=0:fdm=marker: 142 | -------------------------------------------------------------------------------- /plugin/textobj/line.vim: -------------------------------------------------------------------------------- 1 | " textobj-line - Text objects for the current line 2 | " Version: 0.0.2 3 | " Copyright (C) 2012-2015 Kana Natsuno 4 | " License: MIT license {{{ 5 | " Permission is hereby granted, free of charge, to any person obtaining 6 | " a copy of this software and associated documentation files (the 7 | " "Software"), to deal in the Software without restriction, including 8 | " without limitation the rights to use, copy, modify, merge, publish, 9 | " distribute, sublicense, and/or sell copies of the Software, and to 10 | " permit persons to whom the Software is furnished to do so, subject to 11 | " the following conditions: 12 | " 13 | " The above copyright notice and this permission notice shall be included 14 | " in all copies or substantial portions of the Software. 15 | " 16 | " THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17 | " OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | " MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | " IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | " CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | " TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | " SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | " }}} 24 | 25 | if exists('g:loaded_textobj_line') 26 | finish 27 | endif 28 | 29 | 30 | 31 | 32 | call textobj#user#plugin('line', { 33 | \ '-': { 34 | \ 'select-a': 'al', 'select-a-function': 'textobj#line#select_a', 35 | \ 'select-i': 'il', 'select-i-function': 'textobj#line#select_i', 36 | \ }, 37 | \ }) 38 | 39 | 40 | 41 | 42 | let g:loaded_textobj_line = 1 43 | 44 | " __END__ 45 | " vim: foldmethod=marker 46 | -------------------------------------------------------------------------------- /t/basics.vim: -------------------------------------------------------------------------------- 1 | runtime! plugin/textobj/line.vim 2 | 3 | function! s:check(move_cmd, op_cmd, expected_value) 4 | let @0 = '*nothing yanked*' 5 | execute 'normal!' a:move_cmd 6 | execute 'normal' a:op_cmd 7 | Expect @0 ==# a:expected_value 8 | endfunction 9 | 10 | 11 | 12 | 13 | describe '(textobj-line-select-a)' 14 | before 15 | new 16 | end 17 | 18 | after 19 | close! 20 | end 21 | 22 | it 'selects all characters in the current line but the end of line' 23 | silent 1 put! =['', ' foo bar baz ', '', 'x', '', ' ', '', '', ''] 24 | 25 | call s:check('2gg0', 'valy', ' foo bar baz ') 26 | call s:check('2gg0', 'yal', ' foo bar baz ') 27 | call s:check('2gg0ww', 'valy', ' foo bar baz ') 28 | call s:check('2gg0ww', 'yal', ' foo bar baz ') 29 | call s:check('4gg0', 'valy', 'x') 30 | call s:check('4gg0', 'yal', 'x') 31 | call s:check('6gg2|', 'valy', ' ') 32 | call s:check('6gg2|', 'yal', ' ') 33 | call s:check('8gg0', 'valy', "\n") " NB: Cannot select empty text in Visual mode. 34 | call s:check('8gg0', 'yal', '') 35 | end 36 | end 37 | 38 | 39 | 40 | 41 | describe '(textobj-line-select-i)' 42 | before 43 | new 44 | end 45 | 46 | after 47 | close! 48 | end 49 | 50 | it 'selects all characters in the current line but surrounding spaces' 51 | silent 1 put! =['', ' foo bar baz ', '', 'x', '', ' ', '', '', ''] 52 | 53 | call s:check('2gg0', 'vily', 'foo bar baz') 54 | call s:check('2gg0', 'yil', 'foo bar baz') 55 | call s:check('2gg0ww', 'vily', 'foo bar baz') 56 | call s:check('2gg0ww', 'yil', 'foo bar baz') 57 | call s:check('4gg0', 'vily', 'x') 58 | call s:check('4gg0', 'yil', 'x') 59 | call s:check('6gg2|', 'vily', ' ') " NB: Cannot select empty text in Visual mode. 60 | call s:check('6gg2|', 'yil', '') 61 | call s:check('8gg0', 'vily', "\n") " NB: Cannot select empty text in Visual mode. 62 | call s:check('8gg0', 'yil', '') 63 | end 64 | end 65 | --------------------------------------------------------------------------------