Windo and Bufdo
From Vim Tips Wiki
Tip 133 • Previous Tip • Next Tip
Created: October 11, 2001 Complexity: basic Author: Salman Halim Minimum version: 6.0 Karma: 9/8 Imported from: Tip#133
The commands bufdo, windo and tabdo are great for operating on all buffers or windows or tabs. However, the commands finish in a different place from where you started.
These versions (Bufdo, Windo and Tabdo) restore the current window or buffer or tab, when the command is finished.
For example, to turn on line numbers everywhere, I use :Windo set nu. Using :windo set nu does the same, but the cursor finishes in a different window.
" Like windo but restore the current window. function! WinDo(command) let currwin=winnr() execute 'windo ' . a:command execute currwin . 'wincmd w' endfunction com! -nargs=+ -complete=command Windo call WinDo(<q-args>)
" Like bufdo but restore the current buffer.
function! BufDo(command)
let currBuff=bufnr("%")
execute 'bufdo ' . a:command
execute 'buffer ' . currBuff
endfunction
com! -nargs=+ -complete=command Bufdo call BufDo(<q-args>)
" Like tabdo but restore the current tab. function! TabDo(command) let currTab=tabpagenr() execute 'tabdo ' . a:command execute 'tabn ' . currTab endfunction com! -nargs=+ -complete=command Tabdo call TabDo(<q-args>)
[edit] References
[edit] Comments
Categories: Review | VimTip | Usage
