ntpeters / vim-better-whitespace

Better whitespace highlighting for Vim

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Remapping the oeprator to `d<space>` doesn't work.

blasco opened this issue · comments

I've tried to remap it:

let g:better_whitespace_operator='d<space>'

but this takes no effect, am I doing something wrong?

Maybe because the d command is already associated with the action to delete, so d<space> is read by vim as delete for a motion of just 1 character. That is why we made it start with <leader> − so that it would not conflict with existing commands.

But strange enough, if I modify the plugin manually it does work. So I went to the autolodaed script and changed it by d<space> and works. I think it would be best to provide an <plug>(delete-whitespaces-operator) that we can freely map like in other plugins. I'll try to implement that and provide a PR.

exe 'xmap <silent> d<space> :StripWhitespace<CR>'
exe 'nmap <silent> d<space> :<C-U>set opfunc=<SID>StripWhitespaceMotion<CR>g@'

That works perfectly fine

These should be exactly the commands that are run when g:better_whitespace_operator='d<space>' if they’re not mapped to anything else previously:

if !empty(g:better_whitespace_operator)
" Ensure we only map if no identical, user-defined mapping already exists
if (empty(mapcheck(g:better_whitespace_operator, 'x')))
" Visual mode
exe 'xmap <silent> '.g:better_whitespace_operator.' :StripWhitespace<CR>'
endif
" Ensure we only map if no identical, user-defined mapping already exists
if (empty(mapcheck(g:better_whitespace_operator, 'n')))
" Normal mode (+ space, with line count)
exe 'nmap <silent> '.g:better_whitespace_operator.'<space> :<C-U>exe ".,+".v:count" StripWhitespace"<CR>'
" Other motions
exe 'nmap <silent> '.g:better_whitespace_operator.' :<C-U>set opfunc=<SID>StripWhitespaceMotion<CR>g@'
endif
endif

What do the mapcheck() commands return before you manually run those exe commands?

Closing for lack of activity. Feel free to reopen when new information is available, in particular with a minimal vimrc and verifying mapcheck() values