On Thu, Sep 24, 2009 at 6:25 AM, Roald de Vries <[email protected]> wrote: > > On Sep 24, 2009, at 12:25 PM, Andy Wokula wrote: >> Roald de Vries schrieb: >>> Hi all, >>> >>> Is it possible to undo an abbreviation expansion? I have a latex >>> mapping 'ia --> \rightarrow', but somtimes don't want it to expand. >>> How can I do that? >>> >>> Roald >> >> Press <C-V> just before entering the next character (here <Space>): >> --><C-V> more text ... >> >> For undoing, you can experiment, e.g. >> >> :ia --> --><C-G>u<BS><BS><BS>\rightarrow >> >> <Esc>u will then bring back the arrow "-->". >> Just invented right now, not common use AFAIK. > > Thanks Andy, the <C-V> trick is very useful. The second abbreviation > too, but I don't want to enter all my abbreviations like this. I would > prefer use an autocommand like > au AbbrExpandPre * <C-G>u > ... but I guess that's impossible since there is no event > AbbrExpandPre, and the command should be an ex command, which shows > the problem: AbbrExpandPre couldn't be an autocommand because insert > mode is never left. > > Doe anybody have a good (even better) solution to my problem? > > Thanks in advance, Roald >
Use a function to expand the abbreviation such that you can save the word and be able to undo. This is what I have done for the sql_iabbr plugin (http://www.vim.org/scripts/script.php?script_id=305). Here is an extract from it (untested): function! ExpandAbbr(original, replacement) let g:UndoBuffer = a:original return word endfunction inoremap <silent> <buffer> <C-G>u <C-W><C-R>=g:UndoBuffer<CR><C-V><Space> To create new abbreviations, you would do something likes this: inoreabbr <silent> abbr <C-R>=ExpandAbbr(abbr', 'abbreviation')<CR> There is a lot of scope for improvement in undo, e.g., you can save the last expansion location and be able to undo even after cursor moves away, but most often you would realize the need for undo almost immediately, so it should sever well enough. -- HTH, Hari > > > --~--~---------~--~----~------------~-------~--~----~ You received this message from the "vim_use" maillist. For more information, visit http://www.vim.org/maillist.php -~----------~----~----~----~------~----~------~--~---
