Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to disable all default mappings #40

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ let g:camelcasemotion_key = '<leader>'
If you want to use different mappings, map your keys to the
<Plug>CamelCaseMotion_? mapping targets your vimrc).

You can also disable all default mappings and only define the ones you want
setting the `g:camelcasemotion_map_keys` variable to `0`: (Default: `1`)

```vim
let g:camelcasemotion_map_keys = 0
```

EXAMPLE: Map to w, b and e mappings:

```vim
Expand Down
4 changes: 4 additions & 0 deletions doc/camelcasemotion.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ EXAMPLE: Map |iw|, |ib| and |ie| motions: >
omap <silent> ie <Plug>CamelCaseMotion_ie
xmap <silent> ie <Plug>CamelCaseMotion_ie

You can also disable all default mappings and only define the ones you want
setting the |g:camelcasemotion_map_keys| variable to `0`: (Default: `1`) >
let g:camelcasemotion_map_keys = 0

==============================================================================
KNOWN PROBLEMS *camelcasemotion-known-problems*

Expand Down
72 changes: 39 additions & 33 deletions plugin/camelcasemotion.vim
Original file line number Diff line number Diff line change
Expand Up @@ -138,43 +138,49 @@ if exists('g:camelcasemotion_key')
call camelcasemotion#CreateMotionMappings(g:camelcasemotion_key)
endif

"- mappings -------------------------------------------------------------------
" The count is passed into the function through the special variable 'v:count1',
" which is easier than misusing the :[range] that :call supports.
" <C-U> is used to delete the unused range.
" Another option would be to use a custom 'command! -count=1', but that doesn't
" work with the normal mode mapping: When a count is typed before the mapping,
" the ':' will convert a count of 3 into ':.,+2MyCommand', but ':3MyCommand'
" would be required to use -count and <count>.
"
" We do not provide the fourth "backward to end" motion (,E), because it is
" seldomly used.
if !exists('g:camelcasemotion_map_keys')
let g:camelcasemotion_map_keys = 1
endif

if g:camelcasemotion_map_keys
"- mappings -------------------------------------------------------------------
" The count is passed into the function through the special variable 'v:count1',
" which is easier than misusing the :[range] that :call supports.
" <C-U> is used to delete the unused range.
" Another option would be to use a custom 'command! -count=1', but that doesn't
" work with the normal mode mapping: When a count is typed before the mapping,
" the ':' will convert a count of 3 into ':.,+2MyCommand', but ':3MyCommand'
" would be required to use -count and <count>.
"
" We do not provide the fourth "backward to end" motion (,E), because it is
" seldomly used.

for s:mode in ['n', 'o', 'v']
for s:motion in ['w', 'b', 'e', 'ge']
let s:targetMapping = '<Plug>CamelCaseMotion_' . s:motion
execute s:mode . 'noremap <silent> ' . s:targetMapping .
\ ' :<C-U>call camelcasemotion#Motion(''' . s:motion . ''',v:count1,''' . s:mode . ''')<CR>'
for s:mode in ['n', 'o', 'v']
for s:motion in ['w', 'b', 'e', 'ge']
let s:targetMapping = '<Plug>CamelCaseMotion_' . s:motion
execute s:mode . 'noremap <silent> ' . s:targetMapping .
\ ' :<C-U>call camelcasemotion#Motion(''' . s:motion . ''',v:count1,''' . s:mode . ''')<CR>'
endfor
endfor
endfor

" To create a text motion, a mapping for operator-pending mode needs to be
" defined. This mapping should move the cursor according to the implemented
" motion, or mark the covered text via a visual selection. As inner text motions
" need to mark both to the left and right of the cursor position, the visual
" selection needs to be used.
"
" Vim's built-in inner text objects also work in visual mode; they have
" different behavior depending on whether visual mode has just been entered or
" whether text has already been selected.
" We deviate from that and always override the existing selection.
" To create a text motion, a mapping for operator-pending mode needs to be
" defined. This mapping should move the cursor according to the implemented
" motion, or mark the covered text via a visual selection. As inner text motions
" need to mark both to the left and right of the cursor position, the visual
" selection needs to be used.
"
" Vim's built-in inner text objects also work in visual mode; they have
" different behavior depending on whether visual mode has just been entered or
" whether text has already been selected.
" We deviate from that and always override the existing selection.

for s:mode in ['o', 'v']
for s:motion in ['w', 'b', 'e', 'ge']
let s:targetMapping = '<Plug>CamelCaseMotion_i' . s:motion
execute s:mode . 'noremap <silent> ' . s:targetMapping .
\ ' :<C-U>call camelcasemotion#InnerMotion(''' . s:motion . ''',v:count1)<CR>'
for s:mode in ['o', 'v']
for s:motion in ['w', 'b', 'e', 'ge']
let s:targetMapping = '<Plug>CamelCaseMotion_i' . s:motion
execute s:mode . 'noremap <silent> ' . s:targetMapping .
\ ' :<C-U>call camelcasemotion#InnerMotion(''' . s:motion . ''',v:count1)<CR>'
endfor
endfor
endfor
endif

" vim: set sts=2 sw=2 expandtab ff=unix fdm=syntax :