Tip #382: Search and replace in all open buffers
tip karma |
Rating 13/4, Viewed by 2122
|
created: |
|
December 4, 2002 16:56 |
|
complexity: |
|
basic |
author: |
|
Sean |
|
as of Vim: |
|
6.0 |
Useful for doing simple refactoring i.e. changing a method or variable name. Prompts for a word and then replaces all instances of <cword> in open buffers with the word.
"---------------------------------------------------------------------------
" Search for <cword> and replace with input() in all open buffers
"---------------------------------------------------------------------------
fun! Replace()
let s:word = input("Replace " . expand('<cword>') . " with:")
:exe 'bufdo! %s/' . expand('<cword>') . '/' . s:word . '/ge'
:unlet! s:word
endfun
map \r :call Replace()<CR>
Thanks to Jurgen Kraemer for showing me how to use the :exe command :)
Sean
<<Running the win32-version of Vim from cygwin |
a Map to jump to a subroutine/function from where it is called >>
Additional Notes
|