I have been using the gvim command :w to save and it works fine saving it to the desktop. However with the vim program, when I use the command :w, I cannot find where the saved file is located.
It should save to whatever directory you started writing it in (you can see that in the command line). You can also use your computer's file search to locate it and then inspect for the file path.
As said by others: by default it saves in the directory where you started it. But if you aren't aware in which directory you started, then a way to find out is to use the :pwdcom in vim. This will output the current directory. That's where vim will store the file.
C:\Users\"windows user"\AppData\Local\Packages\KaliLinux.54290C8133FEE_ey8k8hqnwqnmg\LocalState\rootfs\home\"WSL user"
Adding another answer to get the filename as well.
As mentioned by Cary and Jeen, vim saves your file to the directory from where it is started. You can get the directory where it is saved using :pwd.
If you are interested to get name of the file, it can be done by ctrl + g when your laststatus=1, which is the default value.
I usually set laststatus=2 which always show the filename.
I am using chocolatey package manager on windows to manage my emacs installation. However, I don't know where to place my .emacs file.
Your .emacs file will be located in your home directory. There's a list of ways Emacs can determine what that directory is. In order, they are:
If you've set the environment variable "HOME", it will be there. This is probably the most common way to set it.
If you set the registry value "HKCU\SOFTWARE\GNU\Emacs\HOME", it will be there
If you have C:\.emacs, it will use that (deprecated)
Finally, it will look in your AppData directory.
The easiest way to find it, if you don't want to manually set one of those values, is to use the command C-x C-f ~/.emacs from within Emacs. This will load the .emacs file in the correct location. Alternatively, you can use ~/.emacs.d/init.el, if you want to keep every Emacs related file in your home directory inside a single folder.
I wanted to keep all files related to vim in one folder under my $HOME directory, more specifically my gvimrc file. I've moved the original .gvimrc file to $HOME/vim/.gvimrc and created a symlink under my $HOME directory. However, when I run source %, simple functions do not run until I exit and restart the session. For example:
function! EchoSomething()
if &bg == dark
echo "bg is dark"
else
echo "bg is light"
endif
endfunction
This should echo the results on the cmdline, but it show nothing when I source my .gvimrc file.
My preferred alternative to a symlink is to add a source directive to an otherwise empty file at $HOME/.gvimrc
So, if you have another .gvimrc at /path/to/it/, instead of creating a symlink, create an empty file at $HOME/.gvimrc and add the line:
source /path/to/it/.gvimrc
gvimrc (with or without a dot and wherever it is located) is not sourced when you use vim in a terminal.
Since 7.4, CLI Vim and GUI Vim look for the classical $HOME/.vimrc and $HOME/.vim/vimrc and GUI Vim also looks look for the classical $HOME/.gvimrc and $HOME/.vim/gvimrc.
So you can safely drop your symlinks and just rename $HOME/.vim/.gvimrc to $HOME/.vim/gvimrc.
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.
Is there any way how to use :sh to open shell in needed directory? So I don't have to use cd to get directory I need. Running something like :sh /your/directory does not work.
If you're just wanting to run your shell in the directory of the file you're editing you could set autochdir - it automatically changes directory to whatever file you are editing.
Maybe not exactly what you're looking for, but I don't know of any built in way to do that. Though you could write a function to do it. Something like this does the trick for me:
function ShellCd(path)
cd `=a:path`
shell
endfunction
Of course the directory will remain changed after you've ran your shell, but it may be possible to change the function to not do that.