2

In VIM 7.3 on Ubuntu Server 12.04.1, VIM forgets macros and registers after closing. I do have set nocompatible in .vimrc and the command :set viminfo? gives this result:

viminfo='100,<50,s10,h

What might be preventing the macros and registers from being stored across close / open?

Note that I am not interested in storing mappings for long term use in .vimrc. Rather, sometimes (such as during refactoring) I need to perform a simple operation on a few files and I find it easier to do in VIM than with Perl. I just need the macros and registers stored across open / close, which I do have working on other servers.

Thanks.

5
  • 1
    Are the register contents actually stored? You can check with less +/Registers: ~/.viminfo. Also, check whether the file belongs to / is writable by your user. Nov 23, 2012 at 11:24
  • @Ingo: Please post that as an answer. .viminfo was actually owned by root for some reason. Thanks!
    – dotancohen
    Nov 23, 2012 at 12:28
  • When you have something that works on context A and doesn't on context B the very first thing to do is to compare setups on A and B. Did you do that? Is there any difference?
    – romainl
    Nov 23, 2012 at 12:29
  • Thanks, romainl. In fact, I thought that I checked everything relevant but I did not check .viminfo ownership. There is always something additional relevant!
    – dotancohen
    Nov 23, 2012 at 12:32
  • Ah, glad I could help. I actually recently had the same problem on a new VM, this was caused by first running sudo vim; I've expanded this into an answer. Nov 23, 2012 at 13:38

1 Answer 1

4

Macros are the same as (named) registers. You can check whether the register contents are actually stored with the following shell command:

less +/Registers: ~/.viminfo

Also, (e.g. when you've executed sudo vim and there wasn't yet a .viminfo file), the viminfo file may be not writable by your user, so your changes won't persist any more; check with

ls -l ~/.viminfo

that your user is the file owner and the permissions are alright. (Fix with chown / chmod.)

1
  • 2
    Thanks. .viminfo was in fact owned by root.
    – dotancohen
    Nov 24, 2012 at 13:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .