I got a new laptop.
And now when i save a file with vim, the file name replace by lowercase name. Any idea on how to solve this? FileName.vhd -> filename.vhd
I don't have this issue with notepad++
Best Regards,
Since I cannot make a comment, I will make an answer instead. This same problem has been solved here: Vim overwrites filename when writing
In short: put set backupcopy=yes in your vimrc, or type :set backupcopy=yes in Vim to only apply it in the current session. This will make saving files ever so slightly slower, but the filename won't be changed.
Related
While editing a file in vim and opening another file in a second split with netrw, the current working directory does not change and the path is same as the first file opened. Is there any way to fix this?
The following mapping in the .vimrc does change the path of the working file but it also sets the same path for the rest of the files opened in vim.
nnoremap <leader>cd :cd %:p:h<CR>:pwd<CR>
I also viewed questions based on this but couldn't find an appropriate solution.
A solution for this would be really helpful.
Maybe it's a language barrier issue, but you can't really expect Vim to change the path of a file when editing it.
What you want to change is probably the "working directory". If so, you can simply do it with :help 'autochdir':
:set autochdir
I am a new comer to the vim world, and I have just installed spf13-vim for a quick start. Apart from that I have not touched my .vimrc file.
I mainly use vim to write some python scripts on a remote server, so I have to type 'set ft=python' each time I open a file using vim. I am wondering if it's possible to edit my .vimrc file to make python a default choice of vim.
Another confusing thing is that each time I type a blank in vim, it shows a inverted question mark on my vim screen. I think it's because of some mismatch in file encoding, but I have no more idea about it.
I know it's a stupid question, but right now I can't solve it myself. Any help is appreciated.
Edit:
I have solved the problem of setting python default by write 'set ft=python' to my .vimrc file. (I didn't know contents in .vimrc are commands in vim) But I still don't know how to eliminate the inverted question mark when I typed a blank char, even after I do some search.
Name the buffer you're editing from the start, don't forget the :filetype plugin in your .vimrc and then things will work correctly.
In any way having :set ft=whatever in your .vimrc is twice wrong. First it'll apply to all new sessions opened without a file. Moreover it'll only apply to the first buffer. I.e. it won't work with :new.
I'm stuck up with a weird problem. I am trying to copy(yy) and paste(p) a line from one file to another (in split screen). It doesn't look it its working. However, yy, p works in the same file and with another file opened in another "tab". Would be really helpful if someone could tell me how to fix this. Spending a lot of time fixing this :(.
Thanks,
Omkar
This worked:
set clipboard=unnamed
You could also use a named buffer. If you yank with "ayy and put with "ap you can yank and put from any buffer to any other buffer in your vim session. You can use any other letter instead of a as the name of the buffer.
I accidentally deleted my .vimrc which took me weeks to config. I still keep the undofile and I think that's the only way I can restore it. Unfortunately, vim now does not allow me to undo (I guess because my current vimrc version cannot be "patched" with the last undo step).
Also, vim undo file is encoded so I cant see its content in human readable form. There was a step where I just deleted all my vimrc with ggvGc and so if there is a way to decode that vimundo file, I think I can restore it.
Is there anyway I can get my vimrc back? Thank you.
For people coming here years later, it's not possible in recent versions of Vim.
You could try running this to extract what you can from the undo file:
$ strings <undo-file>
See Recover a vim file from the .un~ file without the undo command for more information.
So, as FDinoff suggested, the patch here really works for me.
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.