/를 이용해서 찾았던 단어, :s나 :g를 이용해 바꿀때는 그냥 비우면 돼.
Ctrl-r Ctrl-w하면 현재 커서의 단어가 명령어라인으로 카피된다.
Press/
then Ctrl-r then Ctrl-w to copy the current word to the command line. You can now edit the search pattern and press Enter. Use Ctrl-r Ctrl-w for a <cword>, or Ctrl-r Ctrl-a for a <cWORD>.
After searching, an empty search pattern will repeat the last search. This works with /
, :s
and :g
.
So, after searching for a word, use :%s//new/g
to change all occurrences to 'new', or :g/
to list all lines containing the word. See substitute last search
:g/^baz/s/foo/bar/g
Change each 'foo' to 'bar' in each line starting with 'baz
:'a,'bs/foo/bar/g
Change each 'foo' to 'bar' for all lines from mark a to mark b inclusive.
Save typing by using \zs
and \ze
to set the start and end of a pattern. For example, instead of:
:s/Copyright 2007 All Rights Reserved/Copyright 2008 All Rights Reserved/
Use:
:s/Copyright \zs2007\ze All Rights Reserved/2008/