<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>uprush &#187; 置換</title>
	<atom:link href="http://uprush.net/tag/%e7%bd%ae%e6%8f%9b/feed/" rel="self" type="application/rss+xml" />
	<link>http://uprush.net</link>
	<description>YiFeng's Blog</description>
	<lastBuildDate>Wed, 03 Feb 2010 14:34:38 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.3</generator>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Vimでシステム開発 &#8212; 検索と置換え</title>
		<link>http://uprush.net/2009/05/vim%e3%81%a7%e3%82%b7%e3%82%b9%e3%83%86%e3%83%a0%e9%96%8b%e7%99%ba-%e6%a4%9c%e7%b4%a2%e3%81%a8%e7%bd%ae%e6%8f%9b%e3%81%88/</link>
		<comments>http://uprush.net/2009/05/vim%e3%81%a7%e3%82%b7%e3%82%b9%e3%83%86%e3%83%a0%e9%96%8b%e7%99%ba-%e6%a4%9c%e7%b4%a2%e3%81%a8%e7%bd%ae%e6%8f%9b%e3%81%88/#comments</comments>
		<pubDate>Sun, 17 May 2009 13:31:22 +0000</pubDate>
		<dc:creator>uprush</dc:creator>
				<category><![CDATA[vim]]></category>
		<category><![CDATA[検索]]></category>
		<category><![CDATA[置換]]></category>

		<guid isPermaLink="false">http://blog.uprush.net/?p=257</guid>
		<description><![CDATA[Vimにての検索と置換え、複数ファイルに跨って検索（grep）と置換え、Vimtips（検索と置換え）

検索と置換え

基本な検索と置換えについて、Vim tutorにも詳しく書いてありますが、こちらではもう一度復習しましょう。
Normalモードで、「/」を入力して検索します。例えば「/foo」はfooを検索します。次へを検索は「n」をタイプします。逆方向へ検索は「N」をタイプします。
逆方向に検索するときは「/」の代わりに「?」コマンドを使います。例：?foo
カーソル下の単語を検索するには簡単な方法があります、「*」と「#」を使います。「*」は下へ、「#」は上へ検索します。
検索のヒストリから検索するには、「/」をタイプして、「&#8593;」と「&#8595;」キーで行います。
置換えは以下のように行います。



:s/old/new/g
行単位で見つかった「old」を「new」に置換えします。


:%s/old/new/g
ファイル全体で見つかった「old」を「new」に置換えします。


:%s/old/new/gc
ファイル全体で見つかった「old」を「new」に置換えします。一つ一つ確認を取りながら置換えします。



もちろん、Vimは正規表現を使っての検索と置換えが対応しています。この後も幾つか紹介しますが、正規表現をうまく使えば非常に便利になります。詳しくはヘルプを参照します。

:help&#160;03.9&#160;
:help&#160;pattern&#160;
:help&#160;usr_27.txt&#160;

:help 03.9 :help pattern :help usr_27.txt

&#160;

:help 03.9   :help pattern   :help usr_27.txt


検索に関する設定
以下は私のvimrcの検索に関する設定です、参考になればと思います。

set&#160;hlsearch&#160;&#160;&#160;&#160;&#34;検索文字をハイライト&#160;
set&#160;imsearch=0&#160;&#160;&#34;検索モードでのIMEのデフォルト状態&#160;
set&#160;nowrapscan&#160;&#160;&#160;&#160;&#34;検索でファイル終端に来たら先頭に戻らない&#160;
set&#160;ignorecase&#160;&#160;&#34;検索時大文字と小文字を区別しない&#160;
set&#160;incsearch&#160;&#160;&#160;&#34;増分検索&#160;
map&#160;&#60;F2&#62;&#160;:noh&#60;CR&#62;&#160;&#160;&#160;&#34;&#160;F2を押すと、Highlightを消す&#160;

set hlsearch    &#34;検索文字をハイライト set imsearch=0  &#34;検索モードでのIMEのデフォルト状態 set nowrapscan    &#34;検索でファイル終端に来たら先頭に戻らない set ignorecase  &#34;検索時大文字と小文字を区別しない set incsearch   &#34;増分検索 map &#60;F2&#62; :noh   &#34; F2を押すと、Highlightを消す

&#160;

複数ファイルに跨って検索（grep）と置換え

複数ファイルに跨って検索（grep）
複数ファイルに跨って検索（grep）は、「vimgrep」コマンドを使います。  &#160; 


:vimgrep&#160;/an&#160;error/g&#160;*.c&#160;&#124;&#160;copen&#160;

:vimgrep /an error/g *.c &#124; copen

&#160;
上記コマンドは、現在の作業フォルダにある全ての [...]]]></description>
		<wfw:commentRss>http://uprush.net/2009/05/vim%e3%81%a7%e3%82%b7%e3%82%b9%e3%83%86%e3%83%a0%e9%96%8b%e7%99%ba-%e6%a4%9c%e7%b4%a2%e3%81%a8%e7%bd%ae%e6%8f%9b%e3%81%88/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
