当我使用 VIM 打开现有会话时,set nohlsearch
最后的设置~/.vimrc
不起作用。只有当我手动运行时它才有效。我还注意到,如果我打开一个不在会话中的文件,则设置~/.vimrc
会生效。如果我切换到会话中的缓冲区并运行,该设置也有效:source $MYVIMRC
。
我重新创建了会话,:mksession!
但没有帮助。我正在使用 VIM 7.4。
下面是~/.vimrc
:
" For pre-processing books
command! Book %s/\v([Tt])heyre/\1hey're/gec | %s/\v([Ww])ont/\1on't/gec | %s/\v([Yy])oud/\1ou'd/gec | %s/\v([Nn])eednt/\1eedn't/gec | %s/\v([Ss])houldnt/\1houldn't/gec | %s/\v([Hh])asnt/\1asn't/gec | %s/\v([Cc])ant/\1an't/gec | %s/\v([Tt])hats/\1hat's/gec | %s/\v([Yy])oull/\1ou'll/gec | %s/\v([Yy])oure/\1ou're/gec | %s/\v([Yy])ouve/\1ou've/gec | %s/\v([Ii])ts/\1t's/gec | %s/\v([Dd])ont/\1on't/gec | %s/\v([Aa])rent/\1ren't/gec | %s/\v([Dd])oesnt/\1oesn't/gec | %s/\v([Dd])idnt/\1idn't/gec | %s/\v([Ii])snt/\1sn't/gec | %s/\v([Hh])eres/\1ere's/gec | %s/IDEs\C/IDE's/gec | %s/\v([Nn])onfinal/\1on-final/gec | /\v\c^(chapter|item)|\[.+\]
" Write buffer and delete it afterwards
command! Wd write|bdelete
" Format current buffer that should be an XML document
"command! FormatXml %!xmllint --format -
" Format current selection that should be an XML document
command! -range FormatXml <line1>,<line2>!xmllint --format -
" Copy current buffer contents to the system clipboard (insertion with CTRL+v). Range can be used.
command! -range CopyToClipboard <line1>,<line2>w !xclip -selection clipboard
" Copy current buffer contents to the primary clipboard (insertion with mouse wheel click or with CTRL+SHIFT+INSERT). Range can be used.
command! -range CopyToPrimary <line1>,<line2>w !xclip
" Copy visual selection to the clipboard and pass it to 'eval'
command! -range Eval <line1>,<line2>w !xclip && eval "$(xclip -o)"
" Comment/uncomment shell script
command! -range CommentShellScript <line1>,<line2>s/^/#/g
command! -range UncommentShellScript <line1>,<line2>s/\v^\s*#(.*)/\1/g
" Creates a buffer containing the output of ':browse oldfiles' command at the top
" Move cursor to the path and press ENTER
" TODO: Doesn't open files with spaces in their paths
command! Browse new +setl\ buftype=nofile | 0put =v:oldfiles | nnoremap <buffer> <CR> :e <C-r>=getline('.')<CR><CR>
" If the current line contains a file path, the file will be opened in default program
command! OpenInDefaultProgram exec(":!xdg-open '".getline(".")."'")
" If the current line contains a URL, the URL will be opened in firefox
command! OpenUrlInFirefox exec(":!firefox '".getline(".")."'")
" Remove duplicate method calls. You just want to see which methods have been called and not interested in their call order
command! BtraceUniqMethodCalls %s/\v\(.*\)//g | %sort u | !%uniq
" Remove duplicate classes. You just want to see which classes have been used during execution
command! BtraceUniqClasses %s/\v\.[^\.]{-}\(.*\)//ge | execute 'g/\v\$[0-9]+$/de' | %sort u | %!uniq
" Remove duplicate adjacent method calls. Methods call order is kept.
"command! BtraceRemoveAdjacentDuplicateMethods %s/\v\(.*\)//ge | %!uniq (no
"line numbers)
command! BtraceRemoveAdjacentDuplicateMethods %!awk 'BEGIN {method=""} match($0,/.*\(/) { if (length(method)) { if (index($0,method) == 0) { print $0 } } else { print $0 } method =substr($0, RSTART, RLENGTH-1) }'
set ignorecase
set smartcase
set hidden
set tabstop=2 "2 spaces will be inserted when pressing TAB in INSERT mode
"set softtabstop=0 noexpandtab
set shiftwidth=2 "2 spaces will be inserted when indenting
"set wildmode=longest,list
set history=200
"highlight normal ctermfg=white ctermbg=yellow
set nocompatible
filetype plugin on
filetype indent on
" 'matchit' plugin
"set nocompatible
"filetype plugin on
runtime macros/matchit.vim
" Disable arrow keys in NORMAL mode
noremap <Up> <Nop>
noremap <Down> <Nop>
noremap <Left> <Nop>
noremap <Right> <Nop>
:map <F8> <C-E>:sleep 3500m<CR>j<F8>
function! GotoJump()
jumps
let j = input("Please select your jump: ")
if j != ''
let pattern = '\v\c^\+'
if j =~ pattern
let j = substitute(j, pattern, '', 'g')
execute "normal " . j . "\<c-i>"
else
execute "normal " . j . "\<c-o>"
endif
endif
endfunction
"if $TERM_PROGRAM =~ "iTerm" works also for KDE "Konsole"
" let &t_SI = "\<Esc>]50;CursorShape=1\x7" " Vertical bar in insert mode
" let &t_EI = "\<Esc>]50;CursorShape=1\x7" " Vertical bar in normal mode
" let &t_SI = "\<Esc>]50;CursorShape=0\x7" " Block in insert mode
" let &t_EI = "\<Esc>]50;CursorShape=0\x7" " Block in normal mode
"endif
set nohlsearch
答案1
听起来您的 Windows 已经有本地设置 ( setlocal hlsearch
)。更改全局hlsearch
不会影响这些,重新创建会话只会再次存储这些设置。
也许最简单的解决方案是打开会话文件(作为文本文件,而不加载会话),然后简单地删除设置 hlsearch 的行。