Simple repetition question

0 views
Skip to first unread message

Zachary Turner

unread,
Dec 5, 2008, 9:01:29 PM12/5/08
to vim_use
I'm writing code in some programming language, and when I compile it
gives me the unfortunate error message:

Syntax error: Character 28345-28347

Opening the file in VIM and starting from the beginning, the sequence
'28345l' does not produce desired results, because the 'l' stops at
the end of the line. How can I seek to the n'th character in a file?

Thanks

Eustáquio Rangel

unread,
Dec 5, 2008, 9:23:13 PM12/5/08
to vim...@googlegroups.com
> Opening the file in VIM and starting from the beginning, the sequence
> '28345l' does not produce desired results, because the 'l' stops at
> the end of the line. How can I seek to the n'th character in a file?

Try

28345go

Zachary Turner

unread,
Dec 5, 2008, 11:23:40 PM12/5/08
to vim_use
Thanks, this works from the beginning of the file. Is there a similar
method I can use if I know the character offset from a given
position? Like I know it's the 750th character from the first
occurence of some string which I can search for. So I search for it
using /, then from there is there another command that is just an
offset from that position?

On Dec 5, 8:23 pm, "Eustáquio Rangel" <eustaquioran...@gmail.com>
wrote:

Charles E. Campbell, Jr.

unread,
Dec 5, 2008, 11:44:53 PM12/5/08
to vim...@googlegroups.com
Zachary Turner wrote:
> Thanks, this works from the beginning of the file. Is there a similar
> method I can use if I know the character offset from a given
> position? Like I know it's the 750th character from the first
> occurence of some string which I can search for. So I search for it
> using /, then from there is there another command that is just an
> offset from that position?
> [snip]
>

Please bottom post! Its the preferred style here in vim_use.

So, with that out of the way... why not try

set ww=b,s,<,>,[,]

and then try your 750l .

Regards,
Chip Campbell

Zachary Turner

unread,
Dec 5, 2008, 11:53:22 PM12/5/08
to vim_use


On Dec 5, 10:44 pm, "Charles E. Campbell, Jr."
Understood. Seems like every forum/group I visit has a different
preference :(

Thanks for the tip, though.

Zach

Tony Mechelynck

unread,
Dec 6, 2008, 10:59:03 AM12/6/08
to vim...@googlegroups.com

It isn't obvious, because AFAICT there's no pattern atom to search for
the nth byte throughout the file. You might try the following (untested):

function SeekToByte(byte)
let l = byte2line(a:byte)
let b = a:byte - line2byte(l) + 1
call cursor(l, b)
endfunction

I think the final cursor will be wrong (but in the right line) if the
line includes, before the desired position, characters which don't
occupy one screen cell per byte. These includes hard tabs (1 to
'tabstop' screen cells per byte), control characters (0x00 to 0x1F other
than tabs and ends-of-lines, 2 screen cells per byte), and possibly some
other characters depending on 'encoding' (e.g., anything above U+007F if
'encoding' is UTF-8). I didn't find exactly how to get the column right
in such a case.


Best regards,
Tony.
--
The difference between science and the fuzzy subjects is that science
requires reasoning while those other subjects merely require
scholarship.
-- Robert Heinlein

Tony Mechelynck

unread,
Dec 6, 2008, 11:05:47 AM12/6/08
to vim...@googlegroups.com

D'uh! And I tried to reinvent the wheel. Thanks for telling us!

I really should have noticed that there was a +byte_offset item in my
":version" listing.


Best regards,
Tony.
--
NAPOLEON: What shall we do with this soldier, Giuseppe? Everything he
says is wrong.
GIUSEPPE: Make him a general, Excellency, and then everything he says
will be right.
-- G. B. Shaw, "The Man of Destiny"

Reply all
Reply to author
Forward
0 new messages