setpos() and <up> => wrong position

71 views
Skip to first unread message

Dimitar DIMITROV

unread,
Aug 19, 2013, 4:16:23 AM8/19/13
to vim...@googlegroups.com
Hi all,

I will use the following text as an example:

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure [d]olor in reprehenderit in voluptate velit esse cillum dolore eu
fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
culpa qui officia deserunt mollit anim id est laborum.

My cursor is on [d] as shown above:

Now try :ec getpos('.') -> [0, 4, 17, 0]
Move away and :call setpos('.',[0,4,17,0])
If you use <up> <down> k or j you will not move just above/below the char but in some weird location

Regards
 
Dimitar


---
GPG Key: 2048R/160C6FA8 2012-10-11 Dimitar Dimitrov (kurkale6ka) <mit...@yahoo.fr>

John Little

unread,
Aug 19, 2013, 5:22:07 AM8/19/13
to vim...@googlegroups.com, Dimitar DIMITROV
On Monday, August 19, 2013 8:16:23 PM UTC+12, Dimitar DIMITROV wrote:
> If you use <up> <down> k or j you will not move just above/below the char but in some weird location

My vim 7.4 doesn't do this, but 7.3.547 does, so it looks like a bug that's been fixed.

Regards, John Little

Dimitar DIMITROV

unread,
Aug 19, 2013, 5:28:54 AM8/19/13
to vim...@googlegroups.com
>> If you use <up> <down> k or j you will not move just above/below the char but in some weird location
>
>My vim 7.4 doesn't do this, but 7.3.547 does, so it looks like a bug that's been fixed.

I used version 7.4 with Included patches: 1-5 so not sure how come you're not seing it.
Also used: vim -nNX -u NONE

>Regards, John Little


Dimitar

John Beckett

unread,
Aug 19, 2013, 5:30:16 AM8/19/13
to vim...@googlegroups.com
Dimitar DIMITROV wrote:
> Now try :ec getpos('.') -> [0, 4, 17, 0]
> Move away and :call setpos('.',[0,4,17,0])
> If you use <up> <down> k or j you will not move just
> above/below the char but in some weird location

Say the cursor is in column 20, then setpos() is used to jump
to [d], then k is pressed.

The result is that the cursor goes to column 20. That is
possibly not very helpful, but it's compatible with ":help k":

The first two commands [k and j] put the cursor in the
same column (if possible) as it was after the
last command that changed the column

In other words, calling setpos() is not regarded as a command.

John


Christian Brabandt

unread,
Aug 19, 2013, 5:54:12 AM8/19/13
to vim...@googlegroups.com
May be another optional parameter to the setpos() function, that
if given specifies the desired cursor position?

Or should we rather "fix" setpos() in that it always set's the
desired cursor position to the actual position?

regards,
Christian

glts

unread,
Aug 19, 2013, 6:01:58 AM8/19/13
to vim...@googlegroups.com
On Mon, Aug 19, 2013 at 10:16 AM, Dimitar DIMITROV <mit...@yahoo.fr> wrote:
> I will use the following text as an example:
>
> Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
> tempor
> incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
> nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
> consequat.
> Duis aute irure [d]olor in reprehenderit in voluptate velit esse cillum
> dolore eu
> fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt
> in
> culpa qui officia deserunt mollit anim id est laborum.
>
> My cursor is on [d] as shown above:
>
> Now try :ec getpos('.') -> [0, 4, 17, 0]
> Move away and :call setpos('.',[0,4,17,0])
> If you use <up> <down> k or j you will not move just above/below the char
> but in some weird location

Not a bug.

See:
https://groups.google.com/d/msg/vim_dev/o9GRXaJMwHg/9g8INNnNB9YJ

Christian Brabandt

unread,
Aug 19, 2013, 3:53:01 PM8/19/13
to vim...@googlegroups.com
On Mo, 19 Aug 2013, Christian Brabandt wrote:

> May be another optional parameter to the setpos() function, that
> if given specifies the desired cursor position?

Like the attached patch does.

regards,
Christian
--
Es geh�rt viel dazu, eine Br�cke hinter sich abzurei�en, wenn man auch
keine vor sich hat.
-- Karlheinz Deschner
setpos_curswant.diff

Bram Moolenaar

unread,
Aug 22, 2013, 11:23:11 AM8/22/13
to Christian Brabandt, vim...@googlegroups.com

Christian Brabandt wrote:

> On Mo, 19 Aug 2013, Christian Brabandt wrote:
>
> > May be another optional parameter to the setpos() function, that
> > if given specifies the desired cursor position?
>
> Like the attached patch does.

Hmm, I wonder if the extra list elements are going to cause a problem in
some existing script.


--
hundred-and-one symptoms of being an internet addict:
107. When using your phone you forget that you don't have to use your
keyboard.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Christian Brabandt

unread,
Aug 22, 2013, 12:05:24 PM8/22/13
to Bram Moolenaar, vim...@googlegroups.com
On Thu, August 22, 2013 17:23, Bram Moolenaar wrote:
> Christian Brabandt wrote:
>> On Mo, 19 Aug 2013, Christian Brabandt wrote:
>>
>> > May be another optional parameter to the setpos() function, that
>> > if given specifies the desired cursor position?
>>
>> Like the attached patch does.
>
> Hmm, I wonder if the extra list elements are going to cause a problem in
> some existing script.

