瀏覽代碼

display trailing white space in vim and add alias to clear them

Weiyi Lou 13 年之前
父節點
當前提交
7421d3dd9b
共有 1 個文件被更改,包括 13 次插入3 次删除
  1. 13 3
      vim/vimrc

+ 13 - 3
vim/vimrc

@@ -49,14 +49,17 @@ if has("autocmd")
     autocmd WinEnter * setlocal cursorline
     autocmd WinEnter * setlocal cursorline
     autocmd WinLeave * setlocal nocursorline
     autocmd WinLeave * setlocal nocursorline
 
 
+    " Show trailing white space
+    autocmd InsertEnter * match ExtraWhitespace /\s\+\%#\@<!$/
+
     " Source the vimrc file after saving it
     " Source the vimrc file after saving it
     autocmd bufwritepost .vimrc source $MYVIMRC
     autocmd bufwritepost .vimrc source $MYVIMRC
 
 
     " A way to specify startup actions
     " A way to specify startup actions
     autocmd VimEnter * call StartUp()
     autocmd VimEnter * call StartUp()
- 
+
     " if the last window is NERDTree, then close Vim
     " if the last window is NERDTree, then close Vim
-    "autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif 
+    "autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
 else
 else
     set autoindent on
     set autoindent on
 endif
 endif
@@ -88,6 +91,7 @@ set wrap lbr        " wrap long lines of text
 set backspace=eol,start,indent "backspace over everything
 set backspace=eol,start,indent "backspace over everything
 set textwidth=80
 set textwidth=80
 set colorcolumn=+1  " mark out the limits of the textwidth
 set colorcolumn=+1  " mark out the limits of the textwidth
+set listchars=trail:_,tab:>.,eol:$
 
 
 
 
 """"""""
 """"""""
@@ -98,7 +102,10 @@ syntax enable
 colorscheme solarized
 colorscheme solarized
 set t_Co=16
 set t_Co=16
 set background=dark
 set background=dark
-hi Folded term=none cterm=none ctermfg=darkred ctermbg=none "set colour for folded lines
+" set colour for folded lines
+highlight Folded term=none cterm=none ctermfg=darkred ctermbg=none
+" show trailing white space
+highlight ExtraWhitespace ctermfg=red ctermbg=red guifg=red guibg=red
 
 
 
 
 """"""""
 """"""""
@@ -149,6 +156,9 @@ imap II <Esc>
 " Yank to end of line, like D
 " Yank to end of line, like D
 nmap Y y$
 nmap Y y$
 
 
+" Clear trailing white space
+nmap <silent> <leader>$    :%s/\s\+$//g<CR>
+
 " Add extra lines up and down
 " Add extra lines up and down
 nmap <leader>j    o<Esc>k
 nmap <leader>j    o<Esc>k
 nmap <leader>k    O<Esc>j
 nmap <leader>k    O<Esc>j