├── .gitignore ├── .travis.yml ├── Gemfile ├── README.md ├── Rakefile ├── VimFlavor ├── autoload └── textobj │ └── entire.vim ├── doc └── textobj-entire.txt ├── plugin └── textobj │ └── entire.vim └── t ├── basics.vim ├── jumplist.vim └── mark.vim /.gitignore: -------------------------------------------------------------------------------- 1 | .vim-flavor 2 | Gemfile.lock 3 | VimFlavor.lock 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: ruby 2 | rvm: 3 | - 2.4.1 4 | script: rake ci 5 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gem 'vim-flavor', '~> 1.1' 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vim-textobj-entire - Text objects for entire buffers 2 | 3 | [![Build Status](https://travis-ci.org/kana/vim-textobj-entire.png)](https://travis-ci.org/kana/vim-textobj-entire) 4 | 5 | vim-textobj-entire is a Vim plugin to provide text objects (`ae` and `ie` by 6 | default) to select the entire content of a buffer. Though these are trivial 7 | operations (e.g. `ggVG`), text object versions are more handy, because you do 8 | not have to be conscious of the cursor position (e.g. `vae`). 9 | 10 | vim-textobj-entire provides two text objects: 11 | 12 | * `ae` targets the entire content of the current buffer. 13 | * `ie` is similar to `ae`, but `ie` does not include leading and trailing empty 14 | lines. `ie` is handy for some situations. For example, 15 | 1. Paste some text into a new buffer (`n"*P`) 16 | -- note that the initial empty line is left as the last line. 17 | 2. Edit the text (`:%s/foo/bar/g` etc) 18 | 3. Then copy the resulting text to another application (`"*yie`) 19 | 20 | See also [the reference manual](https://github.com/kana/vim-textobj-entire/blob/master/doc/textobj-entire.txt) for more details. 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env rake 2 | 3 | task :ci => [:dump, :test] 4 | 5 | task :dump do 6 | sh 'vim --version' 7 | end 8 | 9 | task :test do 10 | sh 'bundle exec vim-flavor test' 11 | end 12 | -------------------------------------------------------------------------------- /VimFlavor: -------------------------------------------------------------------------------- 1 | flavor 'kana/vim-textobj-user', '~> 0.3' 2 | -------------------------------------------------------------------------------- /autoload/textobj/entire.vim: -------------------------------------------------------------------------------- 1 | " textobj-entire - Text objects for entire buffer 2 | " Version: 0.0.4 3 | " Copyright (C) 2009-2018 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#entire#select_a() "{{{2 26 | " To easily back to the last position after a command. 27 | " For example: yae 28 | normal! m' 29 | 30 | keepjumps normal! gg0 31 | let start_pos = getpos('.') 32 | 33 | keepjumps normal! G$ 34 | let end_pos = getpos('.') 35 | 36 | return ['V', start_pos, end_pos] 37 | endfunction 38 | 39 | 40 | function! textobj#entire#select_i() "{{{2 41 | " To easily back to the last position after a command. 42 | " For example: yie 43 | normal! m' 44 | 45 | keepjumps normal! gg0 46 | call search('^.', 'cW') 47 | let start_pos = getpos('.') 48 | 49 | keepjumps normal! G$ 50 | call search('^.', 'bcW') 51 | normal! $ 52 | let end_pos = getpos('.') 53 | 54 | return ['V', start_pos, end_pos] 55 | endfunction 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | " __END__ "{{{1 65 | " vim: foldmethod=marker 66 | -------------------------------------------------------------------------------- /doc/textobj-entire.txt: -------------------------------------------------------------------------------- 1 | *textobj-entire.txt* Text objects for entire buffer 2 | 3 | Version 0.0.4 4 | Script ID: 2610 5 | Copyright (C) 2009-2018 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-entire-contents* 28 | 29 | Introduction |textobj-entire-introduction| 30 | Interface |textobj-entire-interface| 31 | Commands |textobj-entire-commands| 32 | Functions |textobj-entire-functions| 33 | Mappings |textobj-entire-mappings| 34 | Examples |textobj-entire-examples| 35 | Bugs |textobj-entire-bugs| 36 | Changelog |textobj-entire-changelog| 37 | 38 | 39 | 40 | 41 | ============================================================================== 42 | INTRODUCTION *textobj-entire-introduction* 43 | 44 | *textobj-entire* is a Vim plugin to provide text objects (|ae| and |ie| by 45 | default) to select the entire content of a buffer. Though these are trivial 46 | operations (e.g. `ggVG`), text object versions are more handy, because you do 47 | not have to be conscious of the cursor position (e.g. `vae`). 48 | 49 | 50 | Requirements: 51 | - Vim 7.2 or later 52 | - |textobj-user| 0.3.7 or later (vimscript#2100) 53 | 54 | Latest version: 55 | https://github.com/kana/vim-textobj-entire 56 | 57 | 58 | 59 | 60 | ============================================================================== 61 | INTERFACE *textobj-entire-interface* 62 | 63 | ------------------------------------------------------------------------------ 64 | MAPPINGS *textobj-entire-mappings* 65 | 66 | These key mappings are defined in Visual mode and Operator-pending mode. 67 | 68 | (textobj-entire-a) *(textobj-entire-a)* 69 | Select the entire content of the current buffer. 70 | This is like `ggVG`, but you do not have to be 71 | conscious of the cursor position. 72 | 73 | (textobj-entire-i) *(textobj-entire-i)* 74 | Like |(textobj-entire-a)|, but leading and 75 | trailing empty lines are excluded. This is handy for 76 | some situations that you do not want to include such 77 | empty lines. For example: 78 | 79 | 1. Paste some text into a new buffer (`n"*P`) 80 | -- note that the initial empty line is left 81 | as the last line. 82 | 2. Edit the text (`:%s/foo/bar/g` etc) 83 | 3. Copy the text to another application (`"*yie`) 84 | 85 | 86 | 87 | 88 | ============================================================================== 89 | CUSTOMIZING *textobj-entire-customizing* 90 | 91 | *g:textobj_entire_no_default_key_mappings* 92 | *:TextobjEntireDefaultKeyMappings* 93 | This plugin will define the following key mappings in Visual mode and 94 | Operator-pending mode automatically. If you don't want these key mappings, 95 | define |g:textobj_entire_no_default_key_mappings| before this plugin is loaded 96 | (e.g. in your |vimrc|). You can also use |:TextobjEntireDefaultKeyMappings| 97 | to redefine these key mappings. This command doesn't override existing {lhs}s 98 | unless [!] is given. 99 | 100 | {lhs} {rhs} ~ 101 | ----- ---------------------- ~ 102 | ae (textobj-entire-a) 103 | ie (textobj-entire-i) 104 | 105 | 106 | 107 | 108 | ============================================================================== 109 | BUGS *textobj-entire-bugs* 110 | 111 | - [count] is just ignored. 112 | 113 | - See |textobj-user-bugs| for further information. 114 | 115 | 116 | 117 | 118 | ============================================================================== 119 | CHANGELOG *textobj-entire-changelog* 120 | 121 | 0.0.4 2018-01-19T19:06:11+09:00 *textobj-entire-changelog-0.0.4* 122 | - Fix the bug that the cursor is not restored to the correct column 123 | when using or `` after `ae` or `ie`. For example, `yae` 124 | moved the cursor to the correct line, but incorrect column (that is 125 | the first non-blank character in the line). 126 | 127 | 0.0.3 2014-02-26T22:28:27+09:00 *textobj-entire-changelog-0.0.3* 128 | - Fix to maintain the |jumplist| for usability. For example, yae 129 | backs the cursor to the position before the yanking. Old versions 130 | do not maintain the jumplist properly, so that moves the 131 | cursor to an unpredictable position. 132 | 133 | 0.0.2 2013-01-18T19:38:03+09:00 *textobj-entire-changelog-0.0.2* 134 | - Support vim-flavor . 135 | - Update |textobj-entire-introduction|. 136 | 137 | 0.0.1 2009-08-13T21:21:01+09:00 138 | - Fix a typo on the name of a variable. 139 | 140 | 0.0.0 2009-04-15T14:41:17+09:00 141 | - Initial version. 142 | 143 | 144 | 145 | 146 | ============================================================================== 147 | vim:tw=78:ts=8:ft=help:norl:fen:fdl=0:fdm=marker: 148 | -------------------------------------------------------------------------------- /plugin/textobj/entire.vim: -------------------------------------------------------------------------------- 1 | " textobj-entire - Text objects for entire buffer 2 | " Version: 0.0.4 3 | " Copyright (C) 2009-2018 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_entire') 26 | finish 27 | endif 28 | 29 | call textobj#user#plugin('entire', { 30 | \ '-': { 31 | \ 'select-a': 'ae', 'select-a-function': 'textobj#entire#select_a', 32 | \ 'select-i': 'ie', 'select-i-function': 'textobj#entire#select_i' 33 | \ } 34 | \ }) 35 | 36 | " Fin. "{{{1 37 | 38 | let g:loaded_textobj_entire = 1 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | " __END__ 48 | " vim: foldmethod=marker 49 | -------------------------------------------------------------------------------- /t/basics.vim: -------------------------------------------------------------------------------- 1 | runtime! plugin/textobj/entire.vim 2 | 3 | let g:filler_line = [ 4 | \ 'Lorem ipsum dolor sit amet, consectetur adipisicing elit,', 5 | \ 'sed do eiusmod tempor incididunt ut labore et dolore magna', 6 | \ 'aliqua. Ut enim ad minim veniam, quis nostrud exercitation', 7 | \ 'ullamco laboris nisi ut aliquip ex ea commodo consequat.', 8 | \ 'Duis aute irure dolor in reprehenderit in voluptate velit', 9 | \ 'esse cillum dolore eu fugiat nulla pariatur. Excepteur sint', 10 | \ 'occaecat cupidatat non proident, sunt in culpa qui officia', 11 | \ 'deserunt mollit anim id est laborum.', 12 | \ ] 13 | 14 | function! FillBuffer() 15 | put =['', ''] + g:filler_line + ['', ''] 16 | 1 delete _ 17 | endfunction 18 | 19 | describe '(textobj-entire-a)' 20 | before 21 | new 22 | call FillBuffer() 23 | end 24 | 25 | after 26 | close! 27 | end 28 | 29 | it 'targets the whole content of the current buffer' 30 | execute 'normal' "y\(textobj-entire-a)" 31 | Expect split(@0, '\n', 1) ==# ['', ''] + g:filler_line + ['', ''] + [''] 32 | end 33 | end 34 | 35 | describe '(textobj-entire-i)' 36 | before 37 | new 38 | call FillBuffer() 39 | end 40 | 41 | after 42 | close! 43 | end 44 | 45 | it 'targets the whole content of the current buffer' 46 | execute 'normal' "y\(textobj-entire-i)" 47 | Expect split(@0, '\n', 1) ==# g:filler_line + [''] 48 | end 49 | end 50 | -------------------------------------------------------------------------------- /t/jumplist.vim: -------------------------------------------------------------------------------- 1 | runtime! plugin/textobj/entire.vim 2 | 3 | let g:filler_line = [ 4 | \ 'Lorem ipsum dolor sit amet, consectetur adipisicing elit,', 5 | \ 'sed do eiusmod tempor incididunt ut labore et dolore magna', 6 | \ 'aliqua. Ut enim ad minim veniam, quis nostrud exercitation', 7 | \ 'ullamco laboris nisi ut aliquip ex ea commodo consequat.', 8 | \ 'Duis aute irure dolor in reprehenderit in voluptate velit', 9 | \ 'esse cillum dolore eu fugiat nulla pariatur. Excepteur sint', 10 | \ 'occaecat cupidatat non proident, sunt in culpa qui officia', 11 | \ 'deserunt mollit anim id est laborum.', 12 | \ ] 13 | 14 | function! FillBuffer() 15 | put =['', ''] + g:filler_line + ['', ''] 16 | 1 delete _ 17 | endfunction 18 | 19 | describe '(textobj-entire-a)' 20 | before 21 | new 22 | call FillBuffer() 23 | end 24 | 25 | after 26 | close! 27 | end 28 | 29 | it 'does not change the jumplist' 30 | normal! 3gg 31 | normal! 5gg 32 | normal! 7gg 33 | normal! 11gg 34 | 35 | execute 'normal' "y\(textobj-entire-a)" 36 | Expect line('.') == 1 37 | 38 | execute 'normal!' "\" 39 | Expect line('.') == 11 40 | 41 | execute 'normal!' "\" 42 | Expect line('.') == 7 43 | 44 | execute 'normal!' "\" 45 | Expect line('.') == 5 46 | 47 | execute 'normal!' "\" 48 | Expect line('.') == 3 49 | end 50 | end 51 | 52 | describe '(textobj-entire-i)' 53 | before 54 | new 55 | call FillBuffer() 56 | end 57 | 58 | after 59 | close! 60 | end 61 | 62 | it 'does not change the jumplist' 63 | normal! 2gg 64 | normal! 4gg 65 | normal! 6gg 66 | normal! 10gg 67 | 68 | execute 'normal' "y\(textobj-entire-i)" 69 | Expect line('.') == 3 70 | 71 | execute 'normal!' "\" 72 | Expect line('.') == 10 73 | 74 | execute 'normal!' "\" 75 | Expect line('.') == 6 76 | 77 | execute 'normal!' "\" 78 | Expect line('.') == 4 79 | 80 | execute 'normal!' "\" 81 | Expect line('.') == 2 82 | end 83 | end 84 | -------------------------------------------------------------------------------- /t/mark.vim: -------------------------------------------------------------------------------- 1 | runtime! plugin/textobj/entire.vim 2 | 3 | let g:filler_line = [ 4 | \ 'Lorem ipsum dolor sit amet, consectetur adipisicing elit,', 5 | \ 'sed do eiusmod tempor incididunt ut labore et dolore magna', 6 | \ 'aliqua. Ut enim ad minim veniam, quis nostrud exercitation', 7 | \ 'ullamco laboris nisi ut aliquip ex ea commodo consequat.', 8 | \ 'Duis aute irure dolor in reprehenderit in voluptate velit', 9 | \ 'esse cillum dolore eu fugiat nulla pariatur. Excepteur sint', 10 | \ 'occaecat cupidatat non proident, sunt in culpa qui officia', 11 | \ 'deserunt mollit anim id est laborum.', 12 | \ ] 13 | 14 | function! FillBuffer() 15 | put =['', ''] + g:filler_line + ['', ''] 16 | 1 delete _ 17 | endfunction 18 | 19 | describe '(textobj-entire-a)' 20 | before 21 | new 22 | call FillBuffer() 23 | end 24 | 25 | after 26 | close! 27 | end 28 | 29 | it 'marks the correct cursor column' 30 | normal! 5gg9| 31 | Expect [line('.'), col('.')] == [5, 9] 32 | 33 | execute 'normal' "y\(textobj-entire-a)" 34 | Expect [line('.'), col('.')] == [1, 1] 35 | 36 | execute 'normal!' "\" 37 | Expect [line('.'), col('.')] == [5, 9] 38 | end 39 | end 40 | 41 | describe '(textobj-entire-i)' 42 | before 43 | new 44 | call FillBuffer() 45 | end 46 | 47 | after 48 | close! 49 | end 50 | 51 | it 'marks the correct cursor column' 52 | normal! 5gg9| 53 | Expect [line('.'), col('.')] == [5, 9] 54 | 55 | execute 'normal' "y\(textobj-entire-i)" 56 | Expect [line('.'), col('.')] == [3, 1] 57 | 58 | execute 'normal!' "\" 59 | Expect [line('.'), col('.')] == [5, 9] 60 | end 61 | end 62 | --------------------------------------------------------------------------------