66 åºæ¬ã³ãã³ã ( :substitute ã¨ã :global ã¨ã )
人ã®ã¨ã³ããªã«ä¹±å ¥ãã¦ã¿ãã
http://d.hatena.ne.jp/akio0911/20080319/1205916091
人ã®ã¨ã³ããªã«åæã«è¿½è¨
% ã¯ãã¡ã¤ã«å ¨ä½ããã㯠1,$ ã¨åãã詳ããã¯ãã«ãåç §ã
:h cmdline-ranges :h :range
ã¨ããããã§ãä¸ã®äºã¤ã¯åããã³ãã³ãå®è¡æã®ç¯å²æå®ã®åºæ¬ã ããã
:%s/string/replace/g :1,$s/string/replace/g
ç¯å²æå®è¦ãã¤ãã§ã« :global ãªãã¦ã©ãã
ã¤ãã§ã«æ¸ãã¨ã㨠:substitue ããããã© :global ããªã¹ã¹ã¡ï¼
:h :global
å ¥åæåæ°ã¯å¤ããªããã©ãæ¡ä»¶ãæºããè¡ãã¹ã¦ã«ç¹å®ã®ã³ãã³ããå®è¡ãããããªãã¦å ´åã«åãçºæ®ãã¦ãããã:normal ã¨ã®çµã¿åããã§è²ã ã§ãããã使ãæ¹ã¯è©³ããã¯ãã«ãåç §ï¼
:g//s/string/replace/g
ãããã¡ã¨ããæ ãé£ã³è¶ãã¦ããããï¼(:windo, :bufdo)
:h :windo :h :bufdo
åã¦ã£ã³ãã¦ã»åãããã¡ã§ç¹å®ã®ã³ãã³ããå®è¡ããã³ãã³ãã«ã¯ :windo, :bufdo ããã*1ãã ããããã¹ã¦ã®ãããã¡ã§ç¹å®ã®æååãä¸æ¬ç½®æãããå ´åã¯ä»¥ä¸ã®ããã«ãªãã
:bufdo! %s/string/replace/g
ã³ãã³ãå®è¡å¾ã«:bufdoãæå¾ã«è¦ããããã¡ã«ç§»åãã¦ãã¾ããããã®å ´åã¯ããã¦ã :bnext ã¨ããã°ãæ»ããã¯ãã ãä¸è¨ã®ä¾ã§ã¯ãå¤æ´ã¯ä¿åãããªãããã¹ã¦ä¿åãã¦ããã®ãªã以ä¸ã®ããã«ããã
:bufdo %s/string/replace/g | w
ã³ãã³ãã®ãã¨ã« | ãã¤ãããã¨ã§é£ç¶ã§ã³ãã³ããå®è¡ããã:substitute ã®ãã¨ã« :write ãå®è¡ãã¦ãåãããã¡ãã¨ã«ä¿åãã¦ãã ãããããç°¡åï¼
æå¾ã«
å¿«é©ãª Vim ã©ã¤ããéã£ã¦ãã ããï¼
*1::tabdo ãªãã¦ã®ããã£ãã¨æããã§ãããããã¿ãã使ããªãã®ã§èå³ãªãã