Remove trailing spaces using vim
This little function will remove trailing space and maintain your position in a file. I started with something like this.
" Removes trailing spaces
function! TrimWhiteSpace()
%s/+$//e
endfunction
I found that it left me at the bottom of my file, and I kept forgetting to mark my position before running it. After a little research I found this solution, it saves your positon and returns it to you after it's done.
Thanks to stphancheg on stack overflow
" Removes trailing spaces
function! TrimWhiteSpace()
%s/+$//e
endfunction
I found that it left me at the bottom of my file, and I kept forgetting to mark my position before running it. After a little research I found this solution, it saves your positon and returns it to you after it's done.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Removes trailing spaces | |
function! TrimWhiteSpace() | |
let line = line('.') | |
let colum = col('.') %s/+$//e | |
call cursor(line,colum) | |
endfunction |
Thanks to stphancheg on stack overflow
Comments