How do I create the folder .vimrc? - macos

I'm new to VIM so I was doing the VIM tutorial and in the Lesson 7.2 it asks to edit the .vimrc file in the ~/.vimrc directory by typing this command: :e ~/.vimrc but I get an error E37: No write since last change (add ! to override) I didn't know what to do so I tried to find if that file existed but it didn't. I searched for "Where is my .vimrc file" and found this answer: https://stackoverflow.com/a/10921485/5220885 but I don't know how to create it, I wanted to ask in the comments but I don't have enough reputation.

Your error has nothing to do with .vimrc as such, rather it is simply Vim warning you that you are trying to edit a different file when you are already editing another one with unsaved changes.
If you write the changes to your current file, :w, first you won't get the error. Alternatively as the error suggests you can discard the changes and switch to editing .vimrc by adding the exclamation mark to the command, :e! ~/.vimrc
Of course you can just type vim ~/.vimrc in the Terminal to open and edit the file.
HTH

Related

How to get rid of multiple sub files created while usng VIM in Windows

Vim is creating multiple sub files when editing a file under Windows. Please let me know how can I get rid off from the files like - .app.js.un~ or app.js~.
FYI - I also closed the command prompt and still these temporary files exists in the folder.
I saved the files with :wq!
Let me know what settings/config I need to change or what I am doing wrong with the command.
Please check the screenshot -
<file>.un~ is an undo history file and let you undo/redo changes (u/Ctrlr) even after closing and opening again the file later.
<file>~ is a backup file with all file contents before your last change.
If you really want to disable them do:
:set noundofile
:set nobackup
Or add the same commands into <Programs>/Vim/_vimrc.
Note that the undo file is not enabled by default, so you can just delete or comment the set undofile command you will find in your <Programs>/Vim/_vimrc file.

Mac Terminal Prompt of iTerm with Oh-my-Z is messed up

I'm not sure exactly what I did besides try to uninstall an application but it seems my prompt is not working. I just want my iTerm 2 back to the way it was...
Here is my .zshrc file and the prompt. It looks bad. How do I fix this?
It looks like you are using Oh-My-ZSH. In that case you should be able to restore at least the default settings with:
cp $HOME/.oh-my-zsh/templates/zshrc.zsh-template $HOME/.zshrc
This will of course overwrite your ~/.zshrc, but the first line is in the template anyway and the second line is a bash-styile definition for the shell prompt and has no place in a zsh configuration file.
After copying the template I would suggest having a look into the new ~/.zshrc to see, if there are any other settings you want to make.
If the cp command fails because it cannot find the source file, then you probably have somehow removed Oh-My-ZSH. In that case you can re-install it by following the instructions on OhMyZ.sh.

Can't find .zshrc file

Recently I installed someone else .dotfiles and as excepted overwrited my configuration.
The thing is that I want to use my custom settings for my ZSH but I can't find .zshrc inside ~/, I have other .zshrc.files but editing none of these is working.
Also the dotfiles I've installed are in `~/.dotfiles but seems that none of these contains config.
Can someone please explain me how to edit the ZSH now, can I revert my old .zshrc?
Go to home directory typing cd
Type the command zsh and Press Enter
Select the option (2) Populate your ~/.zshrc with the configuration
recommended
by the system administrator and exit (you will need to edit
the file by hand, if so desired).
(You have to type "2" to select it and press enter)...
then all the files will be created on the directory..

Patching macvim remote editing, file netrw.vim

So there's a problem with macvim when doing remote editing through
:e scp://path/to/file
Every time I try to save :w, macvim complains E382: Cannot write, 'buftype' option is set.
The quick fix to solving this is to do :set buftype:""
However, there are patches out there to solve the issue. So I downloaded a patch file to fix this problem. The problem is located in the netrw.vim file. When I try to patch the file netrw.vim through patch -p1 < file.patch, it gives me an error that says
patch: **** Can't rename file netrw.vim to netrw.vim.orig : Permission denied
I tried chmod for netrw.vim, but it doesn't let me.
Any help is appreciated!
p.s. I'm running on OSX 10.9.5
I just tried mvim scp://hostname/, picked a file, edited and changed it, and saved it. It worked.
I then tried mvim scp://hostname/somefile, edited and changed it, and saved it. It worked.
So, I suggest that you upgrade: you can find netrw v154b on http://www.drchip.org/astronaut/vim/index.html#NETRW .
btw, the mvim I used is v7.4.258 .
if you opened a remote directory and selected a file to edit you need create the tmp file in you local and set this command :set by=acwrite or :set buftype=acwrite and finally save your changes :w.

Vim Can't Save File (E212)

Sometimes when I create a file using vim some/path/newfile, vim lets me edit it, only to complain when I attempt to save my changes.
E212 Can't open file for writing.
This appears to happen only when the new file is located in a system directory.
:w! does not override this error.
How can I write the current buffer, without having to save it to a temporary location, exit, then rename it using sudo?
This will ask you for the root password, then save your changes as you requested:
:w !sudo tee %
Then type (L)oad at the prompt, to re-load the file after it is saved.
You can mkdir first, then save it.
Add this line to your .vimrc:
cmap w!! %!sudo tee > /dev/null
and then you can do
:w!!
when you get into this position, and it will write the file using sudo. Very handy.
You can avoid this problem by using "sudo" to start the editing session.
sudo vi name-of-file
If you want a robust, easy-to-remember solution and don't mind installing a plugin, try SudoEdit.vim - Edit Files using sudo or su or any other tool.
If this is the case in Windows 7 or later editions, run the VI editor as Administrator. Right Click of the application and select "Run as Administrator". This issue will be resolved. Moreover, the error is due to Administrative Privileges.
vim some/path/newfile
you can try to do it in two steps,first create the folder 'some' and 'path' by use mkdir ~ ;second you go into the 'path' folder,use the command:sudo vim newfile.then save it
Make sure the directory where you are trying to save the file exists and that you have permission to edit the file.
You can type :help message in Vim to get more information on this and other error messages. Try searching by typing /E212 once the docs come up. You can also view the documentation online at http://vimdoc.sourceforge.net/htmldoc/message.html and CTRL-F to find it.
For what it's worth, you may also want to ensure you have sufficient storage in the partition where you're attempting to save the file. I had to free up some space in my /home drive and that resolved the issue.
I know this is an old question, but this is what fixed it for me. Your file might be set to immutable meaning that you can't edit it.
You can check this with lsattr /path/to/file.txt
If it is use
chattr -i /etc/resolv.conf to make it no longer immutable.
Just had this issue outside of system directory.
When I tried to open a file vim src/help/tips.c. Turns out help directory did not exist, the directory was named differently and it was one of those very rare occasions that I did not auto-complete with Tab.
So, in conclusion, if this happens for a file that is not at a place where you may have permission issues, look if the path leading up to the file is a valid one.
I have experienced this in Kali!! The default account requires escalation to root with "sudo" in order for the file to be editable.
e.g: sudo vim / at this point all standard expectations appear to follow.

Resources