vim autoload folder permission denied? - vim

I'm trying to edit files in my .vim/autoload folder but somehow I don't have permission. sudo doesn't work. I've never had this issue before. The only change is that I've upgraded to a new macbook but all directories are the same.

Answered in the repost in Vi & Vim.
Problem was directory was created with sudo.
Solved with:
$ sudo chown -Rh gabe:staff ~/.vim
$ chmod -R a+rX,u+w,go-w ~/.vim

Related

CentOS 6.7 Root user home deleted?

Some how I managed to delete the /root directory, so I went and recreated and set the proper permissions to the file directory. However, my command line is different and instead of showing root#my-machine# I get -bash-4.1#.
How can I fix this?
Thanks
So you deleted /root and now you have -bash-4.1# in your command line huh?
Well this is caused of a missing / corrupt .bashrc (in your case missing) file in /root (.bashrc sources /etc/bashrc which is what sets the prompt). To fix it, you will run the following command which runs when an account is created. Run as the root user (since it is the user having the problem) or you can define the destination path.
command: (make sure you are in /root)
cp -v /etc/skel/.bash* ~/
Exit terminal and log back in.
I was able to fix the error by creating a new .bashrc
Because the /root directory was removed the default .bashrc was deleted.
I fixed it by running
/bin/cp /etc/skel/.bashrc ~/
and then sourcing the new .bashrc file with source ~/.bashrc

.vimrc configuration file does not load when editing as root

I looked at .vimrc configuration file does not load when editing with 'sudo', but the accepted answer doesn't work for me. I have put a test line echo "it works!" into my ~/.vimrc. When I edit a file as user, it works. When I edit a file as root it doesn't. I have linked .vimrc and .vim to the same in /root; so that, they show up there. I have tried sudoedit, sudo vim and su then vim, but nothing works.
I have done some more testing and found that vim -u /home/colin/.vimrc works while I'm root except that it doesn't find the color scheme. But, vim -u /root/.vimrc fails with:
E282: Cannot read from "/root/.vimrc"
So, then I tried to cat .vimrc and ls .vim while root in /root, and got
Too many levels of symbolic links
Once I got the Too many levels of symbolic links, I simply recreated the links. However, when the links were first created, I was in fact able to cat and ls them as root user from \root. So, I don't really know what the problem was or how it was really solved.
Here is what I did though:
su
vim -u /home/colin/.vimrc works but can't load plugins
vim -u /root/.vimrc failed with error message
cd ~ (which took me to \root since su in step 1 made me root)
cat .vimrc and ls .vim both failed and complained Too many levels of symbolic links
rm -r .vimrc .vim
ln -s /home/colin/.vimrc ./.vimrc
ln -s /home/colin/.vim ./.vim
exit
All I did is just create two simple soft links. Since you will not change the name of the .vimrc or .vim files, all you need is just add two pointers to your local user's configuration file. Try this in your terminal:
sudo ln -s ${HOME}/.vimrc /root/.vimrc;
sudo ln -s ${HOME}/.vim /root/.vim;

File disappeared on Linux. Search says it's still there

So I was editing a cpp file in sublime on my linux machine and I'm not sure what I did or what happened but all of a sudden the file disappeared on sublime. So it went to it's directory to open it back up but it's not there.
I did a quick search for it and it says it's says it's still in the the directory it was in but it doesn't show the actual file.
I don't think it's hidden. Any ideas??
Thanks
Use chmod to give permission to use the file in user.
chmod 777 <filename>
Before running this command you have to open root privilege by using sudo su command.

Linux : How to delete locked file

I want to remove xyz_DB.lock.db file. I tried as root but couldn't delete it. How to remove it in terminal. My initial requirement was remove a folder. but it includes this locked file. And is there anyway to delete folder directly which include a locked file ?
Check with lsattr command if the immutable bit is set for the file, it will show (i)
# lsattr file
----i--------e- file
If so, change it using following command:
# chattr -i file
And then try to remove it.
Try either changing the files permissions through the GUI or use rm -rf on the directory that contains it.
try "chown" to provide permission to your file/folder and then delete it,
e.g: assume username= amol and filename=myfile.txt,,
For File:--- sudo chown amol:amol myfile.txt
For Folder:-- sudo chown -R amol:amol directory_name

Use sudo with .vimrc

I'm using CentOS and created a .vimrc file in my /home directory. I tested it out by creating a txt file and yes, that worked fine. Now, I have my project files in my /srv directory with SELinux turned on. I tried opening a file: vim README.txt and yes, my .vimrc settings are still being applied.
Now, since I'm in the /srv directory, simply doing vim means that my file is read only. So, I do sudo vim README.txt in order to be able to edit files. Now, the problem lies that once I do sudo, none of my .vimrc settings are applied. I tried creating a copy of .vimrc in the /srv folder but that didn't work either.
How do I apply .vimrc settings while using sudo?
Use sudoedit instead of sudo vim. You should be doing that anyway. Make sure your EDITOR environment variable is set to vim (probably already is, or vim is the default; you can set it in your .profile analog if need be).
As shown here, you can use the following:
sudo -E vim README.txt
From the man page:
-E The -E (preserve environment) option indicates to the security policy that the user wishes to preserve their existing environment variables. The
security policy may return an error if the -E option is specified and the user does not have permission to preserve the environment.
The accepted answer is the most secure. But this one is more flexible as I can use sudo -E operation with any operation, I don't have to configure anything else beforehand.
/root/.vimrc is the working directory of sudo vim.
You need copy your .vimrc file from /home/ec2-user/.vimrc to /root/.vimrc
The presented solutions in the other responses work but are not very practical, as you have to enter you password every time you want to edit a file.
I usually have a tmux session open within which I am rooted via sudo su, so I enter my password once at the beginning of the session and can then work for hours without having to enter it again.
I worked around the issue presented here by creating the following symbolic links :
sudo su
ln -s /home/MY-USER-NAME/.vimrc .vimrc
ln -s /home/MY-USER-NAME/.vim .vim
You might need to remove the /root/.vim/ directory first.
I hope this helps

Resources