Reply to message «Re: go to next line multiples of n», sent 09:29:14 10 June 2011, Friday by Bee:
> > > This does NOT work.
> > >
> > > :nmap J execute "normal " . tline - line('.') % tline . "j"
In the original normal command you had problems with operator priorities: if
you'd run
echo "normal " . tline - line('.') % tline . "j"
you found what is the problem (it outputs `-1j' for the first line). In this
command you should have added parenthesis:
execute "normal! " . (tline - line('.') % tline) . "j"
. I don't see any problems with
> :nmap <expr> J tline+1-line('.')%tline.'jzt'
> :nmap <expr> K tline+1-line('.')%tline.'kzt'
except that you should not use `nmap' without `nore' here: `nnoremap' saves
your time as number of mappings that can interfere with each other grows up.
Maybe this is the problem. If it is not, write what happens when you use this
mapping and what you expect to happen: I don't get what is wrong here.
Also, write parenthesis. It works now because concatenation operator has the
same priority as addition and substraction and number calculations occur to be
first, but it will fail if you add some string before `tline' as you did in
original mapping.
Original message:
> On Jun 9, 10:09 pm, Christian Brabandt <[email protected]> wrote:
> > Hi Bee!
> >
> > On Do, 09 Jun 2011, Bee wrote:
> > > I would like to jump to the next (or prev) line, always a multiple of
> > > "tline".
> > >
> > > let tline = 16
> > >
> > > This calculates how many more lines to jump
> > > useful with "j"
> > >
> > > :echo tline - line(".") % tline
> > >
> > > This calculates the line to jump to
> > > useful with "G"
> > >
> > > :echo ( line(".") / tline + 1 ) * tline
> > >
> > > How to create a mapping?
> > >
> > > This does NOT work.
> > >
> > > :nmap J execute "normal " . tline - line('.') % tline . "j"
> >
> > You want an expression mapping:
> > :nmap <expr> J tline-line('.')%tline.'j'
> >
> > See also the help at :h map-expression
> >
> > regards,
> > Christian
> > --
>
> Thank you, Christian
>
> Works great but for the offset I needed to add 1:
> :nmap <expr> J tline+1-line('.')%tline.'jzt'
> :nmap <expr> K tline+1-line('.')%tline.'kzt'
>
> And now I also have the reverse.
signature.asc
Description: This is a digitally signed message part.
