2

This question is related to Do a forward slash search but don't have vim immediately jump to the string? but is not a dup.

I recently updated my Linux box (clicked on the "install updates" button in my Fedora distro' gui), and it has definitely changed Vim's behavior:

In Normal Mode, I used to perform the following keystroke sequence to replace all instances of the entire word under my cursor: :, %, s,/,\,<,Ctrl-r,Ctrl-w,\,>,/,replacement,/,g

Post-update, things have changed such that after the first / in that sequence, vim immediately moves the cursor and starts searching. This effectively kills my ability to use the Ctrl-r,Ctrl-w sequence to insert the word currently under the cursor.

Based on the answer to the noted question, I tried modifying my keystroke sequence to insert a : before the first / in that sequence, but that does not work: the Ctrl-r,Ctrl-w sequence inserts some other word (not the word under the cursor).

Is there a way to just disable this "search immediately if you type /" feature altogether? (I.e. instead of having to change your key-sequence as per the noted question) Or what can I do to restore things so that the old, noted, "replace everywhere" keystroke-sequence works again?

$ vim --version                                                                                 
VIM - Vi IMproved 8.1 (2018 May 18, compiled Oct 22 2019 12:17:41)
Included patches: 1-2198                                                                       
Modified by <[email protected]>                                                              
Compiled by <[email protected]>
...
$
$ cat ~/.vimrc
execute pathogen#infect()

set backspace=indent,eol,start
set shiftwidth=2
set softtabstop=2
set expandtab
set smarttab
set cino+=(0
set statusline=
set statusline +=\[%n]    " buffer number
set statusline +=\%F      " File
set statusline +=%=%l/%L  " currentLine/totalLine
set statusline +=%4v      " virtual column
set laststatus=2
set number
set ruler                 " show the cursor position all the time
set scrolloff=7           " start scrolling when cursor is 7 lines from top/bottom
set t_Co=256
set textwidth=80
set formatoptions=croqlt  " Hard-wrap when typing exceeds <textwidth>
set hlsearch
syntax on
filetype plugin indent on
autocmd FileType make set noexpandtab shiftwidth=4 softtabstop=0
colorscheme Base2Tone_MorningDark

" highlights
hi Search ctermfg=black ctermbg=yellow
hi LineNr ctermfg=yellow ctermbg=NONE
hi Normal ctermfg=NONE ctermbg=NONE

" syntastic stuff
let g:syntastic_check_on_open = 1
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_check_on_wq = 1
let g:syntastic_c_checkers = ['cppcheck']
let g:syntastic_cpp_checkers = ['cppcheck']
let g:syntastic_python_checkers = ['flake8']
let g:syntastic_javascript_checkers = ['eslint']

I don't really know what version of vim I had before the upgrade, and I'd have no idea how to go about unearthing that information now.

1 Answer 1

3

This is due to an upgrade to 'incsearch'. Turning it off should do the trick.

P.S.: you could map the key stroke instead:

nnoremap <leader>cw :%s/<cword>/

But I prefer

nnoremap <leader>cw :let @/=expand('<cword>')<CR>cgn

which sets the search pattern, but doesn't highlight, and then uses the .-repeatable cgn command.

1
  • 1
    TIL: "incsearch". So bonus thank you for educating me on the term for this feature.
    – StoneThrow
    Dec 8, 2019 at 2:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.