Skip to content

Allow us to disable the default keymappings easily #248

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

Open
wants to merge 3 commits 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
9 changes: 8 additions & 1 deletion doc/sneak.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ NORMAL-MODE~
[count]S{char}{char} | Invoke backwards |sneak-vertical-scope|
{operator}z{char}{char} | Perform {operator} from the cursor to the next
| occurrence of {char}{char}
{operator}Z{char}{char} | Perform {operator} from the cursor to the
{operator}Z{char}{char} | Perform {operator} from the cursor to the
| previous occurrence of {char}{char}

NOTE: s and S go to the next/previous match immediately after invoking
Expand Down Expand Up @@ -259,6 +259,13 @@ OPTIONS *sneak-options*
To change an option, add a |let| statement in your |vimrc|. Example: >
let g:sneak#use_ic_scs = 0
<
g:sneak#no_default_mappings = 0
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

flip it so it is "positive logic"

Suggested change
g:sneak#no_default_mappings = 0
g:sneak#default_mappings = 1

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer the negative one here because it sounds natural for me (at least) to be set to 0 as default, and user will set it to 1 to turn on especially when an option expects either 0 or 1 as "OFF" or "ON".

Addition to that, I usually unify default values to be set to 0 unless the variable has specific reason to be other than 0; such unification reduces unnecessary chances that users should grep default values.

However, I also know positive logic is preferable in most cases so that it's a matter of taste after all. Please adopt the one on your preference.


0: Apply all the default |sneak-mappings| that escape from the checks
through hasmapto() and mapcheck().

1: Disable any |sneak-mappings|. See |sneak-custom-mappings|.

g:sneak#f_reset = 1
g:sneak#t_reset = 1

Expand Down
66 changes: 34 additions & 32 deletions plugin/sneak.vim
Original file line number Diff line number Diff line change
Expand Up @@ -363,41 +363,43 @@ xnoremap <silent> <Plug>SneakLabel_S :<c-u>call sneak#wrap(visualmode(), 2, 1, 2
onoremap <silent> <Plug>SneakLabel_s :<c-u>call sneak#wrap(v:operator, 2, 0, 2, 2)<cr>
onoremap <silent> <Plug>SneakLabel_S :<c-u>call sneak#wrap(v:operator, 2, 1, 2, 2)<cr>

if !hasmapto('<Plug>SneakForward') && !hasmapto('<Plug>Sneak_s', 'n') && mapcheck('s', 'n') ==# ''
nmap s <Plug>Sneak_s
endif
if !hasmapto('<Plug>SneakBackward') && !hasmapto('<Plug>Sneak_S', 'n') && mapcheck('S', 'n') ==# ''
nmap S <Plug>Sneak_S
endif
if !hasmapto('<Plug>Sneak_s', 'o') && mapcheck('z', 'o') ==# ''
omap z <Plug>Sneak_s
endif
if !hasmapto('<Plug>Sneak_S', 'o') && mapcheck('Z', 'o') ==# ''
omap Z <Plug>Sneak_S
endif
if !get(g:, 'sneak#no_default_mappings', 0)
if !hasmapto('<Plug>SneakForward') && !hasmapto('<Plug>Sneak_s', 'n') && mapcheck('s', 'n') ==# ''
nmap s <Plug>Sneak_s
endif
if !hasmapto('<Plug>SneakBackward') && !hasmapto('<Plug>Sneak_S', 'n') && mapcheck('S', 'n') ==# ''
nmap S <Plug>Sneak_S
endif
if !hasmapto('<Plug>Sneak_s', 'o') && mapcheck('z', 'o') ==# ''
omap z <Plug>Sneak_s
endif
if !hasmapto('<Plug>Sneak_S', 'o') && mapcheck('Z', 'o') ==# ''
omap Z <Plug>Sneak_S
endif

if !hasmapto('<Plug>Sneak_;', 'n') && !hasmapto('<Plug>SneakNext', 'n') && mapcheck(';', 'n') ==# ''
nmap ; <Plug>Sneak_;
omap ; <Plug>Sneak_;
xmap ; <Plug>Sneak_;
endif
if !hasmapto('<Plug>Sneak_,', 'n') && !hasmapto('<Plug>SneakPrevious', 'n')
if mapcheck(',', 'n') ==# ''
nmap , <Plug>Sneak_,
omap , <Plug>Sneak_,
xmap , <Plug>Sneak_,
elseif mapcheck('\', 'n') ==# '' || mapcheck('\', 'n') ==# ','
nmap \ <Plug>Sneak_,
omap \ <Plug>Sneak_,
xmap \ <Plug>Sneak_,
if !hasmapto('<Plug>Sneak_;', 'n') && !hasmapto('<Plug>SneakNext', 'n') && mapcheck(';', 'n') ==# ''
nmap ; <Plug>Sneak_;
omap ; <Plug>Sneak_;
xmap ; <Plug>Sneak_;
endif
if !hasmapto('<Plug>Sneak_,', 'n') && !hasmapto('<Plug>SneakPrevious', 'n')
if mapcheck(',', 'n') ==# ''
nmap , <Plug>Sneak_,
omap , <Plug>Sneak_,
xmap , <Plug>Sneak_,
elseif mapcheck('\', 'n') ==# '' || mapcheck('\', 'n') ==# ','
nmap \ <Plug>Sneak_,
omap \ <Plug>Sneak_,
xmap \ <Plug>Sneak_,
endif
endif
endif

if !hasmapto('<Plug>VSneakForward') && !hasmapto('<Plug>Sneak_s', 'v') && mapcheck('s', 'x') ==# ''
xmap s <Plug>Sneak_s
endif
if !hasmapto('<Plug>VSneakBackward') && !hasmapto('<Plug>Sneak_S', 'v') && mapcheck('Z', 'x') ==# ''
xmap Z <Plug>Sneak_S
if !hasmapto('<Plug>VSneakForward') && !hasmapto('<Plug>Sneak_s', 'v') && mapcheck('s', 'x') ==# ''
xmap s <Plug>Sneak_s
endif
if !hasmapto('<Plug>VSneakBackward') && !hasmapto('<Plug>Sneak_S', 'v') && mapcheck('Z', 'x') ==# ''
xmap Z <Plug>Sneak_S
endif
endif

" redundant legacy mappings for backwards compatibility (must come _after_ the hasmapto('<Plug>Sneak_S') checks above)
Expand Down