Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Showing trailing spaces in vim

I've set the following options in .vimrc

set listchars=tab:▸\ ,trail:· set list 

And expected to see dots in those places where spaces are used for tabulation in the code (I use spaces, not tabs). However, the result is different:

enter image description here

Could you please recommend how to reach the desired result? Thanks!

like image 282
lyuba Avatar asked Jan 06 '11 16:01

lyuba


People also ask

How do I show tabs and spaces in Vim?

If you don't want to show all the whitespaces of the text on the Vim editor of your system, you need to turn the “hls” command off. For that purpose, go to the normal mode first. Press the “;” character, and you will be in the command mode.

How do I check space in Vim?

Upgrading my gvim solved my problem. For others that are getting an error, type :help listchars to check whether "space" is a valid option for "listchars". If it is not, upgrade your vim to the patch @brettanomyces specified. Or just leave "space" out of the set command if you don't care to see spaces.

How do I get rid of whitespace trailing?

Type M-x delete-trailing-whitespace to delete all trailing whitespace. This command deletes all extra spaces at the end of each line in the buffer, and all empty lines at the end of the buffer; to ignore the latter, change the variable delete-trailing-lines to nil .


Video Answer


2 Answers

You should check this link. I'm using the match command solution :

:highlight ExtraWhitespace ctermbg=red guibg=red :match ExtraWhitespace /\s\+$/ 

This page also provides list based solutions which I haven't personally tried.

like image 71
icecrime Avatar answered Sep 21 '22 05:09

icecrime


The vim-better-whitespace plugin incorporates many tips from the Vim Wiki page referenced in @icecrime's answer. It also has some nifty configuration options.

I installed pathogen.vim just to use this plugin and am happy with my life, all things considered.

like image 35
jtpereyda Avatar answered Sep 20 '22 05:09

jtpereyda