View Full Version : [SOLVED] How can I change permission of vimrc so that I can write to it?
zeynel2
October 28th, 2013, 12:29 AM
Now
$ :e $MYVIMRC opens a read only version.
apollothethird
October 28th, 2013, 12:36 AM
Now
$ :e $MYVIMRC opens a read only version.
Your code block suggest that you're at a command prompt. If you're at a command prompt, the ":e" command should give you an error message.
Which application are you running? I can test the application and give you more details.
In the meantime will you give us the output of these commands:
$ echo $MYVIMRC
$ ls -l $MYVIMRC
Those commands are executed at the shell prompt.
-- L. James
--
L. D. James
ljames@apollo3.com
www.apollo3.com/~ljames (http://www.apollo3.com/~ljames)
zeynel2
October 28th, 2013, 01:15 AM
I am sorry, I was actually in vim and opened the file with :e $MYVIMRC but could not write to it. That's why I was asking how to change the permission in vim so that I can write to it.
apollothethird
October 28th, 2013, 07:48 AM
I am sorry, I was actually in vim and opened the file with :e $MYVIMRC but could not write to it. That's why I was asking how to change the permission in vim so that I can write to it.
If you tell us the results you get when you type in the commands I gave you in my first reply we could most likely easily identify your problem and tell you exactly what to do to resolve the issue.
-- L. James
--
L. D. James
ljames@apollo3.com
www.apollo3.com/~ljames
zeynel2
October 28th, 2013, 11:13 AM
Here are the results:
a@b:~$ echo $MYVIMRC
a@b:~$ ls -l $MYVIMRC
total 60
drwxr-xr-x 2 a a 4096 Oct 19 15:35 Desktop
drwxr-xr-x 10 a a 4096 Oct 27 15:17 Documents
drwxr-xr-x 2 a a 4096 Oct 27 12:10 Downloads
drwx------ 5 a a 4096 Oct 27 15:14 Dropbox
-rw-r--r-- 1 a a 8445 Oct 19 15:21 examples.desktop
drwxrwxr-x 2 a a 4096 Oct 19 15:45 leiningen
drwxr-xr-x 2 a a 4096 Oct 19 15:35 Music
drwxrwxr-x 6 a a 4096 Oct 19 17:30 my-new-project
drwxr-xr-x 2 a a 4096 Oct 27 12:10 Pictures
drwxr-xr-x 2 a a 4096 Oct 19 15:35 Public
drwxr-xr-x 2 a a 4096 Oct 19 15:35 Templates
drwxrwxr-x 2 a a 4096 Oct 22 19:34 Ubuntu One
drwxr-xr-x 2 a a 4096 Oct 19 15:35 Videos
a@b:~$
Impavidus
October 28th, 2013, 02:10 PM
Usually your vimrc is in a file called .vimrc, which can be found automatically by vim. I don't think vim checks for the environment variable MYVIMRC, but maybe you had something special in mind.
Vim understands environment variables and the command :e $MYVIMRC will cause it to read the environment variable MYVIMRC, which may contain the string foo.txt, and then vim will open the file foo.txt for editing. In your case it seems that the environment variable MYVIMRC doesn't exist, in which case vim will open the file $MYVIMRC (yes, the string you gave, including the dollar sign) for editing in the current directory. If the file exists but you don't have write permission for the file or if the file doesn't exist and you don't have write permission in the current directory, the file will be read-only.
BrunoLotse
October 28th, 2013, 02:59 PM
Hi:) execute this command
chmod 600 ~/.vimrc Now you should be able to open it in write mode.Cheers, Bruno
apollothethird
October 28th, 2013, 05:30 PM
Here are the results:
a@b:~$ echo $MYVIMRC
a@b:~$ ls -l $MYVIMRC
total 60
drwxr-xr-x 2 a a 4096 Oct 19 15:35 Desktop
drwxr-xr-x 10 a a 4096 Oct 27 15:17 Documents
drwxr-xr-x 2 a a 4096 Oct 27 12:10 Downloads
drwx------ 5 a a 4096 Oct 27 15:14 Dropbox
-rw-r--r-- 1 a a 8445 Oct 19 15:21 examples.desktop
drwxrwxr-x 2 a a 4096 Oct 19 15:45 leiningen
drwxr-xr-x 2 a a 4096 Oct 19 15:35 Music
drwxrwxr-x 6 a a 4096 Oct 19 17:30 my-new-project
drwxr-xr-x 2 a a 4096 Oct 27 12:10 Pictures
drwxr-xr-x 2 a a 4096 Oct 19 15:35 Public
drwxr-xr-x 2 a a 4096 Oct 19 15:35 Templates
drwxrwxr-x 2 a a 4096 Oct 22 19:34 Ubuntu One
drwxr-xr-x 2 a a 4096 Oct 19 15:35 Videos
a@b:~$
Hi, Zeynel2.
Thanks for giving us this information. The problem you were experiencing had nothing to do with the permissions of your vimrc file. From the output, you were trying to access and write to something that didn't exist.
Try using the ":e" command to actually create and write to the file you wish to write to (i.e. :e .vimrc). You won't have to bother with the permissions. The permissions will automatically be set when you create the file. Again, the command you were using was not performing what you expected.
-- L. James
--
L. D. James
ljames@apollo3.com
www.apollo3.com/~ljames
BrunoLotse
October 28th, 2013, 06:50 PM
Not true.
From the provided output we have no idea wether .vimrc exists or not on the system. Most probably it does exist. We need the output of hidden, i.e. dot files. Search for hidden files and you most probably see .vimrc with read only permissions. Cheers.Bruno
Impavidus
October 28th, 2013, 10:29 PM
At no point the OP has referred to .vimrc. He has only referred to $MYVIMRC, which is an undefined variable. It's very unlikely he actually wanted to create a file with the name $MYVIMRC, but that is what he told vim to do and what is what didn't work. Most likely he wanted to write to the file ~/.vimrc. So the less relevant question is: Does the OP have write permission in the current directory? The more relevant question is: How does one make the environment variable MYVIMRC point to the file ~/.vimrc? This can be done by putting it in ~/.bashrc, but I don't think he actually needs it. Vim will check ~/.vimrc by default. Just refer to it by its name and forget about the MYVIMRC, unless you had something special in mind.
zeynel2
October 28th, 2013, 11:55 PM
Hi:) execute this command
chmod 600 ~/.vimrc Now you should be able to open it in write mode.Cheers, Bruno
Thanks, this worked, but I had to add sudo:
sudo chmod 600 ~/.vimrc.
apollothethird
October 29th, 2013, 12:01 AM
Thanks, this worked, but I had to add sudo:
sudo chmod 600 ~/.vimrc.
Hi, Zeynel. Glad you got your issue resolved.
By the way, as I mentioned before, you didn't have to change your ~/.vimrc for access permission. You already had access just by actually creating the file.
Finally, if your issue is resolved, please consider using the system tools to make the thread as SOLVED. This would be an appreciated contribution back to the community. Others with a similar question can easier find their solution.
Have a nice day!
-- L. James
--
L. D. James
ljames@apollo3.com
www.apollo3.com/~ljames
zeynel2
October 29th, 2013, 12:01 AM
Thanks, for the help. I read my question, and indeed it was too terse and confusing. I was trying to follow the instructions here http://vim.wikia.com/wiki/Open_vimrc_file#Opening_vimrc to open .vimrc, that's why
:e $MYVIMRC was in my question.
apollothethird
October 29th, 2013, 03:29 AM
Thanks, for the help. I read my question, and indeed it was too terse and confusing. I was trying to follow the instructions here http://vim.wikia.com/wiki/Open_vimrc_file#Opening_vimrc to open .vimrc, that's why
:e $MYVIMRC was in my question.
Zeynel2. It appears, after reading your link and running local test, the string variables are expanded when in the vim environment. That takes us back to my original assessment (as a few others has mentioned), your problem was in that you didn't have a the $MYVIMRC variable set to anything.
Your link says this is set automatically. However, it appears that, this isn't so (the automatic set of the variable) in every distribution... as in the case of the Ubuntu version you and I are apparently running.
You can remedy this by manually setting the MYVIMRC in your .bashrc file. After the setting of the variable, it'll work for you just as it does in the link you posted.
-- L. James
--
L. D. James
ljames@apollo3.com
www.apollo3.com/~ljames
zeynel2
October 29th, 2013, 11:51 AM
Vim understands environment variables and the command :e $MYVIMRC will cause it to read the environment variable MYVIMRC, which may contain the string foo.txt, and then vim will open the file foo.txt for editing. In your case it seems that the environment variable MYVIMRC doesn't exist, in which case vim will open the file $MYVIMRC (yes, the string you gave, including the dollar sign) for editing in the current directory.
Yes, this is what happens. How do I set $MYVIMRC to open .vimrc? :e echo $MYVIMRC as explained here http://stackoverflow.com/a/8977682/215094 does not seem to work.
BrunoLotse
October 29th, 2013, 12:47 PM
Hi :)You don't have to set MYVIMRC in your environment. vim is able to figure it out on its own. Try this. Open some other file on your system - like
vim ~/my_test_file.txt When the file is on type
:e $MYVIMRC Vim should open config file .vimrc set on your system.Cheers,Bruno
Impavidus
October 29th, 2013, 02:13 PM
I would have sworn it didn't work yesterday (I have got a .vimrc). Maybe I made a typo.
BrunoLotse
October 29th, 2013, 02:53 PM
All well that ends well :)Here you will find a good example of vimrc file http://vim.wikia.com/wiki/Example_vimrcTry learn and use vi. It's worth it. Cheers, Bruno
zeynel2
October 30th, 2013, 10:53 AM
Hi :)You don't have to set MYVIMRC in your environment. vim is able to figure it out on its own. Try this. Open some other file on your system - like
vim ~/my_test_file.txt When the file is on type
:e $MYVIMRC Vim should open config file .vimrc set on your system.Cheers,Bruno
Thanks, but when I do this exactly as instructed, vim opens a new file named $MYVIMRC; it does not open my existing .vimrc file.
BrunoLotse
October 30th, 2013, 01:06 PM
Hi:) This is strange. You mentioned that you need to apply sudo when changing .vimrc permissions. This is also fishy. It looks like some other user is owing your config file. Try to figure out what user it is.
\ls -l ~/.vimrc When you execute this do you see your username?Cheers,Bruno
zeynel2
October 31st, 2013, 11:07 AM
Hi, Bruno, thanks for the help. This is what I see:
a@b:~$ \ls -l ~/.vimrc
-rw------- 1 root root 964 Oct 30 06:07 /home/a/.vimrc
a@b:~$
BrunoLotse
October 31st, 2013, 01:00 PM
Hi:) Yep, we see that file ~/.vimrc belongs to root. But it should belong to you, i.e. user a. So you have to change ownership of the file
sudo chown a:a /home/a/.vimrcYou are changing root to user a. Run ls -l ~/.vimrc, make sure that root is gone and a is in place and then run vim. When vim is running execute
:e $MYVIMRCvim should open your ~/.vimrc config file which you can edit.Cheers, BrunoP.S. You're welcome:)
Impavidus
October 31st, 2013, 01:13 PM
And to prevent it from becoming root-owned again, never edit your .vimrc from vim when running as root. I suspect that's what happend.
zeynel2
October 31st, 2013, 11:56 PM
And to prevent it from becoming root-owned again, never edit your .vimrc from vim when running as root. I suspect that's what happend.
Can you explain this? I am still very confused about the file management. Why would it run vim as root?
zeynel2
October 31st, 2013, 11:57 PM
Great, thanks again, this is now working.
Impavidus
November 1st, 2013, 12:40 AM
Maybe you thought: Let's change this root-owned file, and then typed sudo vim <filename>. Then you thought: I want to change my .vimrc, so you typed :e $MYVIMRC. Then you saved your .vimrc and it would have been root-owned, as vim was running as root.
I've seen many tutorials telling people to work with certain root-owned files, probably because they are always there. I think it's wiser to stay away from them when following tutorials. You don't know yet what you're doing.
apollothethird
November 3rd, 2013, 01:28 AM
Great, thanks again, this is now working.
Hi, Zeynel2.
We are glad you have your issue resolved.
Please consider that you can actually give back to the community by marking this issue as solved. It'll save out time when reviewing unsolved issues trying to help users who are still trying to get a resolution. It'll also help others who have a similar issue to zoom in on the threads that have been resolved.
You can mark it solved by clicking on "Tread Tools" > "Mark this thread as solved".
Thanks again for any consideration on this.
We are always glad to help!
-- L. James
--
L. D. James
ljames@apollo3.com
www.apollo3.com/~ljames
Powered by vBulletin® Version 4.2.2 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.