Vim "set noundofile" doesn't work, Vim still creates undo files - vim

Even though I I added "set noundofile" in the "_vimrc" file in the installation directory of Vim it still creates undo files.

You have no business editing anything in Vim's installation directory. Whatever you do to configure Vim must happen in your own runtime directory, located in your own "home directory", and nowhere else:
%USERPROFILE%\vimfiles
If it doesn't already exist, create it yourself.
Disabling undo files is indeed done with set noundofile, that you are supposed to put in your own vimrc, under the directory mentioned above:
%USERPROFILE%\vimfiles\vimrc
That file is sourced after any system-level vimrc so whatever you put in that file will take precedence. It is your vimrc.

Related

How to restore vim to default setting [duplicate]

I have mismatched plugin files floating around ~/.vim; I am experiencing a corrupted behavior within vim itself, and both my .vimrc and .gvimrc are filled with things I don't understand.
Examples: NERDTree plugin displays two identical file drawers on start, settings in .vimrc and .gvimrc aren't manifesting themselves.
Is there any way that I can completely "re-install" vim? Or, is there a way that I can get a new .vim folder, and start over form scratch? I want to learn vim, but it's hard with all these plugins installed. I just want to start with a plain vanilla installation.
Thanks for any help in advance.
cd
mv .vimrc .vimrc-old
mv .vim .vim-old
touch .vimrc
mkdir .vim
To remove everything from your vim configuration remove the entire .vim folder as well as everything from your .vimrc file. Keep the empty file in place though because without it vim will start in compatible mode by default and you almost certainly don't want that.
Note that there are system-wide files that are not stored in your home directory but if you haven't tweaked any of those then the above steps are all you need to do.
I know this is a bit old question but there is another useful command you can use mv ~/.viminfo ~/.oldviminfo
As mentioned in this answer, I moved .vim and .vimrc. which resulted in the error below
bash: /usr/bin/vim: No such file or directory
I'm not sure why I was facing the error above. When I moved only the .vimrc to .vimrc-bkp and created a new empty .vimrc, vim started working like a fresh install.

Vim won't save backup files into the correct directory

I have a vimrc file that has the following (along with a lot of other settings):
set backupdir=~/.vim-tmp
However, when I open a file foobar.txt using vim, change some text, save it and exit vim, a .footbar.txt~ file is left behind in the same directory as foobar. A few questions:
1) Shouldn't my setting in vimrc force this backup file to go into ~/.vim-tmp rather than the current directory?
2) Shouldn't the backup file be deleted when vim exits?
And just to verify, I searched for "backup" in my vimrc and only got the result at the top of the screen. Therefore, I don't think my setting is being overridden.
I figured my problem out on my own. What happened was my vimrc had set undofile however it did not have an undo directory; therefore, adding the following solved my issued:
set undodir=~/.vim/undodir

Why does the "*.txt~" file remain even after closing Vim? [duplicate]

I've found that while using Vim on Windows Vim saves the file, a .ext.swp file that's deleted on closing the Vim window and a .ext~ file.
I assume the .ext.swp file is a session backup in case Vim crashes. What's the purpose of the .ext~ file however? Is this a permanent backup file? It's annoying as I'd like to copy all the files I'm working on to my host, without these duplicates. How can I turn this off or, if it's there for a good reason, hide the files?
I think the better solution is to place these lines in your vimrc file
set backupdir=~/vimtmp//,.
set directory=~/vimtmp//,.
The first line is for backup files, the second line for swap files. The double slash at the end ensures that there is no conflict in case of two files having the same name, see comments (at the time of this edit this option is only honored for swap files, not yet for backup files). The ,. allow vim to use the current directory if the former doesn't exist.
You have to create a directory in your home directory called vimtmp for this to work. Also, check that backups are enabled in your config (add set backup if not).
That way you get the benefit of both worlds, you don't have to see the files, but if something does get futzed you can go get your backup file from vimtmp. Don't forget to clean the directory out every now and then.
The *.ext~ file is a backup file, containing the file as it was before you edited it.
The *.ext.swp file is the swap file, which serves as a lock file and contains the undo/redo history as well as any other internal info Vim needs. In case of a crash you can re-open your file and Vim will restore its previous state from the swap file (which I find helpful, so I don't switch it off).
To switch off automatic creation of backup files, use (in your vimrc):
set nobackup
set nowritebackup
Where nowritebackup changes the default "save" behavior of Vim, which is:
write buffer to new file
delete the original file
rename the new file
and makes Vim write the buffer to the original file (resulting in the risk of destroying it in case of an I/O error). But you prevent "jumping files" on the Windows desktop with it, which is the primary reason for me to have nowritebackup in place.
To turn off those files, just add these lines to .vimrc (vim configuration file on unix based OS):
set nobackup #no backup files
set nowritebackup #only in case you don't want a backup file while editing
set noswapfile #no swap files
:set nobackup
will turn off backups. You can also set a backupdir if you still want those backup files but in a central folder. This way your working dir is not littered with ~ files.
You find more information on backups under :he backup.
And you can also set a different backup extension and where to save those backup (I prefer ~/.vimbackups on linux). I used to use "versioned" backups, via:
au BufWritePre * let &bex = '-' . strftime("%Y%m%d-%H%M%S") . '.vimbackup'
This sets a dynamic backup extension (ORIGINALFILENAME-YYYYMMDD-HHMMSS.vimbackup).
Put this line into your vimrc:
set nobk nowb noswf noudf " nobackup nowritebackup noswapfile noundofile
In windows that would be the:
C:\Program Files (x86)\vim\_vimrc
file for system-wide vim configuration for all users.
Setting the last one noundofile is important in Windows to prevent the creation of *~ tilda files after editing.
I wish Vim had that line included by default. Nobody likes ugly directories.
Let the user choose if and how she wants to enable advanced backup/undo file features first.
This is the most annoying part of Vim.
The next step might be setting up:
set noeb vb t_vb= " errorbells visualbell
to disable beeping in vim as well :-)
You're correct that the .swp file is used by vim for locking and as a recovery file.
Try putting set nobackup in your vimrc if you don't want these files. See the Vim docs for various backup related options if you want the whole scoop, or want to have .bak files instead...
The only option that worked for me was to put this line in my ~/.vimrc file
set noundofile
The other options referring to backup files did not prevent the creation of the temp files ending in ~ (tilde)
I had to add set noundofile to ~_gvimrc
The "~" directory can be identified by changing the directory with the cd ~ command

