Sometimes Vim creates a .swp file when I edit something, but not always. Why is that, and what causes Vim to create .swp files? Is it bad to disable them in .vimrc?
Vim creates .swp files for recovery. In case you fail to save, vim will be able to recover (at least some of) the file.
The merits of disabling them depends on what you do. If you use vim for anything that has a build, you probably save your sources all the time (how much time goes by between your coding stuff and compiling, building, and running a ut? Probably not hours). I hate the swps because they always require me to tell the version control system to ignore them.
Related
I like Vim's swap file system and I want to be prepared for the case I forget to :w, reusing this system.
I think it's possible if I can change when Vim deletes the swap file, but I could not find the way firstly to stop Vim from deleting it.
Do you know how to do it? or any alternative?
I'm using vim now for almost over a month and I am very dedicated to it. But since I added a few plugins, navigating through larger files (400+ lines... especially PHP files) makes vim pretty slow. It doesn't bother me much, because it is still pretty fast.
But I sometimes face the problem that navigating with hjkl hangs and even though I stopped pressing j for instance it keeps going for quite a while which is very annoying.
I run vim in iTerm on my mac and I'm not sure what to do here.
Thank you for any help.
//edit: Okay I found now what causes trouble. Everything that changes the current line style or messes with line numbers causes trouble.
So set cursorline or set rnu nu are causing my vim to lag. I think it is because the "redraw" is a pain for my terminal.
This is absolutely normal.
Some vim plugins are powerful, but not intended to be used handling large files (because it will require an enormous memory usage).
But the solution is simple: Use the LargeFile plugin which automatically detects when the file you are opening is too big and, in that case, disable some plugins and features just for that buffer.
I have weird issue with vim - for some files it doesn't color the syntax and opens it readonly mode by default, even if I use sudo. chmod for this file are 664, I am also owner of this file, so normally i shouldn't.
I have no set ro in my vimrc.
I noticed also that it often happens after removing .swp for this file - unfortunately, after this, this particular file is every time opened in readonly mode. One idea is - maybe is this some kind of spf13 cache?
For other files the behavior is correct.
Anyone knows this issue?
I found solution - it was more trivial than I expected.
I read the vim messages more carefully and I saw at the end:
if you did this already, delete the swap file `~/.vimswap/urls.py.swp`
So i did small investigation and i found .vimviews inside my /home directory. I just removed it's content and ...it works!
Probably spf13. There are WAY too many problems caused by spf13 in my opinion. Try doing :verbose set readonly? when you see the problem, to see where it happened from. My guess:
I think I remember spf13 having some kind of automatic session management built in, this would restore 'readonly' on a file if it had ever been set on that file.
It is quite possible (a fairly common solution) that if spf13 detects an existing swap file, it will automatically open the file in readonly mode, triggering (1).
It is also quite possible that some autocmd or another related to (2) sets an empty filetype or syntax, which would likewise be remembered by (1).
If this is the case, you can probably find the session file causing the issue (using that :verbose set readonly? command) and delete it.
Also consider, whether you really need all of spf13, or if you could achieve your desired configuration easier by installing plugins and configuring Vim yourself.
Whenever I quit a file, even using :q!, Vim will save it. What could possibly be causing this?
In init:
ack.vim
keybindings.vim
nerdcommenter.vim
nerdtree.vim
options.vim
supertab.vim
syntastic.vim
tabline.vim
vcomments.vim
vim-fugitive.vim
vim-powerline.vim
in plugin:
EasyMotion.vim
mru.vim
Often, a binary search where you disable half of your plugins, then only one half of that (when the problem is still there), or the other half (when the problem vanished) lets you get to the problematic script quickly. The same can be done with the configuration in your ~/.vimrc (by commenting out blocks).
Also, you can capture a full log of a Vim session with vim -V20vimlog. After quitting Vim, examine the vimlog log file for appropriate commands. In your case, that would be :write commands.
If I'm editing a file in Vim, then some external program changes the file, Vim tells me:
W11: Warning: File "test.erl" has changed since editing started
See ":help W11" for more info.
[O]K, (L)oad File:
If I Load the file, though, all the undo history is lost.
Is there any way to avoid that?
Update: it appears that this is one of the new features in Vim 7.3: https://groups.google.com/group/vim_announce/browse_thread/thread/66c02efd1523554b
I don't believe this is possible.
There is a very useful patch available for the vim source code available here that keeps the undo history after exiting vim and restarting. However, I've just tried it and it seems to fail when the file is edited externally. It might be worth contacting the author or reporting a bug on the patch website to see if this can be overcome.
G'day,
I'm not sure but does setting autoread, i.e. entering :set autoread leave the undo history for the file when it changes?
Hmmmm. I'm thinking probably not because the change history is maintained as line numbers and vim doesn't know if those line numbers are still relevant to the changed file.
BTW WTF are you editing a file that is being changed by external forces anyway? Sounds dangerous to me. (-:
This is a workaround I used before Vim 7.3:
" :e usually clears undo history, so we don't really do :e any more.
" Instead we delete the contents of the buffer, then read the file in, which
" is an operation we can undo. We must delete the top (empty) line also.
:map :e<Enter> :%d<Enter>:r<Enter>:0<Enter>dd
When you see the warning prompt, you would have to hit ok instead of load, and then perform the load yourself: :e<Enter>
There are two disadvantages (although I found the tradeoff acceptable):
You lose the line you were on. Your cursor is left sitting at the top of the file.
Vim still thinks the buffer is out of sync with the file, so when you next save, you may need to do :w! instead of the normal :w, and you will need to hit y to confirm the overwrite.
Edit: There might be a workaround for the second problem.
Edit: The first problem could be addressed with a bit more scripting (see :h line.)
I don't see how vim could keep track of something it didn't do.
So, as to the question, I would suggest - source control ... but that's probably not the answer you're looking for.