Sunday, September 25, 2011

Re: Lines displayed in wrong order on 'Load'

On 09/25/2011 07:59 AM, Bram Moolenaar wrote:
>
> Andrie Avk wrote:
>
>> I'm running into a weird issue with vim 7.3 1-35 on Ubuntu.
>>
>> When a file is modified outside of vim in a way that adds a single line
>> (it's always added in a third line from top, but I don't think that
>> matters), and when you switch to the buffer, Vim prompts to load the
>> file. If I choose to load, the line is displayed as being 4th line from
>> top. If another line is added as third line again, it's now displayed as
>> 5th line, and so on.
>>
>> If I type :edit , lines will show in proper order.
>>
>> For my needs this is not a big issue at all, but I was wondering if this
>> is a known issue, is it fixed in latest vim, should I submit a bug
>> report?
>
> I can't imagine how this can happen. Perhaps a plugin causes problems?
> Did you try starting with "vim -u NONE"?
>


Here's some more detail on what I was doing:

I wrote a python vim function that accepts a line from user input, reads
all lines from a file that's currently loaded in another vim buffer, and
writes the file out again, inserting the new line as 3rd line of the
file.

Initially I wrote it as:

lines = open(fname).readlines()
lines.insert(2, newline+'\n')
with open(fname, 'w') as fp: fp.writelines(lines)

I made a small mistake when describing the issue in my first report, in
fact the first line is added in the correct position, but when I was
adding a 2nd line, it was showing up one line down from where it should
be, 3rd line would be one line lower still, and so on.

I thought that the issue may be that I'm not closing the file explicitly
after reading, so I changed the reading to use the same 'with open ...'
form.

The issue was still present and then I added debugging prints to show
that new lines are in the right position in `lines`, and they were.

Because of :edit of that file showing lines in correct order, I thought
it's a vim problem and not anything to do with the python function.

After a vim restart, however, everything works fine even from the python
function. I don't think this was caused by any plugin because right now
I have all the same plugins loaded.

I'm also not sure why a restart fixed it. I should have tried it before
sending the email.

Thanks,

- ak

--
You received this message from the "vim_use" 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

No comments:

Post a Comment