├── .gitignore
├── .travis.yml
├── Gemfile
├── Rakefile
├── VimFlavor
├── autoload
└── altercmd.vim
├── doc
└── altercmd.txt
├── plugin
└── altercmd.vim
└── t
└── basics.vim
/.gitignore:
--------------------------------------------------------------------------------
1 | .vim-flavor
2 | Gemfile.lock
3 | VimFlavor.lock
4 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: ruby
2 | rvm:
3 | - 2.1.5
4 | script: rake ci
5 |
--------------------------------------------------------------------------------
/Gemfile:
--------------------------------------------------------------------------------
1 | source 'https://rubygems.org'
2 |
3 | gem 'vim-flavor', '~> 2.0'
4 |
--------------------------------------------------------------------------------
/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 | # No dependencies.
2 |
--------------------------------------------------------------------------------
/autoload/altercmd.vim:
--------------------------------------------------------------------------------
1 | " altercmd - Alter built-in Ex commands by your own ones
2 | " Version: 0.0.1
3 | " Copyright (C) 2009-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! altercmd#define(...) "{{{2
26 | let [buffer, original_name, alternate_name]
27 | \ = (a:000[0] ==? '' ? [] : ['']) + a:000
28 |
29 | if original_name =~ '\['
30 | let [original_name_head, original_name_tail] = split(original_name, '[')
31 | let original_name_tail = substitute(original_name_tail, '\]', '', '')
32 | else
33 | let original_name_head = original_name
34 | let original_name_tail = ''
35 | endif
36 |
37 | let original_name_tail = ' ' . original_name_tail
38 | for i in range(len(original_name_tail))
39 | let lhs = original_name_head . original_name_tail[1:i]
40 | execute 'cnoreabbrev ' buffer lhs
41 | \ '(getcmdtype() == ":" && getcmdline() ==# "' . lhs . '")'
42 | \ '?' ('"' . alternate_name . '"')
43 | \ ':' ('"' . lhs . '"')
44 | endfor
45 | endfunction
46 |
47 |
48 |
49 |
50 | function! altercmd#load() "{{{2
51 | runtime plugin/altercmd.vim
52 | endfunction
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 | " __END__ "{{{1
62 | " vim: foldmethod=marker
63 |
--------------------------------------------------------------------------------
/doc/altercmd.txt:
--------------------------------------------------------------------------------
1 | *altercmd.txt* Alter built-in Ex commands by your own ones
2 |
3 | Version 0.0.1
4 | Script ID: 2675
5 | Copyright (C) 2009-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 *altercmd-contents*
28 |
29 | Introduction |altercmd-introduction|
30 | Interface |altercmd-interface|
31 | Commands |altercmd-commands|
32 | Functions |altercmd-functions|
33 | Bugs |altercmd-bugs|
34 | Changelog |altercmd-changelog|
35 |
36 |
37 |
38 |
39 | ==============================================================================
40 | INTRODUCTION *altercmd-introduction*
41 |
42 | *altercmd* is a Vim plugin to provide an easy way to alternate built-in Ex
43 | commands by user-defined Ex commands. This plugin provides |:AlterCommand|
44 | for this purpose. For example, if you define :CD, a custom version of |:cd|,
45 | add the following in your vimrc.
46 | >
47 | AlterCommand cd CD
48 | <
49 | With the above setting, you can use :cd as if it is :CD. It means that :CD
50 | will be automatically inserted if you type :cd as an Ex command, so you don't
51 | have to type :CD to use :cd and you'll never encounter mistyping :cd and :CD.
52 |
53 | :AlterCommand also supports partial command names. For example, |:help| can
54 | be invoked with :h, :he, :hel or :help.
55 | >
56 | AlterCommand h[elp] HELP
57 | <
58 | With the above setting, you can use :h, :he, :hel and :help as if they are
59 | :HELP, your own version of :help.
60 |
61 |
62 | Requirements:
63 | - Vim 7.2 or later
64 |
65 | Latest version:
66 | https://github.com/kana/vim-altercmd
67 |
68 |
69 |
70 |
71 | ==============================================================================
72 | INTERFACE *altercmd-interface*
73 |
74 | ------------------------------------------------------------------------------
75 | COMMANDS *altercmd-commands*
76 |
77 | *:AlterCommand*
78 | :AlterCommand [] {original} {alternative}
79 | Declare to use {alternative} Ex command instead of
80 | {original} Ex command.
81 |
82 | If is given, this declaration is only
83 | available for the current buffer. Otherwise, this
84 | declaration is available globally.
85 |
86 | See also |altercmd-introduction| for examples.
87 |
88 | Technically, this Ex command does just define some
89 | |abbreviations| in Command-line mode.
90 |
91 |
92 | ------------------------------------------------------------------------------
93 | FUNCTIONS *altercmd-functions*
94 |
95 | altercmd#define({original}, {alternative}) *altercmd#define()*
96 | altercmd#define('', {original}, {alternative})
97 | Function version of |:AlterCommand|.
98 |
99 | altercmd#load() *altercmd#load()*
100 | Load this plugin. You have to call this in your vimrc
101 | if you want to use |:AlterCommand| in your vimrc.
102 |
103 |
104 |
105 |
106 | ==============================================================================
107 | BUGS *altercmd-bugs*
108 |
109 | - Not all cases are supported. For example:
110 |
111 | - [range] is not supported yet. If [range] is given, altercmd doesn't work.
112 |
113 | - If any argument is not given to an Ex command which has an alternative Ex
114 | command, altercmd doesn't work.
115 |
116 | - And there may be more cases where altercmd doesn't work well.
117 |
118 |
119 |
120 |
121 | ==============================================================================
122 | CHANGELOG *altercmd-changelog*
123 |
124 | 0.0.1 2015-01-31T23:52:24+09:00
125 | - Fix a bug that buffer-local |:AlterCommand| could not be defined.
126 |
127 | 0.0.0 2009-06-14T03:47:25+09:00
128 | - Initial version.
129 |
130 |
131 |
132 |
133 | ==============================================================================
134 | vim:tw=78:ts=8:ft=help:norl:fen:fdl=0:fdm=marker:
135 |
--------------------------------------------------------------------------------
/plugin/altercmd.vim:
--------------------------------------------------------------------------------
1 | " altercmd - Alter built-in Ex commands by your own ones
2 | " Version: 0.0.1
3 | " Copyright (C) 2009-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_altercmd')
26 | finish
27 | endif
28 |
29 |
30 |
31 |
32 | command! -bar -complete=command -nargs=* AlterCommand
33 | \ call altercmd#define()
34 |
35 |
36 |
37 |
38 | let g:loaded_altercmd = 1
39 |
40 | " __END__
41 | " vim: foldmethod=marker
42 |
--------------------------------------------------------------------------------
/t/basics.vim:
--------------------------------------------------------------------------------
1 | call altercmd#define('full', 'F-U-L-L')
2 | call altercmd#define('ab[br]', 'A-B-B-R')
3 |
4 | function! RecordTheCurrentCommandLine()
5 | let g:cmdline = getcmdline()
6 | return ''
7 | endfunction
8 | cnoremap {X} RecordTheCurrentCommandLine()
9 |
10 | function! Test(lhs, rhs)
11 | let g:cmdline = ''
12 | silent execute 'normal' ":".a:lhs."\{X}\"
13 | Expect g:cmdline ==# a:rhs
14 | endfunction
15 |
16 | describe 'altercmd#define'
17 | it 'replaces a built-in command'
18 | call Test('full', 'F-U-L-L')
19 | end
20 |
21 | it 'replaces all abbreviated names of a built-in command'
22 | call Test('ab', 'A-B-B-R')
23 | call Test('abb', 'A-B-B-R')
24 | call Test('abbr', 'A-B-B-R')
25 | end
26 |
27 | it 'supports '
28 | silent edit 'test-A'
29 | call altercmd#define('', 'ctx', 'Axe')
30 | silent edit 'test-B'
31 | call altercmd#define('', 'ctx', 'Bow')
32 | silent edit 'test-C'
33 | call altercmd#define('', 'ctx', 'Club')
34 |
35 | silent edit 'test-A'
36 | call Test('full', 'F-U-L-L')
37 | call Test('ctx', 'Axe')
38 | silent edit 'test-B'
39 | call Test('full', 'F-U-L-L')
40 | call Test('ctx', 'Bow')
41 | silent edit 'test-C'
42 | call Test('full', 'F-U-L-L')
43 | call Test('ctx', 'Club')
44 | end
45 | end
46 |
--------------------------------------------------------------------------------