-1

i want to do some refactor in my web site using vim

i have html file index.html and css file style.css i want to rename some css classes

so when i change

<div class="XX"> </div>

to

<div class="yy"> </div>

the css file change automatically from

.xx{ color:red; }

to

.yy{ color:red; }

how i do that in vim ?

1 Answer 1

1

Vim is not an IDE and does not provide any refactor tools. However you can do a find and replace by using a substitution and combined with arglist or quickfix list to accomplish your goals. See the following vimcast for more: Project-wide find and replace. Here is an example project wide substitution using :Cdo referenced in the vimcast episode.

:vimgrep/ClassName/ **/*
:Cdo s/ClassName/SomethingElse/ge|w

You may also want to use something faster than :vimgrep. You can use the systems's grep via :grep or use a faster grepping tool like Ack or Ag Silver Search via 'grepprg'. If you are in a git repo then I suggest you use git grep or :Ggrep if you use fugitive.

You may also want to use the c flag for the substitution so you can confirm each substitution.

For more help see:

:h quickfix
:h arglist
:h :s
:h :s_flags
:h :vimgrep
:h :grep
:h 'grepprg'

Your Answer

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

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