LoginSignup
2
2

More than 5 years have passed since last update.

incsearch.vim を使いたい

Last updated at Posted at 2015-07-06

incsearch.vim を使いたいと思っているけれど、標準のインクリメンタルサーチの場合にできていることを同様に実現する方法がわかっていないので移行できていない。

実現方法がわからないのは、下記のようなこと。

検索結果を置換用に流用

インクリメンタルサーチを実行中に <C-t> で検索文字列を置換用に流用している。

" https://raw.githubusercontent.com/cohama/.vim/master/.vimrc
" / と :s///g をトグルする {{{
cnoremap <expr> <C-t> ToggleSubstituteSearch(getcmdtype(), getcmdline())
function! ToggleSubstituteSearch(type, line)
  if a:type ==# '/' || a:type ==# '?'
    let range = GetOnetime('s:range', '%')
    return "\<End>\<C-U>\<BS>" . substitute(a:line, '^\(.*\)', ':' . range . 's/\1', '')
  elseif a:type ==# ':'
    let g:line = a:line
    let [s:range, expr] = matchlist(a:line, '^\(.*\)s\%[ubstitute]\/\(.*\)$')[1:2]
    if s:range ==# '''<,''>'
      call setpos('.', getpos('''<'))
    endif
    return "\<End>\<C-U>\<BS>" . '/' . expr
  endif
endfunction
function! GetOnetime(varname, defaultValue)
  if !exists(a:varname)
    return a:defaultValue
  endif

  let varValue = eval(a:varname)
  execute 'unlet ' . a:varname
  return varValue
endfunction
" }}}

クリップボードからの貼付け

/ 押下後にクリップボードから貼り付けてインクリメンタルサーチに使っている

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2