What is the issue with vim -u /path_to/vimrc?

I share an user with other people.
Everyone has created a directory into home directory and everyone is working in his "own" directory.
I want to use my own setting when I use vim and I don't want to bother others with my preferences.
I created my .vimrc file into $HOME/my_directory
I've defined an alias my_vim="vim -u /full_path_to_home/my_directory/.vimrc"
When I edit a file with my_vim, I don't have the right colors.
I have the same problem when I use the command
:source /full_path_to_home/my_directory/.vimrc
If I copy my .vimrc file into $HOME directory, everything is fine.
Where is the problem ?
From :help vimrc
If Vim was started with "-u filename",
the file "filename" is used.
All following initializations until 4.
are skipped.
So by specifying a vimrc file, its ignoring the system-wide vimrc (/erc/vimrc/) where syntax highlighting and other things are configured. You can work around this problem by adding the following code to the top of your vimrc:
if filereadable("/etc/vimrc")
source /etc/vimrc
endif
If this sort of thing comes up a lot, I would recommend changing your $HOME to point to the current $HOME/my_directory whenever you log in.

GVIM on windows: way to disable the tmp file creation

I use gvim on windows and I want to know a way to disable the temp file(ending in ~) file creation. Also is there a problem if we do it?
You can disable the backup file by putting this line in your .vimrc:
set nobackup
I almost always do this, as the ~ file is more annoying that useful. There is no problem with doing this, you'll just lose the ability to revert to a backup of the file.
If you want to get rid of the temporary .swp (swap) file too, you can also set this:
set noswapfile
The swap file is created when you have a file open, and provides some backup/recovery security, in case Vim crashes while editing a file. It also can prevent multiple Vims from editing the same file. I usually just turn this off too, because I rarely have a use for it. The .swp file isn't as annoying as the ~ file, because it goes away when you close Vim, but I still just turn that feature off.
It's not quite what you asked for, but something that I've found works well is to redirect the swap and backup files to a seperate, dedicated folder. That way, they're still there if I need them, but they're not cluttering up the folder I'm working in.
The _vimrc file can be created in any of the following locations:
%HOMEPATH%\_vimrc
C:\Program Files (x86)\Vim\_vimrc
The following lines in the _vimrc file put backup files into a temporary directory:
set backup
set dir=%TMP%
set backupdir=%TMP%
set directory=%TMP%
set noundofile
The last line prevents the proliferation of undo files.
put these in your vimrc file
set nobackup
set nowritebackup
set noswapfile
From inside vim:
:e $HOME/_vimrc
and add this to the file:
set nobackup
Then, $HOME/_vimrc~ will hopefully be the last backup that vim makes!
You can also use the _vimrc from $VIM.
The _vimrc file from your home dir will be loaded later and the last setting wins.
Beware when using a common dir for backup, swap or undo files.
If you are on an USB or network drive and a drive letter gets reused you may run into problems.

Resources