Vim Tips Wiki
Advertisement

Previous TipNext Tip

Tip: #133 - Run a command in multiple buffers

Created: October 11, 2001 13:41 Complexity: basic Author: Salman Halim Version: 6.0 Karma: 9/8 Imported from: Tip#133

i like bufdo and windo but i don't like the fact that the commands end in a different window/buffer than from where i executed them. these versions (starts with a capital letter) will restore the current window or buffer when the command's done.

For example, to turn on line numbers everywhere, i use :Windo set nu -- :windo set nu does the trick also but leaves me in a different window than where i started.


" just like windo but restores the current window when it's done 
function! WinDo(command) 
 let currwin=winnr() 
 execute 'windo ' . a:command 
 execute currwin . 'wincmd w' 
endfunction 
com! -nargs=+ -complete=command Windo call WinDo(<q-args>) 

" just like bufdo but restores the current buffer when it's done 
function! BufDo(command) 
 let currBuff=bufnr("%") 
 execute 'bufdo ' . a:command 
 execute 'buffer ' . currBuff 
endfunction
com! -nargs=+ -complete=command Bufdo call BufDo(<q-args>)

References

Comments

tabdo suffers from the same thing. Can a similar fix be made?


Advertisement