Hari Krishna Dara wrote:
On Fri, 6 Oct 2006 at 2:53pm, Fletcher Mattox wrote:


When I edit two files by typing ":e foo" and ":e #", vim remembers
my current location in each and kindly positions me there when
I revisit them.  However, when I edit three or more files, vim forgets
where I was and always positions the cursor at the top of the file.
How do I get vim to remember where I was in an arbitrary number
of files?


My observation is that if you don't have 'hidden' option set, Vim will
unload the buffer when it is hidden. And when you reopen the file using
the :e command, it results in getting reloaded, and Vim discards the
saved position (somehow this doesn't apply to :e#). A better way is to
open existing buffers using :buf and :sbuf commands (which preseve the
position) and use :edit only to load new buffers. The :buf commands also
allow you to complete names from loaded buffers.

With a high enough ' (apostrophe) value in your 'viminfo' option, Vim will remember your file marks (including the cursor position) even when you leave a file or exit Vim; and with an autocommand which is defined near the end of the vimrc_example.vim (so if, like me, you source that script, you already have that autocommand), when you reenter a file (at the BufRead autocommand) the previous cursor position is restored. (This assumes that you have +autocmd and +viminfo compiled-in, and that you use 'nocompatible'.)

I don't have 'hidden' and I don't use ":hide". When (after saving any changes) I leave one buffer for another using ":e", the old buffer is unloaded, but not deleted from the buffer list; its marks and cursor position are remembered, and if I go back to it with ":e" later I find myself back where I used to be -- unless too many other files have been edited in the meantime, causing it to disappear "beyond the horizon".

With the 'nocompatible' default value of the 'viminfo' option, the marks (and cursor locations) are remembered for 20 files. You may change the value but not remove the item from an otherwise nonempty 'viminfo' option, so one way to do it would be e.g.

        :let &viminfo = substitute(&viminfo, "'\\d*","'100","")

which replaces the first (and normally the only) apostrophe in the 'viminfo' option value, and all digits immediately following it, by the string "'100", remembering marks and cursor for the 100 latest files instead of 20. Doing it this way avoids clobbering other 'viminfo' settings.

Best regards,

Reply via email to