Getting rid of block characters at the end of a line in vim

enter image description here

Given my .vimrc, how do I get rid of those brownish characters at the end of the line in vim?

+3


source to share


3 answers


This can either be the result of a previous search $

(end of line), or an explicit display of end of line markers.

You can turn off highlighting of search results with :set nohlsearch

.



You can turn off the explicit end-of-line marker :set nolist

.

+5


source


If you really want to remove trailing spaces:



:%s/[[:space:]]\+$//

      

+3


source


I have a function in my file ~/.vimrc

that I am using to communicate with my save program

fun! CleanExtraSpaces()
        let save_cursor = getpos(".")
        let old_query = getreg('/')
        :%s/\s\+$//e
        call setpos('.', save_cursor)
        call setreg('/', old_query)
 endfun
 com! Cls :call CleanExtraSpaces()

 " auto clean trailing spaces
 if has("autocmd")
    autocmd BufWritePre *.txt,*.js,*.py,*.wiki,*.sh :call CleanExtraSpaces()
 endif

      

This code gets rid of all exta whitespace during save, or you can invoke it manually by typing :Cls<Enter>

the most important part is :%s/\s\+$//e

\s\+ .............. one space or mor
$ ................. at the end of the line
e ................. if not exists any extra space it ignores error messages

      

+1


source







All Articles