vim-sandwich icon indicating copy to clipboard operation
vim-sandwich copied to clipboard

textobj-sandwich query mappings break sentence text objects.

Open MageJohn opened this issue 7 years ago • 11 comments

The default mappings for <Plug>(textobj-sandwich-query-i) and <Plug>(textobj-sandwich-query-a), break the built in text objects for sentences, which are also is and as. As well as code I write quite a lot of markdown, and the sentence text objects are very useful. It would be great to have different default mappings for these. For now I've remapped the commands to iq and aq (q for query). As far as I can find there are no conflicts with this mapping.

As a side note, is there an easier way to remap just the query versions of the text objects? Currently I'm doing:

let g:textobj_sandwich_no_default_key_mappings = 1
xmap ib <Plug>(textobj-sandwich-auto-i)
omap ib <Plug>(textobj-sandwich-auto-i)
xmap ab <Plug>(textobj-sandwich-auto-a)
omap ab <Plug>(textobj-sandwich-auto-a)

xmap iq <Plug>(textobj-sandwich-query-i)
omap iq <Plug>(textobj-sandwich-query-i)
xmap aq <Plug>(textobj-sandwich-query-a)
omap aq <Plug>(textobj-sandwich-query-a)

Since the only difference is with the query type, this seems redundant, but the way I understand the docs suggest this is the only way. It isn't important, I was just wondering.

MageJohn avatar Feb 22 '18 21:02 MageJohn

Hi. Although I realized the mapping problem, it would affect too many people, so I don't want to change the default key mappings, sorry. I think the default key mapping is not so important; it should be determined by a user rather than the author. The important thing is that there is a way to change the keymapping.

As for the description in vimrc, the yours is the right way I think. Once I have thought about a something like "magic stuff" to define keymappings easier but I gave up finally. Probably I can make the desctiption shorter but it will be hard to understand for users who are not familiar with Vim script and need additional startup time (some people really enthusiastic about it). The current style may not be the best because as you said it is redundant, but I think it is easy to understand and less cost.

machakann avatar Feb 23 '18 10:02 machakann

Hi, also default mappings start with s which is a command.

["x]s			Delete [count] characters [into register x] and start
			insert (s stands for Substitute).  Synonym for "cl"
			(not |linewise|).

khrt avatar Jul 12 '18 06:07 khrt

I have

map <silent> s <nop>
map <silent> S <nop>

as c has the same usage, anyway. This way {sS}X can be used for other maps.

Regarding previous:

  • da<wait until blinking>s will delete a sentence.
  • dasX will delete from X to X

rpuntaie avatar Jul 19 '19 13:07 rpuntaie

I think the plugin is also breaking the ib/ab text objects, which stands for everything inside/outside parenthesis. I had no idea why my mapping was broken until I disable vim-sandwich. This should be written on the front page README to warn users about the conflicts.

ianliu avatar Feb 19 '20 17:02 ianliu

I think the plugin is also breaking the ib/ab text objects, which stands for everything inside/outside parenthesis. I had no idea why my mapping was broken until I disable vim-sandwich. This should be written on the front page README to warn users about the conflicts.

I agree, both this and the sentences should be warned in the readme. I'm good with replacing the substitue actions for sandwich, but I don't want to replace the sentence object.

More importantly, I think it is a mistake for the plugin to remove a sentence as a text object. So far I like how I can sandwich so many things that I can think of, try it, and it works. If I follow that logic my instinct would be for example to do sas( to surround a sentence with (), but I currently don't know how to do that with this plugin's default mappings.

indeedwatson avatar May 08 '20 17:05 indeedwatson

How can I remap s to y. I'm really used to use s and now there is a little delay when I use it.

J053Fabi0 avatar Jul 12 '20 08:07 J053Fabi0

@J053Fabi0

nmap ya <Plug>(operator-sandwich-add)
xmap ya <Plug>(operator-sandwich-add)
xmap yd <Plug>(operator-sandwich-delete)
xmap yr <Plug>(operator-sandwich-replace)
nmap <silent> yd <Plug>(operator-sandwich-delete)<Plug>(operator-sandwich-release-count)<Plug>(textobj-sandwich-query-a)
nmap <silent> yr <Plug>(operator-sandwich-replace)<Plug>(operator-sandwich-release-count)<Plug>(textobj-sandwich-query-a)
nmap <silent> ydb <Plug>(operator-sandwich-delete)<Plug>(operator-sandwich-release-count)<Plug>(textobj-sandwich-auto-a)
nmap <silent> yrb <Plug>(operator-sandwich-replace)<Plug>(operator-sandwich-release-count)<Plug>(textobj-sandwich-auto-a)

But it may take a little delay with y...?

machakann avatar Jul 18 '20 12:07 machakann

And now how can I unmap sa, sr, srb, and sd. I've tried with this:

nunmap sa
nunmap srb
nunmap sr
nunmap sd

But it fails.

J053Fabi0 avatar Jul 29 '20 03:07 J053Fabi0

Never mind, I figured it out:

autocmd VimEnter * unmap sa
autocmd VimEnter * unmap srb
autocmd VimEnter * unmap sr
autocmd VimEnter * unmap sd
autocmd VimEnter * unmap sdb

J053Fabi0 avatar Jul 29 '20 03:07 J053Fabi0

Or just:

let g:sandwich_no_default_key_mappings = 1
let g:operator_sandwich_no_default_key_mappings = 1

machakann avatar Jul 29 '20 12:07 machakann

@J053Fabi0

nmap ya <Plug>(operator-sandwich-add)
xmap ya <Plug>(operator-sandwich-add)
xmap yd <Plug>(operator-sandwich-delete)
xmap yr <Plug>(operator-sandwich-replace)
nmap <silent> yd <Plug>(operator-sandwich-delete)<Plug>(operator-sandwich-release-count)<Plug>(textobj-sandwich-query-a)
nmap <silent> yr <Plug>(operator-sandwich-replace)<Plug>(operator-sandwich-release-count)<Plug>(textobj-sandwich-query-a)
nmap <silent> ydb <Plug>(operator-sandwich-delete)<Plug>(operator-sandwich-release-count)<Plug>(textobj-sandwich-auto-a)
nmap <silent> yrb <Plug>(operator-sandwich-replace)<Plug>(operator-sandwich-release-count)<Plug>(textobj-sandwich-auto-a)

But it may take a little delay with y...?

for me, no xmap or nmap start with t:

nmap ta <Plug>(operator-sandwich-add)
xmap ta <Plug>(operator-sandwich-add)
xmap td <Plug>(operator-sandwich-delete)
xmap tr <Plug>(operator-sandwich-replace)
nmap <silent> td <Plug>(operator-sandwich-delete)<Plug>(operator-sandwich-release-count)<Plug>(textobj-sandwich-query-a)
nmap <silent> tr <Plug>(operator-sandwich-replace)<Plug>(operator-sandwich-release-count)<Plug>(textobj-sandwich-query-a)
nmap <silent> tdb <Plug>(operator-sandwich-delete)<Plug>(operator-sandwich-release-count)<Plug>(textobj-sandwich-auto-a)
nmap <silent> trb <Plug>(operator-sandwich-replace)<Plug>(operator-sandwich-release-count)<Plug>(textobj-sandwich-auto-a)

sisrfeng avatar Jan 31 '22 09:01 sisrfeng