I don't think, it will make a difference for the optional list-argument
of the setpos() call. It might only make a difference for the list
returned by the getpos() call now having 5 elements. If you're worried
about that, simply let getpos('.') always return 4 elements (though
this makes it harder to determine the prefered column).

regards,
Christian

Nikolay Pavlov

unread,
Aug 22, 2013, 12:40:05 PM8/22/13
to vim...@googlegroups.com, Bram Moolenaar

I bet there is a bunch of scripts using 4-variable lets. Simple grep over the mess in $HOME/.vam (I hold all but my plugins there) found at least LaTeX_box plugin (ftplugin/latex-box/common.vim) and python-mode-klen (autoload/pymode/lint.vim, though it should have used line() and not getpos()). I do not know how many plugins do
    let pos=getpos('.')
    ...
    let [a,b,c,d]=pos
, use negative indices or something else. Why not use optional argumet to getpos() then? Note: optional argument should make it return a dictionary. 5 indistinguishable  numbers are way too much.

Also check out winsaveview(), particularly .curswant key. Maybe there is no need to modify getpos().

> regards,
> Christian
>
> --
> --
> You received this message from the "vim_dev" maillist.
> Do not top-post! Type your reply below the text you are replying to.
> For more information, visit http://www.vim.org/maillist.php
>
> ---
> You received this message because you are subscribed to the Google Groups "vim_dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+u...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

Christian Brabandt

unread,
Aug 22, 2013, 2:24:18 PM8/22/13
to vim...@googlegroups.com

On Do, 22 Aug 2013, Nikolay Pavlov wrote:

> I bet there is a bunch of scripts using 4-variable lets. Simple grep over

What do you mean with 4-variable lets?

> the mess in $HOME/.vam (I hold all but my plugins there) found at least
> LaTeX_box plugin (ftplugin/latex-box/common.vim) and python-mode-klen
> (autoload/pymode/lint.vim, though it should have used line() and not
> getpos()). I do not know how many plugins do
> let pos=getpos('.')
> ...
> let [a,b,c,d]=pos
> , use negative indices or something else. Why not use optional argumet to
> getpos() then? Note: optional argument should make it return a dictionary.
> 5 indistinguishable numbers are way too much.

Probably not. There not much difference to winsaveview() anymore. It was
only a suggestion, though.

regards,
Christian
--
Frage an Radio Eriwan:
Gibt es bei uns mehr Humor als anderswo?
Radio Eriwan antwortet:
Im Prinzip ja. Aber wir haben ihn auch n�tig.

Nikolay Pavlov

unread,
Aug 22, 2013, 3:08:30 PM8/22/13
to vim...@googlegroups.com


On Aug 22, 2013 10:24 PM, "Christian Brabandt" <cbl...@256bit.org> wrote:
>
>
> On Do, 22 Aug 2013, Nikolay Pavlov wrote:
>
> > I bet there is a bunch of scripts using 4-variable lets. Simple grep over
>
> What do you mean with 4-variable lets?

     let [a,b,c,d]=e

> > the mess in $HOME/.vam (I hold all but my plugins there) found at least
> > LaTeX_box plugin (ftplugin/latex-box/common.vim) and python-mode-klen
> > (autoload/pymode/lint.vim, though it should have used line() and not
> > getpos()). I do not know how many plugins do
> >     let pos=getpos('.')
> >     ...
> >     let [a,b,c,d]=pos
> > , use negative indices or something else. Why not use optional argumet to
> > getpos() then? Note: optional argument should make it return a dictionary.
> > 5 indistinguishable  numbers are way too much.
>
> Probably not. There not much difference to winsaveview() anymore. It was
> only a suggestion, though.
>
> regards,
> Christian
> --
> Frage an Radio Eriwan:
> Gibt es bei uns mehr Humor als anderswo?
> Radio Eriwan antwortet:

> Im Prinzip ja. Aber wir haben ihn auch nötig.

Bram Moolenaar

unread,
Aug 22, 2013, 5:07:17 PM8/22/13
to Nikolay Pavlov, vim...@googlegroups.com
Yes, in complicated cases winsaveview() can be used.

I think that in most cases the original problem applies: setpos() does
not set the curswant position. I think the best way to fix this is by
adding a separate set_curswant() function. Without argument it uses the
current cursor position, and otherwise it sets the position to a column
number.

--
FIXME and XXX are two common keywords used to mark broken or incomplete code
not only since XXX as a sex reference would grab everybody's attention but
simply due to the fact that Vim would highlight these words.
-- Hendrik Scholz

Nikolay Pavlov

unread,
Aug 22, 2013, 11:41:45 PM8/22/13
to Bram Moolenaar, vim...@googlegroups.com

I think that winrestview() should be officially allowed to accept custom dictionary:

    call winrestview({'curswant': 3})

seems to work fine. No "If you have changed the values the result is unpredictable.", but say what can be set this way and what combinations of keys should not be used.

Reply all
Reply to author
Forward
0 new messages