├── .gitignore ├── .travis.yml ├── Gemfile ├── Guardfile ├── MIT-LICENSE.txt ├── README.md ├── Rakefile ├── autoload ├── increment_activator.vim └── increment_activator │ ├── candidates.vim │ └── operator.vim ├── doc └── vim-increment-activator.txt ├── plugin └── increment_activator.vim ├── snapshot.gif └── test ├── integration ├── insert_mode_test.vim └── normal_mode_test.vim └── unit └── candidates_spec.vim /.gitignore: -------------------------------------------------------------------------------- 1 | tags 2 | doc/tags 3 | *.lock 4 | .vim-flavor 5 | *.un~ 6 | *.sw[op] 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: ruby 2 | rvm: 3 | - 2.2.3 4 | bundler_args: --without development 5 | 6 | sudo: false 7 | cache: bundler 8 | 9 | script: 10 | - rake ci 11 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | gem 'vim-flavor', '~> 2.2.1' 3 | 4 | group :development do 5 | gem 'guard' 6 | gem 'guard-rake' 7 | 8 | gem 'growl' # Runs on Mac OS X 9 | gem 'libnotify' # Runs on Linux, FreeBSD, OpenBSD and Solaris 10 | gem 'rb-notifu' # Runs on Windows 11 | end 12 | -------------------------------------------------------------------------------- /Guardfile: -------------------------------------------------------------------------------- 1 | guard 'rake', :task => 'test' do 2 | watch(%r{^(test|plugin|autoload)/.+$}) 3 | end 4 | -------------------------------------------------------------------------------- /MIT-LICENSE.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2013-2024 Takuya Nishigori, https://github.com/nishigori/increment-activator 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # IncrementActivator.vim 2 | 3 | [![Build Status](http://img.shields.io/travis/nishigori/increment-activator/master.svg?style=flat)](https://travis-ci.org/nishigori/increment-activator) 4 | [![MIT Licensed](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](https://raw.githubusercontent.com/nishigori/increment-activator/master/MIT-LICENSE.txt) 5 | 6 | ![v:version >= 702](https://img.shields.io/badge/v:version->=%20702-007F00.svg?style=flat) 7 | ![nvim --version >= 0.1.7](https://img.shields.io/badge/nvim%20----version->=%20NVIM%200.1.7-54a23d.svg?style=flat) 8 | ![Script Type: Utility](http://img.shields.io/badge/script%20type-utility-000000.svg?style=flat) 9 | 10 | The [Vim] powerful increment plugin 11 | 12 | The behavior is like ``, `` increment or decrement number by the default [Vim][] 13 | 14 | It has been enhanced to allow increment the list that you have defined 15 | 16 | ![SnapShot - IncrementActivator.vim](snapshot.gif) 17 | 18 | [Vim]: http://vim.org/ 19 | 20 | ## Installation 21 | 22 | ### Using [dein.vim](https://github.com/Shougo/dein.vim) 23 | 24 | ```viml 25 | call dein#add('nishigori/increment-activator') 26 | ``` 27 | 28 | If you hope to do other approach, Please read more [Documentation](doc/vim-increment-activator.txt) 29 | 30 | ## Usage 31 | 32 | ### Kay map 33 | 34 | On **Normal-mode**, This plugin defines the following key mapping automatically `` & `` 35 | 36 | If you don't want there key mappings, please write on vimrc 37 | 38 | ```viml 39 | let g:increment_activator_no_default_key_mappings = 1 40 | 41 | " e.g) Original key mappings 42 | nmap ab (increment-activator-increment) 43 | nmap az (increment-activator-decrement) 44 | ``` 45 | 46 | If you want to be enabled to other `mode()`, please define map like this. 47 | 48 | ```viml 49 | " Be enabled on insert-mode 50 | imap (increment-activator-increment) 51 | imap (increment-activator-decrement) 52 | ``` 53 | 54 | ### Case of candidates for increment 55 | 56 | The list will be generated in candidates patterns automatically 57 | 58 | * no changes 59 | * lower 60 | * UPPER 61 | * Capitalize 62 | 63 | ### Default list defined by plugin 64 | 65 | * yes/no 66 | * on/off 67 | * true/false 68 | * weekday (sunday <-> monday <-> wednesday <- ... -> saturday <-> sunday) 69 | * weekday-shorten (sun <-> mon <- ... -> sat <-> sun) 70 | * month (january <-> february <- ... -> december <-> january) 71 | * month-shorten (jan <-> feb <- ... -> dec <-> jan) 72 | 73 | If you want to disable default candidates, puts on vimrc 74 | 75 | ```viml 76 | let g:increment_activator_no_default_candidates = 1 77 | ``` 78 | 79 | ### Customization 80 | 81 | You can define original list for increment / decrement :) 82 | 83 | Type of `g:increment_activator_filetype_candidates` is dict. each key is Vim's filetype. 84 | 85 | The candidates for priority is - 86 | 87 | 1. Current filetype (`&filetype`) 88 | 2. `_` key (`_` is special as apply to all filetypes) 89 | 3. number by default Vim 90 | 91 | *Example $MYVIMRC:* 92 | 93 | ```viml 94 | let g:increment_activator_filetype_candidates = { 95 | \ '_' : [ 96 | \ ['Pythonista', 'PHPer', 'Gopher'], 97 | \ ['ぬるぽ', 'ガッ'], 98 | \ ['info', 'warning', 'notice', 'error'], 99 | \ ], 100 | \ 'cucumber': [ 101 | \ ['Given', 'And', 'When', 'Then'], 102 | \ ], 103 | \ 'erlang': [ 104 | \ ['module', 'export'], 105 | \ [ 106 | \ 'is_alive', 'is_atom', 'is_binary', 'is_bitstring', 107 | \ 'is_boolean', 'is_float', 'is_function', 108 | \ 'is_integer', 'is_list', 'is_number', 109 | \ 'is_pid', 'is_port', 'is_process_alive', 110 | \ 'is_record', 'is_reference', 'is_tuple', 111 | \ ], 112 | \ ], 113 | \ 'git-rebase-todo': [ 114 | \ ['pick', 'reword', 'edit', 'squash', 'fixup', 'exec'], 115 | \ ], 116 | \ 'go': [ 117 | \ ['true', 'false', 'iota', 'nil'], 118 | \ ['byte', 'complex64', 'complex128'], 119 | \ ['int', 'int8', 'int16', 'int32', 'int64'], 120 | \ ['uint', 'uint8', 'uint16', 'uint32', 'uint64'], 121 | \ ['float32', 'float64'], 122 | \ ['interface', 'struct'], 123 | \ ], 124 | \ } 125 | ``` 126 | 127 | More than, Please read [Documentation](doc/vim-increment-activator.txt) 128 | 129 | ## Author 130 | 131 | * [Takuya Nishigori](http://github.com/nishigori) 132 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env rake 2 | 3 | task :default => [:test] 4 | 5 | task :ci => [:dump, :test] 6 | 7 | task :dump do 8 | sh 'vim --version' 9 | end 10 | 11 | task :test do 12 | sh 'bundle exec vim-flavor test test/**' 13 | end 14 | 15 | -------------------------------------------------------------------------------- /autoload/increment_activator.vim: -------------------------------------------------------------------------------- 1 | "============================================================================= 2 | " PACKAGE: IncrementActivator.vim 3 | " FILE: autoload/increment_activator.vim 4 | " AUTHOR: Takuya Nishigori 5 | " License: MIT license {{{ 6 | " Permission is hereby granted, free of charge, to any person obtaining 7 | " a copy of this software and associated documentation files (the 8 | " "Software"), to deal in the Software without restriction, including 9 | " without limitation the rights to use, copy, modify, merge, publish, 10 | " distribute, sublicense, and/or sell copies of the Software, and to 11 | " permit persons to whom the Software is furnished to do so, subject to 12 | " the following conditions: 13 | " 14 | " The above copyright notice and this permission notice shall be included 15 | " in all copies or substantial portions of the Software. 16 | " 17 | " THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | " OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | " MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | " IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | " CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | " TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | " SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | " }}} 25 | "============================================================================= 26 | " vim:set fdm=marker ts=2 sw=2 sts=0: 27 | 28 | function! increment_activator#increment() " {{{ 29 | call increment_activator#operator#applies('increment') 30 | endfunction " }}} 31 | 32 | function! increment_activator#decrement() " {{{ 33 | call increment_activator#operator#applies('decrement') 34 | endfunction " }}} 35 | -------------------------------------------------------------------------------- /autoload/increment_activator/candidates.vim: -------------------------------------------------------------------------------- 1 | "============================================================================= 2 | " PACKAGE: IncrementActivator.vim 3 | " FILE: autoload/increment_activator/candidates.vim 4 | " AUTHOR: Takuya Nishigori 5 | " License: MIT license {{{ 6 | " Permission is hereby granted, free of charge, to any person obtaining 7 | " a copy of this software and associated documentation files (the 8 | " "Software"), to deal in the Software without restriction, including 9 | " without limitation the rights to use, copy, modify, merge, publish, 10 | " distribute, sublicense, and/or sell copies of the Software, and to 11 | " permit persons to whom the Software is furnished to do so, subject to 12 | " the following conditions: 13 | " 14 | " The above copyright notice and this permission notice shall be included 15 | " in all copies or substantial portions of the Software. 16 | " 17 | " THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | " OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | " MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | " IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | " CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | " TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | " SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | " }}} 25 | "============================================================================= 26 | " vim:set fdm=marker ts=2 sw=2 sts=0: 27 | 28 | let s:candidates = {} 29 | 30 | let s:default_candidates_lists = [ 31 | \ ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'], 32 | \ ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'], 33 | \ ['jan', 'feb', 'mar', 'apr', 'may', 'june', 'july', 'aug', 'sep', 'oct', 'nov', 'dec'], 34 | \ ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'], 35 | \ ['true', 'false'], 36 | \ ['yes', 'no'], 37 | \ ['on', 'off'], 38 | \ ] 39 | 40 | 41 | function! s:generate_word_types(word) " {{{ 42 | let lower = tolower(a:word) 43 | let UPPER = toupper(a:word) 44 | let Capitalization = matchstr(UPPER, '.') . matchstr(lower, '^.\zs.*') 45 | 46 | return [a:word, lower, UPPER, Capitalization] 47 | endfunction " }}} 48 | 49 | function! s:generate(from_lists) " {{{ 50 | let candidates = {} 51 | for word_list in a:from_lists 52 | " Prepared in advence for looping first 53 | let previous_word_types = s:generate_word_types(word_list[-1]) 54 | let current_word_types = s:generate_word_types(word_list[0]) 55 | 56 | let length = len(word_list) 57 | let index = 1 58 | for current_word in word_list 59 | let next_word = index != length ? word_list[index] : word_list[0] 60 | let next_word_types = s:generate_word_types(next_word) 61 | 62 | let w = 0 63 | while w < len(current_word_types) 64 | let candidates[current_word_types[w]] = 65 | \ [ previous_word_types[w], next_word_types[w] ] 66 | let w+= 1 67 | endwhile 68 | 69 | " Prepared in advance for looping next 70 | let previous_word_types = current_word_types 71 | let current_word_types = next_word_types 72 | 73 | let index += 1 74 | endfor 75 | endfor 76 | 77 | return candidates 78 | endfunction " }}} 79 | 80 | function! s:generate_file_alltype() " {{{ 81 | if !has_key(s:candidates, '_') 82 | let l:user_defines_list = has_key(g:increment_activator_filetype_candidates, '_') 83 | \ ? copy(g:increment_activator_filetype_candidates['_']) : [] 84 | let l:plugin_defines_list = !g:increment_activator_no_default_candidates 85 | \ ? copy(s:default_candidates_lists) : [] 86 | let s:candidates['_'] = s:generate(extend(l:plugin_defines_list, l:user_defines_list)) 87 | endif 88 | 89 | return s:candidates['_'] 90 | endfunction " }}} 91 | 92 | function! increment_activator#candidates#generate(to_filetype) " {{{ 93 | let file_type = empty(a:to_filetype) ? '_' : a:to_filetype 94 | if !has_key(s:candidates, file_type) 95 | let l:alltype_list = copy(s:generate_file_alltype()) 96 | let l:user_defines_list = has_key(g:increment_activator_filetype_candidates, file_type) 97 | \ ? g:increment_activator_filetype_candidates[file_type] : [] 98 | let s:candidates[file_type] = extend(l:alltype_list, s:generate(user_defines_list)) 99 | endif 100 | 101 | return s:candidates[file_type] 102 | endfunction " }}} 103 | 104 | function! increment_activator#candidates#clear() " {{{ 105 | let s:candidates = {} 106 | endfunction " }}} 107 | -------------------------------------------------------------------------------- /autoload/increment_activator/operator.vim: -------------------------------------------------------------------------------- 1 | "============================================================================= 2 | " PACKAGE: IncrementActivator.vim 3 | " FILE: autoload/increment_activator/operator.vim 4 | " AUTHOR: Takuya Nishigori 5 | " License: MIT license {{{ 6 | " Permission is hereby granted, free of charge, to any person obtaining 7 | " a copy of this software and associated documentation files (the 8 | " "Software"), to deal in the Software without restriction, including 9 | " without limitation the rights to use, copy, modify, merge, publish, 10 | " distribute, sublicense, and/or sell copies of the Software, and to 11 | " permit persons to whom the Software is furnished to do so, subject to 12 | " the following conditions: 13 | " 14 | " The above copyright notice and this permission notice shall be included 15 | " in all copies or substantial portions of the Software. 16 | " 17 | " THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | " OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | " MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | " IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | " CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | " TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | " SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | " }}} 25 | "============================================================================= 26 | " vim:set fdm=marker ts=2 sw=2 sts=0: 27 | 28 | let s:operation_identifier_map = { 29 | \ 'decrement': [0, "\"], 30 | \ 'increment': [1, "\"], 31 | \ } 32 | 33 | function! s:create_changable_word_cmd() " {{{ 34 | if matchstr(getline('.'), '.', col('.') - 1) == ' ' 35 | return 'wciw' " Jump to without white-spaces 36 | endif 37 | 38 | return 'ciw' 39 | endfunction " }}} 40 | 41 | function! increment_activator#operator#get_currently_word() " {{{ 42 | " TODO: In future, it has been enhanced to allow many (date, datetime, ..) 43 | return expand('') 44 | endfunction " }}} 45 | 46 | function! increment_activator#operator#applies(identifier_key) " {{{ 47 | let increment_identifiers = s:operation_identifier_map[a:identifier_key] 48 | let candidates = increment_activator#candidates#generate(&filetype) 49 | let cmd_count = (v:count < 1) ? 1 : v:count 50 | let i = 0 51 | while i < cmd_count 52 | let w = increment_activator#operator#get_currently_word() 53 | let exec_command = has_key(candidates, w) 54 | \ ? s:create_changable_word_cmd() . candidates[w][increment_identifiers[0]] 55 | \ : increment_identifiers[1] 56 | silent execute "normal! " . exec_command 57 | let i = i + 1 58 | endwhile 59 | endfunction " }}} 60 | -------------------------------------------------------------------------------- /doc/vim-increment-activator.txt: -------------------------------------------------------------------------------- 1 | *increment-activator.txt* Utility that increment to cursor or select 2 | 3 | CONTENTS *increment-activator-contents* 4 | 5 | Overview................................|increment-activator-overview| 6 | Installation............................|increment-activator-installation| 7 | Interface...............................|increment-activator-interface| 8 | Variables...........................|increment-activator-variables| 9 | Key Mappings........................|increment-activator-key-mappings| 10 | Issues..................................|increment-activator-issues| 11 | Changelog...............................|increment-activator-changelog| 12 | License.................................|increment-activator-license| 13 | 14 | ============================================================================== 15 | OVERVIEW *increment-activator-overview* 16 | 17 | *increment-activator* (IncrementActivator.vim) is powerful increment activator. 18 | 19 | The behavior is like , (in|de)crement current number 20 | by the default Vim's key-map. 21 | 22 | It has been enhanced to allow increment the list that you have defined. 23 | 24 | The list defined by you is auto generate to candidates. 25 | 26 | For exam, case of private, protected, puBlic 27 | generated candidates to 28 | * no change 29 | * lower (private, protected, public) 30 | * UPPER (PRIVATE, PROTECTED, PUBLIC) 31 | * Capitalize (Private, Protected, Public) 32 | 33 | ============================================================================== 34 | INSTALLATION *increment-activator-installation* 35 | 36 | Pre-Requirements 37 | 38 | - Vim version 7.2 or above 39 | 40 | Using Package Manager: 41 | 42 | Case NeoBundle.vim: > 43 | NeoBundle 'nishigori/increment-activator' 44 | < 45 | Case Vundle: > 46 | Bundle 'nishigori/increment-activator' 47 | < 48 | Getting Manual: 49 | 50 | 1. Get the plugin package 51 | 2. Extract the files and put them in your Vim directory 52 | (usually ~/.vim/ or Program Files/Vim/vimfiles on Windows). 53 | 54 | ============================================================================== 55 | INTERFACE *increment-activator-interface* 56 | 57 | ------------------------------------------------------------------------------ 58 | FUNCTIONS *increment-activator-functions* 59 | 60 | increment_activator#increment() *increment_activator#increment* 61 | Apply to increment currently word. 62 | 63 | increment_activator#decrement() *increment_activator#decrement* 64 | Apply to decrement currently word. 65 | 66 | *increment_activator#candidates#generate* 67 | increment_activator#candidates#generate({filetype}) 68 | 69 | increment_activator#candidates#clear() *increment_activator#candidates#clear* 70 | Clear to generated candidates of all. 71 | 72 | ------------------------------------------------------------------------------ 73 | VARIABLES *increment-activator-variables* 74 | 75 | *g:increment-activator_filetype_candidates* 76 | g:increment_activator_filetype_candidates 77 | Type of dictionary. 78 | Keys is ('_' is filetype of all). 79 | Value is lists (nested the list). 80 | 81 | The candidates for priority is - 82 | 83 | 1. Current filetype (`&filetype`) 84 | 2. `_` key (`_` is special as apply to all filetypes) 85 | 3. number by default Vim 86 | 87 | Example: 88 | > 89 | let g:increment_activator_filetype_candidates = 90 | \ { 91 | \ '_': [ 92 | \ ['info', 'warning', 'notice', 'error'], 93 | \ ['Pythonista', 'PHPer', 'Gopher'], 94 | \ ['ぬるぽ', 'ガッ'], 95 | \ ], 96 | \ 'erlang': [ 97 | \ ['module', 'export'], 98 | \ [ 99 | \ 'is_alive', 'is_atom', 'is_binary', 'is_bitstring', 100 | \ 'is_boolean', 'is_float', 'is_function', 101 | \ 'is_integer', 'is_list', 'is_number', 102 | \ 'is_pid', 'is_port', 'is_process_alive', 103 | \ 'is_record', 'is_reference', 'is_tuple', 104 | \ ], 105 | \ ], 106 | \ 'git-rebase-todo': [ 107 | \ ['pick', 'reword', 'edit', 'squash', 'fixup', 'exec'], 108 | \ ], 109 | \ 'go': [ 110 | \ ['true', 'false', 'iota', 'nil'], 111 | \ ['byte', 'complex64', 'complex128'], 112 | \ ['int', 'int8', 'int16', 'int32', 'int64'], 113 | \ ['uint', 'uint8', 'uint16', 'uint32', 'uint64'], 114 | \ ['float32', 'float64'], 115 | \ ['interface', 'struct'], 116 | \ ], 117 | \ } 118 | < 119 | Defaults to "{}". 120 | 121 | g:increment_activator#config *g:increment-activator_config* 122 | This variable is deprecated. 123 | Please use g:increment_activator_filetype_candidates 124 | 125 | *g:increment_activator#no_default_candidates* 126 | g:increment_activator_no_default_candidates 127 | This plugin will use candicates that defined by plugin for increment. 128 | If you don't want there candicates, 129 | define g:increment_activator_no_default_candidates to 1. 130 | before plugin loaded. 131 | 132 | Candidates defined by plugin: 133 | 134 | * sun, mon, tue, wed, thu, fri, sat 135 | * sunday, monday, tuesday, ... saturday 136 | * jan, feb, mar, apr, may, ... dec 137 | * january, february, march, ... december 138 | * true, false 139 | * yes no 140 | * on, off 141 | > 142 | let g:increment_activator_no_default_candidates = 1 143 | < 144 | Defaults to 0. 145 | 146 | g:increment_activator_no_default_key_mappings 147 | *g:increment_activator_no_default_key_mappings* 148 | This plugin will define the following key mapping automatically. 149 | If you don't want there key mappings (, ), 150 | define |g:increment_activator_no_default_key_mappings| to 1. 151 | before this plugin loaded. 152 | > 153 | let g:increment_activator_no_default_key_mappings = 1 154 | < 155 | Defaults to 0. 156 | 157 | ------------------------------------------------------------------------------ 158 | KEY MAPPINGS *increment-activator-key-mappings* 159 | 160 | This plugin will define the following |Normal-mode| key map automatically. 161 | In other |mode()|, you must define key maps. 162 | 163 | Example for custom key mappings: 164 | > 165 | " Normal-mode: customized 166 | let g:increment_activator_no_default_key_mappings = 1 167 | nmap ab (increment-activator-increment) 168 | nmap az (increment-activator-decrement) 169 | 170 | " Insert-mode 171 | imap (increment-activator-increment) 172 | imap (increment-activator-decrement) 173 | < 174 | 175 | (increment-activator-increment) *(increment-activator-increment)* 176 | Applies to increment currently word. 177 | It supports on |Normal-mode|, |Insert-mode|. 178 | 179 | (increment-activator-decrement) *(increment-activator-decrement)* 180 | Applies to decrement currently word. 181 | It supports on |Normal-mode|, |Insert-mode|. 182 | 183 | ============================================================================== 184 | ISSUES *increment-activator-issues* 185 | 186 | This plugin is under the management of Github. 187 | 188 | https://github.com/nishigori/increment-activator/issues 189 | 190 | Are you having any the problem, question, or idea ? Please add issue !! 191 | 192 | ============================================================================== 193 | CHANGLOG *increment-activator-changelog* 194 | 195 | To get the diff between two versions, go to - 196 | https://github.com/nishigori/increment-activator/compare/VERSION...VERSION 197 | 198 | 0.1.0 Sun Jun 29 19:59:53 2014 +0900 *increment-activator-cahngelog-0.1.0* 199 | - Change variable name from 'increment_activator#config' to - 200 | 'increment_activator_filetype_candidates' 201 | - [GH-6] Fix increment not expect multiple line 202 | 203 | 0.0.2 Tue Jan 14 08:02:55 2014 +0900 *increment-activator-cahngelog-0.0.2* 204 | - Support insert-mode 205 | - Fix E154 'duplicate tag 'increment-activator' 206 | 207 | 0.0.1 Sat Jan 4 06:24:23 2014 +0900 *increment-activator-changelog-0.0.1* 208 | - First release. 209 | - Feature inherited https://github.com/nishigori/vim-sunday 210 | - Support candidates of filetype definition 211 | - define able no use default key mappings 212 | - define able no use candidates created by plugin 213 | 214 | 215 | ============================================================================== 216 | LICENSE *increment-activator-license* 217 | 218 | Copyright 2013-2014 by Takuya Nishigori 219 | 220 | Permission is hereby granted, free of charge, to any person obtaining 221 | a copy of this software and associated documentation files (the 222 | "Software"), to deal in the Software without restriction, including 223 | without limitation the rights to use, copy, modify, merge, publish, 224 | distribute, sublicense, and/or sell copies of the Software, and to 225 | permit persons to whom the Software is furnished to do so, subject to 226 | the following conditions: 227 | 228 | The above copyright notice and this permission notice shall be included 229 | in all copies or substantial portions of the Software. 230 | 231 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 232 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 233 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 234 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 235 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 236 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 237 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 238 | 239 | ============================================================================== 240 | vim:tw=78:ts=8:ft=help:norl:noet:fen: 241 | -------------------------------------------------------------------------------- /plugin/increment_activator.vim: -------------------------------------------------------------------------------- 1 | "============================================================================= 2 | " PACKAGE: IncrementActivator.vim 3 | " FILE: plugin/increment_activator.vim 4 | " AUTHOR: Takuya Nishigori 5 | " License: MIT license {{{ 6 | " Permission is hereby granted, free of charge, to any person obtaining 7 | " a copy of this software and associated documentation files (the 8 | " "Software"), to deal in the Software without restriction, including 9 | " without limitation the rights to use, copy, modify, merge, publish, 10 | " distribute, sublicense, and/or sell copies of the Software, and to 11 | " permit persons to whom the Software is furnished to do so, subject to 12 | " the following conditions: 13 | " 14 | " The above copyright notice and this permission notice shall be included 15 | " in all copies or substantial portions of the Software. 16 | " 17 | " THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | " OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | " MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | " IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | " CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | " TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | " SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | " }}} 25 | "============================================================================= 26 | " vim:set fdm=marker ts=2 sw=2 sts=0: 27 | 28 | " Load Once {{{ 29 | if v:version < 702 30 | echoerr 'IncrementActivator.vim does not supported version Vim (' . v:version . ').' 31 | finish 32 | elseif exists('g:loaded_increment_activator') 33 | finish 34 | endif 35 | " }}} 36 | 37 | let s:save_cpo = &cpo 38 | set cpo&vim 39 | 40 | if exists('g:increment_activator#config') 41 | let s:deprecated_msg = 'g:increment_activator#config is deprecated.' 42 | \ . ' Please use g:increment_activator_filetype_candidates.' 43 | echohl WarningMsg | echomsg s:deprecated_msg | echohl None 44 | endif 45 | 46 | " Global options definition " {{{ 47 | let g:increment_activator_no_default_candidates = 48 | \ get(g:, 'increment_activator_no_default_candidates', 0) 49 | let g:increment_activator_no_default_key_mappings = 50 | \ get(g:, 'increment_activator_no_default_key_mappings', 0) 51 | 52 | let g:increment_activator_filetype_candidates = 53 | \ get(g:, 'increment_activator_filetype_candidates', {}) 54 | " }}} 55 | 56 | " Default Key mapping {{{ 57 | nnoremap (increment-activator-increment) 58 | \ :call increment_activator#increment() 59 | nnoremap (increment-activator-decrement) 60 | \ :call increment_activator#decrement() 61 | inoremap (increment-activator-increment) 62 | \ :call increment_activator#increment() 63 | inoremap (increment-activator-decrement) 64 | \ :call increment_activator#decrement() 65 | 66 | if !g:increment_activator_no_default_key_mappings 67 | nmap (increment-activator-increment) 68 | nmap (increment-activator-decrement) 69 | endif 70 | " }}} 71 | 72 | let g:loaded_increment_activator = 1 73 | let &cpo = s:save_cpo 74 | unlet s:save_cpo 75 | -------------------------------------------------------------------------------- /snapshot.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nishigori/increment-activator/b49fc24094f93aa29a7592034b97095b709c3528/snapshot.gif -------------------------------------------------------------------------------- /test/integration/insert_mode_test.vim: -------------------------------------------------------------------------------- 1 | source plugin/increment_activator.vim 2 | 3 | describe 'default increment' 4 | before 5 | " Define map for insert-mode 6 | imap (increment-activator-increment) 7 | imap (increment-activator-decrement) 8 | end 9 | 10 | after 11 | inoremap 12 | inoremap 13 | execute 'normal! 1GdG' | " Delete all line 14 | call increment_activator#candidates#clear() 15 | end 16 | 17 | it 'can increment number' 18 | execute "normal I1\" 19 | Expect getline(1) == '2' 20 | 21 | execute "normal I\\\" 22 | Expect getline(1) == '-1' 23 | end 24 | 25 | it 'can increment weekday of currently word' 26 | execute "normal Imonday\" 27 | Expect getline(1) == 'tuesday' 28 | end 29 | 30 | it 'can decrement weekday of currently word' 31 | execute "normal Isunday\" 32 | Expect getline(1) == 'saturday' 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /test/integration/normal_mode_test.vim: -------------------------------------------------------------------------------- 1 | source plugin/increment_activator.vim 2 | 3 | describe 'default increment' 4 | 5 | after 6 | execute 'normal 1GdG' | " Delete all line 7 | end 8 | 9 | it 'can increment weekday of currently word' 10 | put! = 'monday' 11 | execute "normal \" 12 | Expect getline(1) == 'tuesday' 13 | end 14 | 15 | it 'can decrement weekday of currently word' 16 | put! = 'sunday' 17 | execute "normal \" 18 | Expect getline(1) == 'saturday' 19 | end 20 | 21 | it 'can increment/decrement number by the default vim behavior' 22 | execute 'normal I1' 23 | execute "normal \" 24 | Expect getline(1) == '2' 25 | 26 | execute "normal \" 27 | execute "normal \" 28 | execute "normal \" 29 | Expect getline(1) == '-1' 30 | end 31 | 32 | end 33 | 34 | describe 'increment target only current line' 35 | 36 | before 37 | put! = 'sunday' " Line3 38 | put! = '1' " Line2 39 | put! = 'sun' " Line1 40 | 41 | " Increment 42 | 2 " Move to line 2 43 | execute "normal \\\" 44 | end 45 | 46 | after 47 | execute 'normal 1GdG' | " Delete all line 48 | end 49 | 50 | it 'should increment currnetly line' 51 | Expect getline(2) == '4' 52 | end 53 | 54 | it 'should not increment next line' 55 | Expect getline(1) == 'sun' 56 | end 57 | 58 | it 'should not increment previous line' 59 | Expect getline(3) == 'sunday' 60 | end 61 | 62 | end 63 | -------------------------------------------------------------------------------- /test/unit/candidates_spec.vim: -------------------------------------------------------------------------------- 1 | source plugin/increment_activator.vim 2 | 3 | function! s:CleanUp() 4 | let g:increment_activator_no_default_candidates = 0 " By the default 5 | call increment_activator#candidates#clear() 6 | endfunction 7 | 8 | describe 'Candidates generation' 9 | 10 | describe 'Default definition' 11 | 12 | before 13 | let g:candidates = increment_activator#candidates#generate('') 14 | end 15 | 16 | after 17 | unlet g:candidates 18 | call s:CleanUp() 19 | end 20 | 21 | it 'should generates case of lower' 22 | Expect has_key(g:candidates, 'sunday') to_be_true 23 | end 24 | 25 | it 'should generates case of UPPER' 26 | Expect has_key(g:candidates, 'SUNDAY') to_be_true 27 | end 28 | 29 | it 'should generates case of Capitalize' 30 | Expect has_key(g:candidates, 'Sunday') to_be_true 31 | end 32 | 33 | end 34 | 35 | describe 'User definition' 36 | 37 | before 38 | let g:increment_activator_filetype_candidates = { 39 | \ '_': [ 40 | \ ['GoodMorning', 'GoodEvening'], 41 | \ ], 42 | \ } 43 | end 44 | 45 | after 46 | call s:CleanUp() 47 | end 48 | 49 | it 'should not defines default candidates' 50 | let g:increment_activator_no_default_candidates = 1 51 | Expect has_key(increment_activator#candidates#generate(''), 'sunday') to_be_false 52 | end 53 | 54 | it 'should include filetype of all' 55 | Expect has_key(increment_activator#candidates#generate(''), 'GoodMorning') to_be_true 56 | end 57 | 58 | end 59 | 60 | describe 'Filetype definition' 61 | 62 | before 63 | let g:increment_activator_filetype_candidates = { 64 | \ 'vim': [ 65 | \ ['augroup', 'autocmd'], 66 | \ ['paste', 'nopaste'], 67 | \ ], 68 | \ 'ruby': [ 69 | \ ['describe', 'context'], 70 | \ ], 71 | \ } 72 | end 73 | 74 | after 75 | call s:CleanUp() 76 | end 77 | 78 | it 'should includes filetype' 79 | Expect has_key(increment_activator#candidates#generate('vim'), 'autocmd') to_be_true 80 | end 81 | 82 | it 'should not includes other filetype' 83 | Expect has_key(increment_activator#candidates#generate('ruby'), 'autocmd') to_be_false 84 | end 85 | 86 | end 87 | 88 | end 89 | --------------------------------------------------------------------------------