Vim autocmd on change line?
I am trying to run a function whenever a string changes, but there is no specific autocommand for that. I could run the function on CursorMoved, but that would slow down the editing. I could also display a function for all basic editing movements, but this can get very messy as I try to keep each line independent from the others. If there is no solution, I could do a diff every few seconds to see what has changed and run the function on the changed lines, but again this is a messy solution.
Any ideas?
source to share
If you can get Vim 7.4, look at events TextChanged
(and TextChangedI
for insert mode) . (Note that this will track changes across the entire buffer.)
source to share
You can do something like this with the BufWritePre event. Have a master file that defines your strings and tokens, and then in the sub files a link to their master, for example:
master-Foo.vim:
let b:Dom_slaves = ['/foo/bar/slave.cpp', '...', ...]
let b:Dom_map = {
\ 10 : "do your laundry",
\ 20 : "prepare your lunch"
\ }
slave.cpp
/* Dom_master = master-Foo.vim */
...
cout << "I will gladly /* Dom-id:10 */ and /* Dom-id:20 */.\n";
Dominate.vim
let MSMap = {}
autocmd BufWritePre * call s:Dominate()
function! s:Dominate()
" if current buffer Dom_slaves and Dom_map defined
" read & update all slaves with Dom_map mappings
" else see if 'Dom_master = somefile' appears in the buffer
" update mapped values from cache or read master file, cache and update
" endif
endfunction
By the way, this is a terrible thing to do with your vim .: P
source to share