简体   繁体   中英

How do I get vim to highlight trailing whitespaces while using vim at the same time?

Following Vim highlighting with solarized color scheme , I tried this

" Default color scheme
syntax enable
 set background=dark
colorscheme solarized
autocmd ColorScheme * highlight RedundantSpaces ctermbg=red
match RedundantSpaces /\s\+$/

However I am still unable to get my whitespace to show up. Here's my .vimrc:

set nocompatible              " required
filetype off                  " required

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()

" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')

" let Vundle manage Vundle, required
Plugin 'gmarik/Vundle.vim'

Plugin 'tmhedberg/SimpylFold'
Plugin 'Vimjas/vim-python-pep8-indent'
Plugin 'vim-syntastic/syntastic'
Plugin 'nvie/vim-flake8'
Plugin 'jeffkreeftmeijer/vim-numbertoggle'
Plugin 'altercation/vim-colors-solarized'

" add all your plugins here (note older versions of Vundle
" used Bundle instead of Plugin)

" ...

" All of your Plugins must be added before the following line
call vundle#end()            " required
filetype plugin indent on    " required

"split navigations
nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>

" See docstrings for folded code
let g:SimpylFold_docstring_preview=1
" Enable folding
set foldmethod=indent
set foldlevel=99

" Enable folding with the spacebar
nnoremap <space> za

" UTF8 Support
set encoding=utf-8

" Syntastic recommended settings
set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*

let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0

" Default color scheme
syntax enable
set background=dark
colorscheme solarized
autocmd ColorScheme * highlight RedundantSpaces ctermbg=red
match RedundantSpaces /\s\+$/

" Make my code look pretty
let python_highlight_all=1
syntax on

" line numbering
set number relativenumber

Also, if possible, how do I use https://github.com/vim-scripts/ShowTrailingWhitespace with Solarize?

add this to the very bottom of your .vimrc

highlight RedundantSpaces ctermbg=red guibg=red 
match RedundantSpaces /\s\+$/

and you should be good to go, no need for ShowTrailingWhitespace plugin

There's no need to use a plugin just to trail whitespaces, i have this in my .vimrc:

autocmd BufWinEnter <buffer> match Error /\s\+$/
autocmd InsertEnter <buffer> match Error /\s\+\%#\@<!$/
autocmd InsertLeave <buffer> match Error /\s\+$/
autocmd BufWinLeave <buffer> call clearmatches()

It trails the whitespaces while you are editing the code, so i think that it will do what you want.

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