简体   繁体   中英

How can I make vim show spaces?

I'm currently trying to switch from gedit to vim. I try to make vim look similar to gedit:

编辑

Especially, I would like to show spaces with dots.

I currently have:

在此处输入图片说明

There are some differences, but it looks quite similar (this is my current .vimrc file ). But I don't get those dots for spaces.

How can I make vim show spaces?

I found some answers (like this one ) that seem to suggest to replace spaces by a special visible character and then replace it back. I don't want to do this every time. I want to be able to open vim and see those spaces.

I know it's an old topic, but it's possible with:

set lcs+=space:·

Works on my Gvim 7.4.

There are times when I absolutely need to see which whitespaces are tabs and which are true space characters, as well as when spaces appear at the end of a line.

When I'm using vim , I use:

:set list

(which I can turn off with :set nolist )

With :set list , literal spaces show up as spaces, tabs show up as ^I , and the end-of-line shows up as a bright-pink $ . (So any blank space you see to the left of the pink $ you'll know is a true space character, and the blank spaces to the right of it is just the "nothing" between the end-of-line and the right side of the editor.)

It's ugly, but it works well.

I don't recommend using it all the time -- just those times when it is crucial to see where literal spaces and literal tab characters exist.

While you can't do exactly what you want here, if your reasoning is like mine, you're wanting to see those spaces because it helps verify proper indentation (do I have 2 spaces there, or is it 3?). For Vim >= 7.3, you can use the indentLine plugin to add a marker at each indentation. It's awesome.

To install if you're using Pathogen :

cd ~/.vim/bundle
git clone https://github.com/Yggdroot/indentLine

在此处输入图片说明

It may be worth using undercurl to do the job.

hi WhiteSpaces gui=undercurl guifg=LightGray
match WhiteSpaces / \+/

or you can put this in your .vimrc

autocmd ColorScheme * highlight WhiteSpaces gui=undercurl guifg=LightGray | match WhiteSpaces / \+/ 

在此处输入图片说明

I came across this question, because I wouldd like to show leading spaces (indent spaces).
The above mentioned plugin indentLine is the solution for that Problem. If you use Vundle as plugin manager you can add Plugin 'Yggdroot/indentLine' to your .vimrc and then run vim +PluginInstall +qall to install the plugin.

Add the following two lines to your .vimrc to show leading spaces as · .

let g:indentLine_leadingSpaceChar='·'
let g:indentLine_leadingSpaceEnabled='1'

Edit: Space not Spac

TLDR: You can't.

Vim provides the 'listchars' option to show Tab vs. Space, and space characters in critical places, ie trailing at the end of lines. It does not offer a modification for all spaces: a blank square is a space, period.

If you're not happy with the workarounds posted in the referenced question, there's no way to achieve this other than modifying Vim's source code and compiling your own binary.

Using the answers of JL and Cedric Simon. Edit ~/.vimrc and add:

set lcs+=space:·
nmap <F2> :set invlist<CR>
imap <F2> <ESC>:set invlist<CR>a

and when you work with vim just pres F2

You don't need to install any plugin to this:

set listchars=tab:\|\ 
"set listchars=tab:\┊\ 
"set listchars=tab:\┆\ 
"set listchars=tab:\¦\ 
set list

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM