Vim error - E138: Can't write viminfo file

8,783

It looks like you need to set the location of your viminfo file as well, with something like:

set viminfo+=n~/.vim/viminfo

See :help viminfo and :help 21.3 for more information.

Share:
8,783

Related videos on Youtube

Technext
Author by

Technext

Updated on September 18, 2022

Comments

  • Technext
    Technext over 1 year

    I have already checked several similar links but nothing worked. Before i explain the issue, i was earlier getting following message while saving any file:

    vim e509 Cannot create backup file (add ! to override)
    

    While searching for solution, i came across several links which suggested creating .vimrc file. So i created one and entered the following contents in it:

    set backup
    set backupdir=~/.vim/backups
    

    I also created the ~/.vim/backups directory. Also, there is no .viminfo file. I think i removed it while trying to fix things.

    Few other details that might be of interest are:

    -sh-4.2$ id
    uid=497(git) gid=496(git) groups=496(git)
    -sh-4.2$ ls -ld .vim*
    drwxr-xr-x 3 git git 4096 Dec 28 21:59 .vim
    -rw-r--r-- 1 git git   40 Dec 28 22:09 .vimrc
    -sh-4.2$ ls -l .vim/
    drwxr-xr-x 2 git git 4096 Dec 28 22:11 backups
    
    -sh-4.2$ pwd
    /var/opt/gitlab
    -sh-4.2$ ls -ld /var/
    drwxr-xr-x 20 root root 4096 Dec 20 22:31 /var/
    -sh-4.2$ ls -ld /var/opt/
    drwxr-xr-x 3 root root 4096 Oct 21 21:01 /var/opt/
    -sh-4.2$ ls -ld /var/opt/gitlab/
    drwxr-xr-x 15 root root 4096 Dec 28 22:08 /var/opt/gitlab/
    

    Now with the above permissions in place (no write for any user in any of the parent dirs), whenever i switch to git user and try saving any file, i am now getting the following error:

    E138: Can't write viminfo file /var/opt/gitlab/.viminfo!
    Press ENTER or type command to continue
    

    Is the above error expected or am i doing something wrong? GitLab application creates git user as part of the install process so i am not sure whether changing the permissions will be a good idea.

    System Info:
    [root@gitlab gitlab]# cat /etc/*release
    NAME="Amazon Linux AMI"
    VERSION="2015.09"
    ID_LIKE="rhel fedora"
    
  • Technext
    Technext over 8 years
    Thanks a lot! It worked. Thanks for the help references too. :) This issue was bugging me for long time.
  • blm
    blm over 8 years
    You're welcome, glad to help.