开发者

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 开发者_Python百科them, rather than just going to each one and applying the command.


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>


Not tested, but this should do it:

:tabdo %s/SEARCH/REPLACE/ge | update

This replaces SEARCH in all tabs with REPLACE and writes the file if it is modified by the command without showing an error message if nothing is found.

If you want to be asked before each replacement, add 'c' to the flags.

See also :help :argdo, :help :windo, and :help :bufdo.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