[vim/vim] Allow users to swap mark positions just as with default motions (Issue #15316)

6 views
Skip to first unread message

Svetlozar Iliev

unread,
Jul 21, 2024, 8:36:26 AM (24 hours ago) Jul 21
to vim/vim, Subscribed

Steps to reproduce

set nocompatible

onoremap i" :<c-u>call <SID>TestInsideObject()<CR>
nnoremap gs :<C-U>set opfunc=<SID>TestInsideQuotes<CR>g@

function! s:TestInsideObject()
    let m1 = getpos(".")
    let m2 = getpos(".")

     let m1[1] = 1
     let m2[1] = 1

     let m1[2] = 2
     let m2[2] = 1

     call setpos("'[", m1)
     call setpos("']", m2)
endfunction

function! s:TestInsideQuotes(motion)
     let m1 = getpos("'[")
     let m2 = getpos("']")

     echom m1
     echom m2
endfunction

Have the following file
``txt
line with some text and empty quotes ""

1. vim -u config.vim test.txt
2. open the file on the first line
3. Hit `gsi"`

So in this example we have two cases, let us run the repro first without the custom `onoremap` the echo calls would echo out the change marks, where the change marks would actually be reversed, the column more specifically for the start mark `[` will be bigger than the column value for the `]` mark. 

**Which some plugins actually use to identify edge case motions such as this one - where the `inner` part of the text object is emtpy, however you might want to put some text inbetween the quotes, however if the marks' columns had not been reversed you would have no way of knowing you are in the edge case. This is super useful**, however if we add the custom `onoremap`, where we manually set the marks now, we can not force set these marks, after the calls to setpos, vim would then override them, and after we execute `gsi"` and hit `:marks` we see that the values are not the ones we set. 

### Expected behaviour

The user should be allowed to replicate this inversed mark behaviour, which the default built in motions provide for empty object such as for example quote pairs. 

### Version of Vim

9.1

### Environment

Ubuntu22
Alacritty
zsh

### Logs and stack traces

```shell
None


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/15316@github.com>

Reply all
Reply to author
Forward
0 new messages