Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run command over multiple buffers/tabs to remove trailing spaces?

I have a command to tidy up excessive whitespace in my code in vim:

" to tidy excess whitespace
map <leader>1 :execute ':%s#\s\+$##g'<CR>

My question is, if I have 10 tabs or buffers open, how can I apply this command to all of them, rather than just going to each one and applying the command.

like image 798
steprobe Avatar asked Nov 23 '09 11:11

steprobe


1 Answers

See this vim tip on using bufdo, windo, and tabdo.

Assuming all your buffers are in the buffer list, your map could be as simple as

" to tidy excess whitespace
map <leader>1 :execute ':bufdo! %s#\s\+$##g'<CR>
like image 166
Greg Bacon Avatar answered Nov 15 '22 20:11

Greg Bacon