取消vi/vim下的黄色空格
set nohls取消搜索的高亮关键字。
hlsearch 是高亮选择搜索的关键字。
原来我此前搜索替换了空格,所以就把所有空格染色了。
而set nohls,则以后的搜索都不会高亮所有搜索的关键字。所以空格也不会有颜色了
当然这个方面只是一次性开关,下次打开时又会出现黄色空格。如果想以后打开所有的文件里的黄色空格都不要的话,就打开用户主目录下的.vimrc文件,(如果没有,就新建一个),在后面输入set nohls,保存。以后再打开所有的文件都不会有烦人的黄色空格了。
另外再附一个我的vimrc文件的配置:
1“””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””
2” => General
3“””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””
4” Sets how many lines of history VIM has to remember
5set history=700
6” Enable filetype plugin
7filetype plugin on
8filetype indent on
9” Set to auto read when a file is changed from the outside
10set autoread
11” With a map leader it’s possible to do extra key combinations
12” like <leader>w saves the current file
13let mapleader = “,”
14let g:mapleader = “,”
15” Fast saving
16nmap <leader>w :w!<cr>
17” Fast editing of the .vimrc
18map <leader>e :e! ~/.vim\_runtime/vimrc<cr>
19” When vimrc is edited, reload it
20autocmd! bufwritepost vimrc source ~/.vim\_runtime/vimrc
21“””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””
22” => VIM user interface
23“””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””
24” Set 7 lines to the curors – when moving vertical..
25set so=7
26set wildmenu “Turn on WiLd menu
27set ruler “Always show current position
28set cmdheight=2 “The commandbar height
29set hid “Change buffer – without saving
30” Set backspace config
31set backspace=eol,start,indent
32set whichwrap+=<,>,h,l
33set ignorecase “Ignore case when searching
34set smartcase
35set hlsearch “Highlight search things
36set incsearch “Make search act like search in modern browsers
37set nolazyredraw “Don’t redraw while executing macros
38set magic “Set magic on, for regular expressions
39set showmatch “Show matching bracets when text indicator is over them
40set mat=2 “How many tenths of a second to blink
41” No sound on errors
42set noerrorbells
43set novisualbell
44set t\_vb=
45set tm=500
46“””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””
47” => Colors and Fonts
48“””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””
49syntax enable “Enable syntax hl
50” Set font according to system
51if has(“gui\_running”)
52 set guioptions-=T
53 set t\_Co=256
54 set background=dark
55 colorscheme peaksea
56 set nonu
57else
58 colorscheme zellner
59 set background=dark
60 set nonu
61endif
62set encoding=utf8
63try
64 lang en\_US
65catch
66endtry
67set ffs=unix,dos,mac “Default file types
68“””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””
69” => Files, backups and undo
70“””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””
71” Turn backup off, since most stuff is in SVN, git anyway…
72set nobackup
73set nowb
74set noswapfile
75“Persistent undo
76try
77 if MySys() <span class="text-highlighted-inline" style="background-color: #fffd38;"> “windows”
78 set undodir=C:WindowsTemp
79 else
80 set undodir=~/.vim\_runtime/undodir
81 endif
82 set undofile
83catch
84endtry
85“””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””
86” => Text, tab and indent related
87“””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””
88set expandtab
89set shiftwidth=4
90set tabstop=4
91set smarttab
92set lbr
93set tw=500
94set ai “Auto indent
95set si “Smart indet
96set wrap “Wrap lines
97“”””””””””””””””””””””””””””””
98” => Visual mode related
99“”””””””””””””””””””””””””””””
100” Really useful!
101” In visual mode when you press \* or # to search for the current selection
102vnoremap <silent> \* :call VisualSearch(‘f’)<cr>
103vnoremap <silent> # :call VisualSearch(‘b’)<cr>
104” When you press gv you vimgrep after the selected text
105vnoremap <silent> gv :call VisualSearch(‘gv’)<cr>
106map <leader>g :vimgrep // \*\*/*.<left><left><left><left><left><left><left>
107function! CmdLine(str)
108 exe “menu Foo.Bar :” . a:str
109 emenu Foo.Bar
110 unmenu Foo
111endfunction
112” From an idea by Michael Naumann
113function! VisualSearch(direction) range
114 let l:saved\_reg = @”
115 execute “normal! vgvy”
116 let l:pattern = escape(@”, ‘/.</left></left></left></left></left></left></left>*$^~\[\]’)
117 let l:pattern = substitute(l:pattern, “n$”, “”, “”)
118 if a:direction </leader></cr></silent></cr></silent></cr></silent></span> ‘b’
119 execute “normal ?” . l:pattern . “^M”
120 elseif a:direction <span class="text-highlighted-inline" style="background-color: #fffd38;"> ‘gv’
121 call CmdLine(“vimgrep ” . ‘/’. l:pattern . ‘/’ . ‘ \*\*/*.’)
122 elseif a:direction <span class="text-highlighted-inline" style="background-color: #fffd38;"> ‘f’
123 execute “normal /” . l:pattern . “^M”
124 endif
125 let @/ = l:pattern
126 let @” = l:saved\_reg
127endfunction
128
129“””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””
130” => Command mode related
131“””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””
132” Smart mappings on the command line
133cno $h e ~/
134cno $d e ~/Desktop/
135cno $j e ./
136cno $c e <c->eCurrentFileDir(“e”)<cr>
137” $q is super useful when browsing on the command line
138cno $q <c->eDeleteTillSlash()<cr>
139” Bash like keys for the command line
140cnoremap <c-a> <home>
141cnoremap <c-e> <end>
142cnoremap <c-k> <c-u>
143cnoremap <c-p> <up>
144cnoremap <c-n> <down>
145” Useful on some European keyboards
146map ? $
147imap ? $
148vmap ? $
149cmap ? $
150func! Cwd()
151 let cwd = getcwd()
152 return “e ” . cwd
153endfunc
154func! DeleteTillSlash()
155 let g:cmd = getcmdline()
156 if MySys() </down></c-n></up></c-p></c-u></c-k></end></c-e></home></c-a></cr></c-></cr></c-></span> “linux” || MySys() <span class="text-highlighted-inline" style="background-color: #fffd38;"> “mac”
157 let g:cmd\_edited = substitute(g:cmd, “[(.](file://(.*/[//]//)</span>*\[/\]).*“, “[1](file://0.0.0.1/)“, “”)
158 else
159 let g:cmd\_edited = substitute(g:cmd, “[(.](file://(.*/[////]//)*\[\]).*“, “[1](file://0.0.0.1/)“, “”)
160 endif
161 if g:cmd <span class="text-highlighted-inline" style="background-color: #fffd38;"> g:cmd\_edited
162 if MySys() </span> “linux” || MySys() <span class="text-highlighted-inline" style="background-color: #fffd38;"> “mac”
163 let g:cmd\_edited = substitute(g:cmd, “[(.](file://(.*/[//]//).*/)</span>*\[/\]).*/“, “[1](file://0.0.0.1/)“, “”)
164 else
165 let g:cmd\_edited = substitute(g:cmd, “[(.](file://(.*/[/////]//).*/[/////)*\[\]).*\[\]”, “[1](file://0.0.0.1/)“, “”)
166 endif
167 endif
168 return g:cmd\_edited
169endfunc
170func! CurrentFileDir(cmd)
171 return a:cmd . ” ” . expand(“%:p:h”) . “/”
172endfunc
173“””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””
174” => Moving around, tabs and buffers
175“””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””
176” Map space to / (search) and c-space to ? (backgwards search)
177map <space> /
178map <c-space> ?
179map <silent> <leader><cr> :noh<cr>
180” Smart way to move btw. windows
181map <c-j> <c-w>j
182map <c-k> <c-w>k
183map <c-h> <c-w>h
184map <c-l> <c-w>l
185” Close the current buffer
186map <leader>bd :Bclose<cr>
187” Close all the buffers
188map <leader>ba :1,300 bd!<cr>
189” Use the arrows to something usefull
190map <right> :bn<cr>
191map <left> :bp<cr>
192” Tab configuration
193map <leader>tn :tabnew<cr>
194map <leader>te :tabedit
195map <leader>tc :tabclose<cr>
196map <leader>tm :tabmove
197” When pressing <leader>cd switch to the directory of the open buffer
198map <leader>cd :cd %:p:h<cr>
199command! Bclose call <sid>BufcloseCloseIt()
200function! <sid>BufcloseCloseIt()
201 let l:currentBufNum = bufnr(“%”)
202 let l:alternateBufNum = bufnr(“#”)
203 if buflisted(l:alternateBufNum)
204 buffer #
205 else
206 bnext
207 endif
208 if bufnr(“%”) <span class="text-highlighted-inline" style="background-color: #fffd38;"> l:currentBufNum
209 new
210 endif
211 if buflisted(l:currentBufNum)
212 execute(“bdelete! “.l:currentBufNum)
213 endif
214endfunction
215” Specify the behavior when switching between buffers
216try
217 set switchbuf=usetab
218 set stal=2
219catch
220endtry
221“”””””””””””””””””””””””””””””
222” => Statusline
223“”””””””””””””””””””””””””””””
224” Always hide the statusline
225set laststatus=2
226” Format the statusline
227set statusline= %{HasPaste()}%F%m%r%h %w CWD: %r%{CurDir()}%h Line: %l/%L:%c
228function! CurDir()
229 let curdir = substitute(getcwd(), ‘/Users/amir/’, “~/”, “g”)
230 return curdir
231endfunction
232function! HasPaste()
233 if &paste
234 return ‘PASTE MODE ‘
235 else
236 return ”
237 endif
238endfunction
239“””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””
240” => Parenthesis/bracket expanding
241“”””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””
242vnoremap $1 <esc>`>a)<esc>`<i(<esc>
243vnoremap $2 <esc>`>a]<esc>`<i\[<esc>
244vnoremap $3 <esc>`>a}<esc>`<i{<esc>
245vnoremap $$ <esc>`>a"<esc>`<i”<esc>
246vnoremap $q <esc>`>a'<esc>`<i’<esc>
247vnoremap $e <esc>`>a"<esc>`<i”<esc>
248” Map auto complete of (, “, ‘, \[
249inoremap $1 ()<esc>i
250inoremap $2 \[\]<esc>i
251inoremap $3 {}<esc>i
252inoremap $4 {<esc>o}<esc>O
253inoremap $q ”<esc>i
254inoremap $e “”<esc>i
255inoremap $t <><esc>i
256“””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””
257” => General Abbrevs
258“””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””
259iab xdate <c-r>=strftime(“%d/%m/%y %H:%M:%S”)<cr>
260“””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””
261” => Editing mappings
262“””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””
263“Remap VIM 0
264map 0 ^
265“Move a line of text using ALT+\[jk\] or Comamnd+\[jk\] on mac
266nmap <m-j> mz:m+<cr>`z<br></br>nmap <M-k> mz:m-2<cr>`z
267vmap <m-j> :m’>+<cr>`<my`>mzgv`yo`z
268vmap <m-k> :m'<-2<cr>`>my`<mzgv`yo`z
269“Delete trailing white space, useful for Python 😉
270func! DeleteTrailingWS()
271 exe “normal mz”
272 %s/s+$//ge
273 exe “normal `z”
274endfunc
275autocmd BufWrite \*.py :call DeleteTrailingWS()
276set guitablabel=%t
277“””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””
278” => Cope
279“””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””
280” Do :help cope if you are unsure what cope is. It’s super useful!
281map <leader>cc :botright cope<cr>
282map <leader>n :cn<cr>
283map <leader>p :cp<cr>
284“”””””””””””””””””””””””””””””
285” => bufExplorer plugin
286“”””””””””””””””””””””””””””””
287let g:bufExplorerDefaultHelp=0
288let g:bufExplorerShowRelativePath=1
289map <leader>o :BufExplorer<cr>
290“”””””””””””””””””””””””””””””
291” => Minibuffer plugin
292“”””””””””””””””””””””””””””””
293let g:miniBufExplModSelTarget = 1
294let g:miniBufExplorerMoreThanOne = 2
295let g:miniBufExplModSelTarget = 0
296let g:miniBufExplUseSingleClick = 1
297let g:miniBufExplMapWindowNavVim = 1
298let g:miniBufExplVSplit = 25
299let g:miniBufExplSplitBelow=1
300let g:bufExplorerSortBy = “name”
301autocmd BufRead,BufNew :call UMiniBufExplorer
302map <leader>u :TMiniBufExplorer<cr>
303“””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””
304” => Omni complete functions
305“””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””
306autocmd FileType css set omnifunc=csscomplete#CompleteCSS
307“””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””
308” => Spell checking
309“””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””
310“Pressing ,ss will toggle and untoggle spell checking
311map <leader>ss :setlocal spell!<cr>
312“Shortcuts using <leader>
313map <leader>sn \]s
314map <leader>sp \[s
315map <leader>sa zg
316map <leader>s? z=
317“”””””””””””””””””””””””””””””
318” => Python section
319“”””””””””””””””””””””””””””””
320let python\_highlight\_all = 1
321au FileType python syn keyword pythonDecorator True None False self
322au BufNewFile,BufRead \*.jinja set syntax=htmljinja
323au BufNewFile,BufRead \*.mako set ft=mako
324au FileType python inoremap <buffer> $r return
325au FileType python inoremap <buffer> $i import
326au FileType python inoremap <buffer> $p print
327au FileType python inoremap <buffer> $f #— PH ———————————————-<esc>FP2xi
328au FileType python map <buffer> <leader>1 /class
329au FileType python map <buffer> <leader>2 /def
330au FileType python map <buffer> <leader>C ?class
331au FileType python map <buffer> <leader>D ?def
332“”””””””””””””””””””””””””””””
333” => JavaScript section
334“””””””””””””””””””””””””””””””
335au FileType javascript call JavaScriptFold()
336au FileType javascript setl fen
337au FileType javascript setl nocindent
338au FileType javascript imap <c-t> AJS.log();<esc>hi
339au FileType javascript imap <c-a> alert();<esc>hi
340au FileType javascript inoremap <buffer> $r return
341au FileType javascript inoremap <buffer> $f //— PH ———————————————-<esc>FP2xi
342function! JavaScriptFold()
343 setl foldmethod=syntax
344 setl foldlevelstart=1
345 syn region foldBraces start=/{/ end=/}/ transparent fold keepend extend
346 function! FoldText()
347 return substitute(getline(v:foldstart), ‘{.</esc></buffer></buffer></esc></c-a></esc></c-t></leader></buffer></leader></buffer></leader></buffer></leader></buffer></esc></buffer></buffer></buffer></buffer></leader></leader></leader></leader></leader></cr></leader></cr></leader></cr></leader></cr></leader></cr></leader></cr></leader></cr></m-k></cr></m-j></cr></m-j></cr></c-r></esc></esc></esc></esc></esc></esc></esc></esc></esc></esc></esc></esc></esc></esc></esc></esc></esc></esc></esc></esc></span></sid></sid></cr></leader></leader></leader></cr></leader></leader></cr></leader></cr></left></cr></right></cr></leader></cr></leader></c-w></c-l></c-w></c-h></c-w></c-k></c-w></c-j></cr></cr></leader></silent></c-space></space>*‘, ‘{…}’, ”)
348 endfunction
349 setl foldtext=FoldText()
350endfunction
351“”””””””””””””””””””””””””””””
352” => MRU plugin
353“”””””””””””””””””””””””””””””
354let MRU\_Max\_Entries = 400
355map <leader>f :MRU<cr>
356“”””””””””””””””””””””””””””””
357” => Command-T
358“”””””””””””””””””””””””””””””
359let g:CommandTMaxHeight = 15
360set wildignore+=*.o,*.obj,.git,\*.pyc
361noremap <leader>j :CommandT<cr>
362noremap <leader>y :CommandTFlush<cr>
363“”””””””””””””””””””””””””””””
364” => Vim grep
365“”””””””””””””””””””””””””””””
366let Grep\_Skip\_Dirs = ‘RCS CVS SCCS .svn generated’
367set grepprg=/bin/grep -nH
368
369“””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””
370” => MISC
371“””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””
372” Remove the Windows ^M – when the encodings gets messed up
373noremap <leader>m mmHmt:%s/<c-v><cr>//ge<cr>‘tzt’m
374“Quickly open a buffer for scripbble
375map <leader>q :e ~/buffer<cr>
376au BufRead,BufNewFile ~/buffer iab <buffer> xh1 </buffer></cr></leader></cr></cr></c-v></leader></cr></leader></cr></leader></cr></leader></span><span class="text-highlighted-inline" style="background-color: #fffd38;"></span><span class="text-highlighted-inline" style="background-color: #fffd38;"></span><span class="text-highlighted-inline" style="background-color: #fffd38;"></span><span class="text-highlighted-inline" style="background-color: #fffd38;"></span><span class="text-highlighted-inline" style="background-color: #fffd38;"></span><span class="text-highlighted-inline" style="background-color: #fffd38;"></span><span class="text-highlighted-inline" style="background-color: #fffd38;"></span><span class="text-highlighted-inline" style="background-color: #fffd38;"></span><span class="text-highlighted-inline" style="background-color: #fffd38;"></span><span class="text-highlighted-inline" style="background-color: #fffd38;"></span>=
377map <leader>pp :setlocal paste!<cr>
378map <leader>bb :cd ..<cr>
379“很方便的gcc自动编译。只需要接下快捷键f5
380map <f5> :call CompileRunGcc()<cr>
381func! CompileRunGcc()
382exec “w”
383exec “!gcc % -o %<”
384exec “! ./%<”
385endfunc
386set nohls
关于vimrc的配置可以参看下以下几个链接:
http://nootn.com/blog/Tool/22/
http://hi.chinaunix.net/?uid-591145-action-viewspace-itemid-20900
http://linuxtoy.org/archives/vimrc.html
当然,更详细的还是去http://www.vim.org官网上去看吧!
捐赠本站(Donate)
如您感觉文章有用,可扫码捐赠本站!(If the article useful, you can scan the QR code to donate))
- Author: shisekong
- Link: https://blog.361way.com/vikongge/434.html
- License: This work is under a 知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议. Kindly fulfill the requirements of the aforementioned License when adapting or creating a derivative of this work.