0

When I open an existing session with VIM the setting set nohlsearch at the very end of ~/.vimrc has no effect. It has effect only when I run it manually. I also noticed that if I open a file that isn't in the session the setting in ~/.vimrc has effect. The setting also works if I switch to a buffer in the session and run :source $MYVIMRC.

I recreated the session with :mksession! but it didn't help. I'm using VIM 7.4.

Below is the ~/.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
  • 1
    Would you mind posting your vimrc file? (or a link to it if it's very big)
    – Kusalananda
    Feb 8, 2018 at 7:28

1 Answer 1

1

It sounds like your windows have local settings already (setlocal hlsearch). Changing the global hlsearch won't affect those, and recreating the session will just store those settings once again.

Probably the easiest solution is to open your session file (as a text file, not load the session), and simply delete the lines that set hlsearch.

2
  • Removing 'set hlsearch' in the session file resolved it. But it is still unclear why the session still had this setting even after I set 'set nohlsearch' in vimrc and recreated the session file afterwards. P.S. I don't use vim on windows, but on Linux. Not sure how you came to this idea...
    – ka3ak
    Feb 8, 2018 at 15:51
  • LOL, I mean Vim "windows", not MS Windows. Each window (file view) within a Vim session can have it's own value for each setting.
    – ams
    Feb 8, 2018 at 16:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .