Vim inserting _viminfo files after every save - windows

I just did a clean (re)install of Vim (Downloaded from vim.org/download.php, used the gvim73_46.exe installer. Version is 7.3 (patches 1-46)
The only changes to my _vimrc are to set line numbers, lines, columns, and enable syntax.
Everytime I edit a file with vim, save it and close it (:wq), a new _viminfo file is created in that files directory.
Also, the backup *.*~ files and .swp files persist, and arn't cleared upon saving. Running Windows 7 enterprise.
This really clutters everything - and is a pain trying to open a file for which a .swp file exists..
Help?

disable viminfo file:
set viminfo="NONE"
disable swap file:
set noswf
disable backup :
set nobk
set nowb
more details:
:h 'swf'
:h 'bk'
:h 'wb'
:h 'viminfo'

That's strange; the viminfo file should be written in your home directory, nowhere else:
The default name of the viminfo file is "$HOME/.viminfo" for Unix and OS/2,
"s:.viminfo" for Amiga, "$HOME_viminfo" for MS-DOS and Win32. For the last
two, when $HOME is not set, "$VIM_viminfo" is used. When $VIM is also not
set, "c:_viminfo" is used. For OS/2 "$VIM/.viminfo" is used when $HOME is
not set and $VIM is set.
It appears as if your %HOME% variable (or the %HOMEDRIVE%%HOMEPATH%) isn't properly set.

Related

Windows gVim 7.3 is creating unexpected folders when opening a file

My setup is:
Windows7 SP1 (Enterprise)
gVim 7.3
Whenever I open a file, Gvim will create 2 folders in the same folder as the file is located. The folders' names are Files and (x86). This only started happening recently. Any idea what could be causing this?
My _vimrc files is as follows
set nocompatible
source $VIMRUNTIME/vimrc_example.vim
behave xterm
set ic
set nu
set ai
set noswapfile
set nobackup
source $VIMRUNTIME/colors/darkblue.vim
set expandtab " expand tabs
set shiftwidth=3
set softtabstop=3
set ruler " show the cursor position all the time
source $VIMRUNTIME/plugin/linuxsty.vim
Do you have any plugins installed? Then try running without them (--noplugin argument), also try a plain Vim gvim -N -u NONE.
It looks like some plugin doesn't do proper quoting of an argument.
You can capture a full log of a Vim session with vim -V20vimlog. After quitting Vim, examine the vimlog log file for suspect commands.

Vim unhides hidden files on Windows

I've noticed that Vim (gVim on Windows 8) unhides hidden files.
By hidden files I don't mean dotfiles; in Windows we don't have dotfiles. It appears that the 'hidden' file attribute on the file is being removed.
Any suggestions/workarounds?
We see this problem on Windows when the writebackup option is enabled and backupcopy is set to no or auto. To fix it, add the following line to .vimrc:
set backupcopy=yes
The writebackup setting instructs Vim to make a backup before overwriting a file, and backupcopy controls how this backup file is created:
"yes" make a copy of the file and overwrite the original one
"no" rename the file and write a new one
"auto" one of the previous, what works best
As we can see, when the value of backupcopy is set to no, Vim will rename the original file that contains the hidden attribute and write a new file in its place without that attribute set (and then delete the backup file afterward unless we enable the backup option). This is faster but can cause problems with file attributes and symlinks.
For more information, read :help backupcopy. We can check the current values of writebackup and backupcopy by running:
:set writebackup? backupcopy?

Vim opens a new folder instead of an existing file with `set enc=utf-8` enabled

When I open a file with vim or gvim from console on windows that is located in a sub directory (e.g. gvim subdir/file), it creates a new file at subdir\subdir\file saying "subdir\file" [New DIRECTORY] instead of simply opening the existing file at subdir\file.
This happens since I added the following line to my vimrc:
set enc=utf-8
Is there a possibility to open and create files in UTF-8 mode on Windows without this issue?
You may also look at my vimrc file.
Thank you for any help.
Change the order of the autochdir and encoding options in your vimrc. First set the encoding then autochdir
set enc=utf-8
set autochdir
An explanation can be found here

Vim: Change start up directory?

When I start GVim and start writing my little program I'd like to save the file to the Desktop but it seems that Vim is starting the command line in:
C:\Windows\System32
How would I go about changing that to:
C:\Users\Casey
so then I could just:
:w Desktop\my_program.py
Assuming you're starting gvim from an icon/shortcut in Windows (from the kind of paths you supply), you can change the starting directory (completely independent from the fact that it IS gvim: it would be the same from any other app!) by editing the "starting directory" property of that Windows icon/shortcut.
Within vim, you can change the current directory with the :cd command:
:cd c:\users\casey
I found this way to be better:
Open gVim
:cd $vim
:e _gvimrc
Add the following line:
:cd c:\users\user\desktop\
I found that :Ex is slow on large directories like c:\windows\system32\ (where gVim usually starts).
Also, here is my full _gvimrc in case anyone is interested. I prefer Consolas for coding. The tabstop setting helps when coding especially in Python, and Ctrl+Tab/Ctrl+Shift+Tab is great for switching between buffers:
set guifont=Consolas:h12:cANSI
set tabstop=4 softtabstop=4 shiftwidth=4 expandtab
map <C-Tab> :bnext<cr>
map <C-S-Tab> :bprevious<cr>
:cd c:\users\user\desktop\
How about changing your starting position?
vim icon -> right click -> property -> shortcut -> Start in -> your path you want to change.
but it works perfectly.
I think :cd yourpath also works. but it will change when you don't want to change.
Use :cd c:\users\casey,
after that save into session (in gVim there is button up and down in red, click on it and save as mySessionProject.vim). Next time you need to go to that directory, open that session (you can also use :source mySessionProject.vim)
for command line:
:mksession! yourdir/yourVimConfName.vim
to load
:source yourDir/yourVimConfName.vim
I found the following to be very useful. I am on Windows 7 and vim 7.3.46, and am using gVim.
I edited startup settings, which wound up altering the _vimrc in c:\Users\me\.
I also tried using :version and editing the _vimrc files I found at $VIM, as well as the _vimrc I found at c:\windows\system32.
Editing those files to include :cd c:\Users\me did not result in my default startup directory changing after starting vim. I wanted my default directory to be c:\Users\me\, and editing c:\Users\me\_vimrc achieved that. That is I entered
:e $MYVIMRC
and added
cd c:\Users\cnorton.Arlington1\
to that file.
Just to to put this up incase anyone needs it:
vimrc accepts enironmental parameters. you can put cd $USERPROFILE in your vimrc
Use this mapping in your .vimrc file
:cd $USERPROFILE\Desktop<cr>
or the same shorter
cd ~\Desktop<cr>
A mapping that also displays afterwards the path instead of the command
nmap <leader>d :cd ~\Desktop<cr>:pwd<cr>
Inside init.vim, I use:
lcd $HOME/Projects

Where can I find my .emacs file for Emacs running on Windows?

I tried looking for the .emacs file for my Windows installation for Emacs, but I could not find it. Does it have the same filename under Windows as in Unix?
Do I have to create it myself? If so, under what specific directory does it go?
Copy and pasted from the Emacs FAQ, http://www.gnu.org/software/emacs/windows/:
Where do I put my init file?
On Windows, the .emacs file may be called _emacs for backward compatibility with DOS and FAT filesystems where filenames could not start with a dot. Some users prefer to continue using such a name, because Windows Explorer cannot create a file with a name starting with a dot, even though the filesystem and most other programs can handle it. In Emacs 22 and later, the init file may also be called .emacs.d/init.el. Many of the other files that are created by Lisp packages are now stored in the .emacs.d directory too, so this keeps all your Emacs related files in one place.
All the files mentioned above should go in your HOME directory. The HOME directory is determined by following the steps below:
If the environment variable HOME is set, use the directory it indicates.
If the registry entry HKCU\SOFTWARE\GNU\Emacs\HOME is set, use the directory it indicates.
If the registry entry HKLM\SOFTWARE\GNU\Emacs\HOME is set, use the directory it indicates. Not recommended, as it results in users sharing the same HOME directory.
If C:\.emacs exists, then use C:/. This is for backward compatibility, as previous versions defaulted to C:/ if HOME was not set.
Use the user's AppData directory, usually a directory called Application Data under the user's profile directory, the location of which varies according to Windows version and whether the computer is part of a domain.
Within Emacs, ~ at the beginning of a file name is expanded to your HOME directory, so you can always find your .emacs file with C-x C-f ~/.emacs.
There's further information at HOME and Startup Directories on MS-Windows.
It should be stored in the variable user-init-file. Use C-H v user-init-file RET to check. You can also open it directly by using M-x eval-expression RET (find-file user-init-file) RET
Open the file like this in Emacs for Windows:
C-x C-f ~/.emacs
More information in the Emacs Wiki
On my Vista box it's in C:\Users\<USER>\AppData\Roaming\
Note that it may NOT be enough to just type Ctrl-x Ctrl-f ~/.emacs and create the file.
It may be that your Emacs application uses a different place to store your init file, and if so, then creating the file ~/.emacs simply creates a useless file which your Emacs application ignores.
Also, you may want to do more than just access the .emacs init file, but you may want to know where it is, i.e., its pathname.
To get at this there are two methods:
Easy way: type Ctrl + H V user-init-file Return
Slightly trickier way:
You can find out where your system is storing its own .emacs file by:
Click options and scroll down to "Set Default Font..."
Change the font setting and click okay
On the options menu, go down to "Save Options"
When the options are saved, the system saves its .emacs file,
and you can read the file path in the minibuffer at the bottom of the Emacs screen
In Windows 7 put your init.el file in C:\Users\user-name\AppData\Roaming\.emacs.d\, where user-name is your user/login folder.
Take care so your init.el file won't be named init.el.txt. This is something Windows does if you create your file with some editor like Notepad.
On versions of Emacs on Windows above 22, it seems to have moved to
~/.emacs.d/init.el
, ~ being the value of your environment variable HOME (see Control Panel → System → Advanced → Environment variables).
The file itself might not exist. In that case just create it.
You must create an emacs initialization file. One is not automatically created.
I had a similar issue and this answer tracks down what I did.
My issue was my ~/.emacs.el file was not loading. Strange because this has always worked for me.
This question/answer helped me but I had to put my init file in the %USERPROFILE%\AppData\Roaming\.emacs.d\init.el because this is apparently the default behavior on Windows.
To troubleshoot this, I ran the following in the emacs *scratch* buffer.
user-emacs-directory
"~/.emacs.d/"
When I saw user-emacs-directory was ~/.emacs.d, I simply moved my .emacs.el file to %USERPROFILE%\.emacs.d\init.el. But this still didn't work.
I continued with expand-file-name as shown below:
(expand-file-name user-emacs-directory)
"c:/Users/pats/AppData/Roaming/.emacs.d/"
Got to love how Windows works. (not) So I moved my emacs.el file to the %USERPROFILE%\AppData\Roaming\.emacs.d\init.el and this worked. The file was now being read. But I got other errors because my initialization file loaded other (personal emacs) files (in ~/myenv/emacs/*.el.
Warning (initialization): An error occurred while loading ‘c:/Users/pats/AppData/Roaming/.emacs.d/init.el’:
Hum... Seems like all my files ~/myenv/emacs/*.el would need to be moved in order for this to work but I didn't want to do that. Then I realized that because the HOME environment variable was not set, emacs was performing its default behavior.
SOLUTION
Once I set my windows HOME environment variable to %USERPROFILE% everything began to work like it has for the past 25 years. :-)
To set the HOME environment variable, I typed WindowsKey+"edit environment variables for your account" to open the Environment Variables dialog box, and entered HOME=%USERPROFILE%.
Now my emacs initialization file .emacs.el is is back to its rightful place $HOME/.emacs.el and not in %USERPROFILE%\AppData\Roaming\.emacs.d\init.el
To be fair, if Windows had just one place to put files for user installed packages the solution of making HOME=%USERPROFILE\AppData\Roaming might be acceptable, but because some applications use %USERPROFILE%, some use %USERPROFILE\AppData\Roaming and others use %USERPROFILE\AppData\Local it just makes it difficult to know where to find your configuration files.
I prefer having everything in my %USERPROFILE% or $HOME directory.
Another similar question was here:
Emacs init.el file doesn't load
As kanja answered, the path to this file is stored in the user-init-file variable (or if no init file exists, the variable contains the default value for where to create it).
So regardless of which of the possible init file names you are using, and which directory it is in, you should be able to visit your init file with:
M-: (find-file user-init-file) RET
Or display its full path in the echo area with:
M-: (expand-file-name user-init-file) RET
On Emacs 23 and Windows 7 it only works if you set:
HKCU\SOFTWARE\GNU\Emacs\HOME
After Emacs 27.1, emacs has started respecting the $XDG_CONFIG_HOME. The init file or the init directory can now be found in $XDG_CONFIG_HOME/emacs/init.el.
In Windows $XDG_CONFIG_HOME could translate to %LOCALAPPDATA%.
In any case you can use the following emacs variables to find out the location of the your initialization file by M-x eval-expression
user-init-file
or the emacs configuration directory
user-emacs-directory
I've found that Emacs 22 will occasionally open either "C:\Documents and Settings\username\Application Data\.emacs", or just "C:\Documents and Settings\username\.emacs" on my XP machine. I haven't found an explanation for why it occasionally changes it's mind.
~ will always point to whatever the current instance of emacs thinks is HOME, but kanja's tip (C-h v user-init-file) will always tell you what ~/.emacs actually maps to.
On Windows 8.1, if Emacs is started from Windows Explorer, a shortcut or from cmd console it uses C:\Users\<USER>\AppData\Roaming.emacs init file. When I start Emacs from PowerShell, Emacs looks for its init file in C:\Users\<USER> folder. The fix to this issue was to set the HOME user environment variable (Control Panel\System and Security\System->Advanced system settings->Advanced->Environment variables) to C:\Users\<USER>. After this change, no matter how I start Emacs, it uses the same init file (see the accepted answer of this question)
On Windows XP it's:
C:\Documents and Settings\yourusernamehere\Application Data\
There is a list of directories based on your Windows version and extra information:
http://www.gnu.org/software/emacs/manual/html_node/emacs/Windows-HOME.html
For WIndows7& Emacs26.3:
if HOME environment is set, then the .emacs file should be in that folder.
otherwise, it should be in c:\.
In both cases, if .emacs is not there, _emacs should be used.
This is because we cannot create .emacs file according to the windows file naming rules.(but we can download or copy it from somewhere else).

Resources