If you do not give range , the command with range will apply to the current line. If you want to do this on the entire buffer, use :%RT or :1,$RT
What you can do to make the entire default buffer:
command -range=% RT <line1>,<line2>call RemoveTrailingWhitespace()
detail:
:h command-range
then you will see:
Possible attributes are: -range Range allowed, default is current line -range=% Range allowed, default is whole file (1,$) -range=NA count (default N) which is specified in the line number position (like |:split|); allows for zero line number. -count=NA count (default N) which is specified either in the line number position, or as an initial argument (like |:Next|). Specifying -count (without a default) acts like -count=0
one comment / question to your function
If you have range information, why not just call vim-build in the command :[range]s to make a replacement? then you can save these lines getline , setline , also loop .
source share