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

后端 未结 2 2076
不知归路
不知归路 2020-12-28 21:26

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

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


        
相关标签:
2条回答
  • 2020-12-28 21:55

    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>
    
    0 讨论(0)
  • 2020-12-28 21:58

    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 讨论(0)
提交回复
热议问题