├── VimFlavor ├── doc └── textobj-diff.txt └── plugin └── textobj └── diff.vim /VimFlavor: -------------------------------------------------------------------------------- 1 | flavor 'kana/vim-textobj-user', '~> 0.3' 2 | -------------------------------------------------------------------------------- /doc/textobj-diff.txt: -------------------------------------------------------------------------------- 1 | *textobj-diff.txt* Text objects for ouputs of diff(1) 2 | 3 | Version 0.0.2 4 | Script ID: 2415 5 | Copyright (C) 2008-2013 Kana Natsuno 6 | License: So-called MIT/X 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-diff-contents* 28 | 29 | Introduction |textobj-diff-introduction| 30 | Interface |textobj-diff-interface| 31 | Key Mapings |textobj-diff-key-mappings| 32 | Customizing |textobj-diff-customizing| 33 | Bugs |textobj-diff-bugs| 34 | Changelog |textobj-diff-changelog| 35 | 36 | 37 | 38 | 39 | ============================================================================== 40 | INTRODUCTION *textobj-diff-introduction* 41 | 42 | *textobj-diff* is a Vim plugin to provide text objects for outputs of diff(1). 43 | Currently it supports the following formats: 44 | - diff --context 45 | - diff --unified 46 | - git diff 47 | 48 | 49 | Requirements: 50 | - Vim 7.2 or later 51 | - |textobj-user| 0.3.7 or later (vimscript#2100) 52 | 53 | Installation: 54 | - Recommended way: Use vim-flavor . 55 | 56 | Latest version: 57 | https://github.com/kana/vim-textobj-diff 58 | 59 | Document in HTML format: 60 | http://vim-doc.heroku.com/view?https://github.com/kana/vim-textobj-diff/blob/master/doc/textobj-diff.txt 61 | 62 | 63 | 64 | 65 | ============================================================================== 66 | INTERFACE *textobj-diff-interface* 67 | 68 | ------------------------------------------------------------------------------ 69 | MAPPINGS *textobj-diff-mappings* 70 | 71 | (textobj-diff-file-n) *(textobj-diff-file-n)* 72 | (textobj-diff-file-p) *(textobj-diff-file-p)* 73 | Move to the beginning of the next/previous header of files. 74 | 75 | (textobj-diff-file-N) *(textobj-diff-file-N)* 76 | (textobj-diff-file-P) *(textobj-diff-file-P)* 77 | Move to the end of the next/previous header of files. 78 | 79 | (textobj-diff-hunk-n) *(textobj-diff-hunk-n)* 80 | (textobj-diff-hunk-p) *(textobj-diff-hunk-p)* 81 | (textobj-diff-hunk-N) *(textobj-diff-hunk-N)* 82 | (textobj-diff-hunk-P) *(textobj-diff-hunk-P)* 83 | Like |(textobj-diff-file-n)| and others, but move to an 84 | appropriate part of a hunk. 85 | 86 | (textobj-diff-file) *(textobj-diff-file)* 87 | Select all hunks and the header of the next/previous files. 88 | 89 | (textobj-diff-hunk) *(textobj-diff-hunk)* 90 | Select the next/previous hunk. 91 | 92 | 93 | 94 | 95 | ============================================================================== 96 | CUSTOMIZING *textobj-diff-customizing* 97 | 98 | *g:textobj_diff_no_default_key_mappings* 99 | *:TextobjDiffDefaultKeyMappings* 100 | This plugin will define the following key mappings in Normal mode, Visual mode 101 | and Operator-pending mode automatically. If you don't want these key 102 | mappings, define |g:textobj_diff_no_default_key_mappings| before this plugin 103 | is loaded (e.g. in $MYVIMRC). You can also use 104 | |:TextobjDiffDefaultKeyMappings| to redefine these key mappings. 105 | 106 | mode {lhs} {rhs} ~ 107 | ---- ----- ------------------------------ ~ 108 | NVO dfJ (textobj-diff-file-N) 109 | NVO dfK (textobj-diff-file-P) 110 | NVO dfj (textobj-diff-file-n) 111 | NVO dfk (textobj-diff-file-p) 112 | NVO dJ (textobj-diff-hunk-N) 113 | NVO dK (textobj-diff-hunk-P) 114 | NVO dj (textobj-diff-hunk-n) 115 | NVO dk (textobj-diff-hunk-p) 116 | VO adH (textobj-diff-file) 117 | VO adf (textobj-diff-file) 118 | VO adh (textobj-diff-hunk) 119 | VO idH (textobj-diff-file) 120 | VO idf (textobj-diff-file) 121 | VO idh (textobj-diff-hunk) 122 | 123 | 124 | 125 | 126 | ============================================================================== 127 | BUGS *textobj-diff-bugs* 128 | 129 | - There are many bugs around the world. 130 | 131 | 132 | 133 | 134 | ============================================================================== 135 | CHANGELOG *textobj-diff-changelog* 136 | 137 | 0.0.2 2013-01-06T15:15:27+09:00 *textobj-diff-changelog-0.0.2* 138 | - Support vim-flavor . 139 | - Update |textobj-diff-introduction|. 140 | 141 | 0.0.1 2012-03-24T14:36:14+09:00 *textobj-diff-changelog-0.0.1* 142 | - Refine the document a bit. 143 | - Refine the internal structure a bit. 144 | 145 | 0.0.0 2008-10-23T14:19:46+09:00 *textobj-diff-changelog-0.0.0* 146 | - Initial version. 147 | 148 | 149 | 150 | 151 | ============================================================================== 152 | vim:tw=78:ts=8:ft=help:norl:fen:fdl=0:fdm=marker: 153 | -------------------------------------------------------------------------------- /plugin/textobj/diff.vim: -------------------------------------------------------------------------------- 1 | " textobj-diff - Text objects for ouputs of diff(1) 2 | " Version: 0.0.2 3 | " Copyright (C) 2008-2013 Kana Natsuno 4 | " License: So-called MIT/X 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_diff') 26 | finish 27 | endif 28 | 29 | 30 | 31 | 32 | let s:REGEXP_CONTEXT_FILE = '^' 33 | \ . '\*\*\* [^\t]\+\t.*\n' 34 | \ . '--- [^\t]\+\t.*\n' 35 | \ . '\_.\{-}' 36 | \ . '\ze\%(' 37 | \ . '\n\*\*\* [^\t]\+\t' 38 | \ . '\|' . '\%$' 39 | \ . '\)' 40 | let s:REGEXP_CONTEXT_HUNK = '^\*\{4,}\n' 41 | \ . '\_.\{-}' 42 | \ . '\ze\%(' 43 | \ . '\n\*\{3,}' 44 | \ . '\|' . '\%$' 45 | \ . '\)' 46 | 47 | let s:REGEXP_GIT_FILE = '^' 48 | \ . 'diff --git .*\n' 49 | \ . '\%([a-z].*\n\)\+' 50 | \ . '--- .*\n' 51 | \ . '+++ .*\n' 52 | \ . '\_.\{-}' 53 | \ . '\ze\%(' 54 | \ . '\ndiff --git' 55 | \ . '\|' . '\n--- ' 56 | \ . '\|' . '\%$' 57 | \ . '\)' 58 | let s:REGEXP_GIT_HUNK = '^@@ [^\t]\+ [^\t]\+ @@.*\n' 59 | \ . '\_.\{-}' 60 | \ . '\ze\%(' 61 | \ . '\n@@ [^\t]\+ [^\t]\+ @@.*\n' 62 | \ . '\|' . '\ndiff --git' 63 | \ . '\|' . '\n--- ' 64 | \ . '\|' . '\%$' 65 | \ . '\)' 66 | 67 | let s:REGEXP_UNIFIED_FILE = '^' 68 | \ . '--- [^\t]\+\t.*\n' 69 | \ . '+++ [^\t]\+\t.*\n' 70 | \ . '\_.\{-}' 71 | \ . '\ze\%(' 72 | \ . '\n--- [^\t]\+\t' 73 | \ . '\|' . '\%$' 74 | \ . '\)' 75 | let s:REGEXP_UNIFIED_HUNK = '^@@ [^\t]\+ [^\t]\+ @@.*\n' 76 | \ . '\_.\{-}' 77 | \ . '\ze\%(' 78 | \ . '\n@@ [^\t]\+ [^\t]\+ @@.*\n' 79 | \ . '\|' . '\n--- [^\t]\+\t' 80 | \ . '\|' . '\%$' 81 | \ . '\)' 82 | 83 | let s:REGEXP_AUTO_FILE = '\%(' 84 | \ . '\%(' . s:REGEXP_CONTEXT_FILE . '\)' 85 | \ . '\|' . '\%(' . s:REGEXP_GIT_FILE . '\)' 86 | \ . '\|' . '\%(' . s:REGEXP_UNIFIED_FILE . '\)' 87 | \ . '\)' 88 | let s:REGEXP_AUTO_HUNK = '\%(' 89 | \ . '\%(' . s:REGEXP_CONTEXT_HUNK . '\)' 90 | \ . '\|' . '\%(' . s:REGEXP_GIT_HUNK . '\)' 91 | \ . '\|' . '\%(' . s:REGEXP_UNIFIED_HUNK . '\)' 92 | \ . '\)' 93 | 94 | 95 | 96 | 97 | call textobj#user#plugin('diff', { 98 | \ 'file': { 99 | \ '*pattern*': s:REGEXP_AUTO_FILE, 100 | \ 'move-N': 'dfJ', 101 | \ 'move-P': 'dfK', 102 | \ 'move-n': 'dfj', 103 | \ 'move-p': 'dfk', 104 | \ 'select': ['adH', 'adf', 'idH', 'idf'], 105 | \ }, 106 | \ 'hunk': { 107 | \ '*pattern*': s:REGEXP_AUTO_HUNK, 108 | \ 'move-N': 'dJ', 109 | \ 'move-P': 'dK', 110 | \ 'move-n': 'dj', 111 | \ 'move-p': 'dk', 112 | \ 'select': ['adh', 'idh'], 113 | \ }, 114 | \ }) 115 | 116 | 117 | 118 | 119 | let g:loaded_textobj_diff = 1 120 | 121 | " __END__ 122 | " vim: foldmethod=marker 123 | --------------------------------------------------------------------------------