disable abbreviation in Vim - vim

Anyone know how to disable specific abbreviation such as :cabbr in Vim
I know how to clear them all with :cabclear
But I can not find any doc for clear specific :cabbr
Also after I disable all the abbre, is there any way I can recover all the abbre? or restore some specific abbreviations

The command you're looking for is :cunabbrev. Check the help files.
Also after I disable all the abbre, is there any way I can recover all the abbre? or restore some specific abbreviations
No, at least not in the same session since you don't really "disable" but rather remove the abbreviations. To bring them back you need to reload your vimrc and plugin files.
Ideally, you should remove the undesired abbreviation at its source instead of removing it after it was created. In case you're unsure where it's coming from, you can check that with :verbose:
:verb ab unwanted-abbrev

Related

how to reset Vim & TMUX dotfiles

Let say I have messed up my vim & tmux configuration. Is it possible to delete or reset them without losing any configuration changes such as PATH etc? If so, then how?
At this point? There probably is no way to get those files back. But, as a preventative measure in the future, keep config files like those in some sort of version-control system (like git or mercurial).
However, if this is too tedious or you don't want to for whatever reason, you can also add the following lines to your .vimrc:
set undofile
set undodir=~/.vim/undodir
Don't forget to mkdir ~/.vim/undodir.
This configuration enables persistent undo history in vim (I assume you're using vim to edit these files). With this feature, even after you close the file, and reopen it, you can still undo changes you made in the previous editing session. So if you'd had this set, your problem would be solved simply by hitting u until the files were in a good state. See :help undofile for more info.
Also, check out the great plugin vim-mundo. It provides a visual "undo tree" and makes browsing vim's complicated undo history very easy. Plus it's compatible with neovim.

Vim folder listing, can't reach :

In Vim's folder viewing mode I can't enter the : state for I get error:
Error detected while processing BufWinEnter Auto commands for "*"
E32: No file name
How do I fix that error?
Here's my vimrc.
Except I now have commented out the BufWin's.
I've stopped looking for this solution for now as I have managed to disable folder viewer.
For that see here.
You seem to have copied an autocmd into your configuration that is too simple and doesn't handle situations like unnamed buffers well.
If this is related to your other question, I'd suggest you have a look at http://vim.wikia.com/wiki/Make_views_automatic, where (in the comments section), multiple solutions to make the automatic view creation more robust are discussed.
Otherwise, go through the list of :autocmd BufWinEnter, try to find the culprit, and either fix it or remove that functionality.
You should be able to get out of this by doing:
:q
in the same way as you would quit from a file? Perhaps you need to add '!'

Manually enable undodir, when needed

I have enabled undodir, to keep track of changes I make even after I close my vim session.
I sometimes want to edit a file, make some changes, save it, then return to the original file of that session. (This might be one of the possible use cases)
If I had undodir disabled, I could simply keep hitting u until it showed me a message.
So I want undodir to be disabled in undo/redo by default, and I should have a command to enable it when needed.
All changes to the file must be tracked in either states, at all times.
Is this possible?
As far as I understand the documentation, only setting undodir does nothing unless undofile is set to true.
So, I assume that you want to activate undofile for certain files.
First thing that comes in mind is a modeline in order to set undofile to true for certain files. But unfortunately, this doesn't work.
The issue, however, is present on the vim developer mailing list and there was a fix provided in January: http://comments.gmane.org/gmane.editors.vim.devel/32896. This fix could be present in current sources; so if you'd like to try, grab the latest vim sources, build it and check if you could use a modeline for setting udf
Until there's an official version containing that fix, you could get around your issue using undofile.vim. Excerpt of it's description:
If you want 'undofile' only for certain files, you will notice that 'undofile' cannot be set in a modeline, or once the buffer is loaded (because an existing undo file will not be loaded then). Bram suggests to use a BufReadPre autocmd which sets 'undofile' before the buffer is loaded. This script does the steps for you.

VIM cpoptions+=n in an XML file

In my vimrc I set cpoptions+=n. Usually this option stays enabled, but as soon as I open an XML file it gets disabled. I've looked through the vim folder for things that modify cpo but can't see anything interesting (other than some saving and restoring of the options so that -=C can be used, but commenting those out changes nothing).
Any idea what's causing this or some pointers as to what to look for?
Open a XML file and run :verbose set cpoptions?. This will show you the current value of the setting and what file set that value. This setting is likely being overridden by the syntax file for xml (it is in my case).
Edit: Although this normally helps, it seems in this case there are many files loaded for the XML filetype that simply save cpo off, change it for their script, then restore the original value. It doesn't look like this is going to help you much.
You may have better luck opening up an XML file and running :scriptnames, then grepping through those scripts listed for cpo to see if you can find the culprit.
If you use GVIM, set it in your .gvimrc, because this is the last loaded configuration file. See :help initialization
other way, as #Randy Morris said, a plugin might set it to the default value. In my configuration, Tabularize set it last time in .vim/bundle/after/plugin/TabularMaps.vim.
EDIT: I found it !
In autoclose plugin, in plugin/autoclose.vim the saved cpoption is not writed back at the end. Simply add
" restore cpoptions
let &cpo = s:global_cpo
to the end of the file.
If you dont use the autoclose plugin, you can search for plugin files that reset the state of cpotions by :vimgrep "set cpo&vim" ~/.vim/**
then in the list you can search after the files that don't restore the original state (usually at the end of script a line starting with let &cpo = is missing).

Vim: Maintain the history of a file after it has been changed and reloaded

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.

Resources