Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
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. –  Ingo Karkat Nov 23 '12 at 11:24
    
@Ingo: Please post that as an answer. .viminfo was actually owned by root for some reason. Thanks! –  dotancohen Nov 23 '12 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 '12 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 '12 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. –  Ingo Karkat Nov 23 '12 at 13:38

1 Answer 1

up vote 2 down vote accepted

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.)

share|improve this answer
    
Thanks. .viminfo was in fact owned by root. –  dotancohen Nov 24 '12 at 13:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.