Reputation: 185
I am new to the so-called “best text editor” Vim, and I’m struggling to become familiar with the operations it can perform. Some of the problems I encounter are really odd; I’m hoping that someone can give me some help with these:
When I enter gVim and type :cd.
, the prompt shows that I am in C:\Windows\System32
. Why is this? I installed Vim in E:\Vim
. Is it possible to change this default directory to something else?
Is there any method to specify a directory in Vim and create a file (using Vim, of course — not in the command line window by running something like vim someName.txt
) in the specified directory? When I’ve tried commands like :e someFileName.txt
, I receive error warnings about some swap file. Also, if I search for this someFileName.txt
, the location is really strange — it is under C:\Users\MyUserName\AppData\Local\Temp
. Why?
This is even more bizarre: In Windows, the default command line directory is C:\Users\MyUserName
. I don’t like that, so I’ve changed it to C:\
. However, if I press the Start button, type cmd.exe
, and press Enter, the command line window still shows that I am in C:\Users\MyUserName
. If I click the shortcut icon in the task bar, the directory is correct (C:\
). Moreover, if I make such a change, and run Vim in the command line, every time that I close a file I receive an error warning:
can't write viminfo file C:\_viminfo!
After some investigation, I’ve found that if I change the command line directory back to C:\Users\MyUserName
, everything is just fine, and a file named viminfo
is created under this directory. So why does it do this? Can’t Vim create this viminfo
file under C:\
, just as it does in C:\Users\MyUserName
?
Upvotes: 3
Views: 1333
Reputation: 196546
This is the default on Windows. I seem to remember that it depends on how it was installed. Anyway, you can change it to whatever you want by typing the following from normal mode:
:cd <your path>
If you want it to be persistent across sessions, create $HOME/_vimrc
(if you don't have it already) and add the line above without the colon.
You get that error message about swapfiles because you are working in a protected directory: the swap can't be created. The answer above should solve this problem in a general way. Anyway, you can edit files anywhere you can write to disk. In the example below, ~
is a shortcut to your $HOME
directory, like in UNIX:
:e ~\filename
Do you have write rights in C:
? I'm not a Windows user so don't take my word for it, but I think that C:\Users\MyUserName
should really be your $HOME
.
Did you run vimtutor
? It's the absolute best way to learn the basic editing commands.
edit
And while we are at it…
Refrain from installing too many (or the latest trending) plugins. If you feel that a certain plugin would be useful, search for alternatives on vim.org and compare before you jump on the bandwagon.
Similarly, avoid "distributions" like the plague. They change too many things and will drag you back on your path to enlightenment.
Get to know how to use the :help
. Answers to most of your questions are there.
Upvotes: 5