vim ã® text-object ããã便å©ã«ä½¿ãããã©ã°ã¤ã³ - surround.vim
http://www.vim.org/scripts/script.php?script_id=1697
vim7 ãã追å ããã text-object ã¯å¤§å¤ä¾¿å©ã§ãä»ãææ¾ããªããªã£ã¦ãã¾ãããã® text-object ããã便å©ã«ä½¿ãããã©ã°ã¤ã³ãsurround.vim ã便å©ãããã®ã§ç´¹ä»ãã¾ãã
ãã¾ã¾ã§ãtext-object ã§ã¯ (以ä¸ã§ã¯ãã³ã¼ãã®ã*ãã®ä½ç½®ã«ç¾å¨ã«ã¼ã½ã«ãããã¨èãã¦ãã ããã)
foo 'b*ar' baz
ã®ä½ç½®ã«ã«ã¼ã½ã«ãããã¨ããi' ã§ã·ã³ã°ã«ã¯ãªã¼ãã¼ã·ã§ã³ã®ä¸èº«ãé¸æã§ããããa' ã§ã·ã³ã°ã«ã¯ãªã¼ãå«ãé¨åãé¸æã§ãã¾ããããããã'ããã®ãã®ãåé¤ããããç½®æãããã¯ã§ããªããã¡ãã£ã¨ä¸ä¾¿ã§ãããããããsurround.vim ã§ã¯
- ds
- cs
- ys
- vs
ããããã«ã³ãã³ããå²ãå½ã¦ã¦ãæ§ã ãªãã¨ãã§ããããã«ãªã£ã¦ã¾ãããã¨ãã°
foo 'b*ar' baz
ã§ã'ããåé¤ããããã°ãds' ã§ã§ãã¾ããã'ããã"ãã«ç½®æããããã°ãcs'" ã§ãã'ãã() ã«ç½®æããããã° cs') ã§ã§ãã¾ããruby 使ã£ã¦ãã¨æååãªãã©ã«ãã'ããã"ãã«å¤ããå¿
è¦ãçµæ§åºã¦ãããã§ããããã®æ©è½ã®ãããã§ç°¡åã«ã§ããããã«ãªãã¾ããã
ys ã使ãã¨ãæ§ã
ãªä½ç½®ããã'ããã()ããªã©ã§å²ããã¨ãã§ãã¾ãã
a = Array.new *foo, bar
ä¸è¨ã«ã¼ã½ã«ä½ç½®ã®æã«ãys$) ( ã$)ãã§è¡æ«ã¾ã§() ã§å²ãã¨å½ä»¤)ããã¨ã
a = Array.new *(foo, bar)
ã¨ãªã£ã¦ãå¾ããã§ãã()ããã'ãã§ããå²ããã¨ãã§ãã¦ããªã便å©ã§ããyss ã使ã£ãå ´åãè¡å ¨ä½ãã¿ã¼ã²ããã«ãªãããã
foo b*ar baz
㧠yss' ãæ¼ãã¨
'foo bar baz'
ã¨è¡ãã'ãã§å²ããã¾ãã
ã¾ã Visual Mode æã®é¸æç¯å²ã®å¤å´ãå²ããã¨ãã§ããããã
my $foo = $self->method; $foo->bar;
ãé¸æã㦠S{ ã§(大æåã® S ã ã¨ã¤ã³ãã³ããæå¹)
{ my $foo = $self->method; $foo->bar; }
ã¨ãªãã¾ãã
XML ã¿ã°ã®è¿½å ãåé¤
text-object ã«ã¯ t ã§ã¿ã°ã®é¸ææ©è½ãããã¾ããããã¯ããããã¿ã°ã®å
å´ã®ã¿é¸æããªã©ã®æ©è½ã§ããã
ããããsurround.vim ã使ãã¨ç¾å¨å²ã£ã¦ããã¿ã°ã®åé¤ãã§ãã¾ãã
<div><p class="comment"><strong>f*oo</strong> bar</p></div>
ã®æã«ãdst ãæ¼ãã¨
<div><p class="comment">*foo bar</p></div>
ã¨ãªãã¾ããããã§ããä¸åº¦ dst ãæ¼ãã¨
<div>*foo bar</div>
ã¨ãªãã¾ãããã¡ããå¤å´ã®ã¿ã°ã®ç½®æãã§ãã¦ããã㧠cst<p> ã¨æ¼ãã¨
<p>*foo bar</p>
ã¨ãªãã¾ããã¾ãã¿ã°ã®è¿½å ç°¡åã§ãv 㧠foo ãç¯å²é¸æãã¦ãst<strong> ã§
<p>*<strong>foo</strong> bar</p>
ã«ãªãã¾ãããys ãå©ç¨ãã¦ãysst<div class="foo"> ã¨æ¼ãã¨
<div class="foo"><p><strong>foo</strong> bar</p></div>
ã¨å²ã¨èªå¨ã«ã¿ã°ã§å²ããã¨ãã§ããããã«ãªãã¾ãã
insert-mode ã§ä½¿ã
insert-mode ã§ã <C-G>S ãæ¼ã㨠surround.vim ã使ããã¨ãã§ããããããã¨ãã° <C-G>S<html><C-G>S<head> ã¨å ¥åããã°
<html> <head> * </head> </html>
ã¨ãã¡ãã¨éãã¿ã°ãèªåã§å ¥åãããããã¦ããããæ¸ãå§ãããã¨ãã§ãã¾ãã
rhtml ã php ã®ã¿ã°ã®å ¥å
surround.vim ãæ¡å¼µãããã¨ã§ãç°¡åã« rhtml ã§ãã使ãã¿ã°ã php ã¿ã°ã®å ¥åãã§ããããã«ãªãã¾ããrails.vim ãå ¥ããã¨åæã« rhtml ç·¨éæã«æ¡å¼µãã¦ããã¦ããã¨ãã°
link_to '/', *'top'
ãªæã« yss= ã§
<%= link_to '/', 'top' %>
ã«ãªã£ãããinsert-mode ã§
<% * -%> <% end -%>
ã¨é常ã«ãã使ãã²ãªå½¢ãããå ¥åã§ããããã¦ä¾¿å©ã§ããphp ã®ã¿ã°ã®å ´åã~/.vimrc ã«
autocmd FileType php let b:surround_45 = "<?php \r ?>"
ã¨ãæ¸ãã¦ããã¨ãphp ã®ç·¨éæã«ããã¨ãã°
foo echo $bar baz
ã® echo $bar ãç¯å²é¸æã㦠s- ã§
foo <?php echo $bar;?> baz
ã¨ãããã¨ãã§ãã¾ãã
surround.vim ãæ¡å¼µãã (gettextç¯)
ããã§ã¯ãèªåããã使ãå
¥åããsurround.vim ã«ç»é²ãã¦ã¿ã¾ããããä¸ã® rhtml ã php ã®å
¥åãæ¡å¼µãã¦è¡ã£ã¦ã¾ãã
surround.vim ãæ¡å¼µããã«ã¯ãã°ãã¼ãã«å¤æ° g:surround_ã¢ã¹ãã¼ã³ã¼ã ã«ãã³ãã¬ã¼ããæ¸ãè¾¼ãã°OKã§ããvim ã§ã¢ã¹ãã¼ã³ã¼ãã調ã¹ãã«ã¯ã調ã¹ããæåã®ä¸ã«ã«ã¼ã½ã«ãããã㦠:ascii ã¨æ¼ãã¨èª¿ã¹ããã¾ãã
æè¿ gettext ã使ãæ©ä¼ãå¢ãã¦ãã¦ã 'foo' ã _('foo') ã«ã "foo" ã _("foo") ã«å¤æ´ããããã¨ãããããã®ã§ãæ©éãã®ãããªåä½ãããããã«æ¡å¼µãã¦ã¿ã¾ãããã
~/.vimrc ã«
let g:surround_103 = "_('\r')" " 103 = g let g:surround_71 = "_(\"\r\")" " 71 = G
ããã ãã§å®äºã§ããããã§ã
foo 'b*ar' baz
ã cs'g ã§
foo *_('bar') baz
ãªã©ã¨ç°¡åã« gettext 㪠syntax ã«ç½®ãæãããã¨ãã§ãã¾ããããã§ãã©ã°ã¼ã¨ gettext ã«ç½®æãããã¨ãã¯é¢åãªã®ã§å©ç¨ãã¦ãªã g", g' *1 ã nmap ã§å®ç¾©ãã¡ããã¾ãã
nmap g' cs'g nmap g" cs"G
ããã§ãg' ã g" ã§ç°¡åã«æååãªãã©ã«ã gettext ãªå½¢å¼ã«ç½®ãæãããã¨ãå¯è½ã«ãªãã¾ããã
çµããã«
surround.vim ã¯ä¹ ãã¶ãã« Life Changing 㪠plugin ã ã£ãã®ã§ãæ°ã«å ¥ã£ãã plugin ã® rate this script 㧠Life Changing ãæ¼ãã¨è¯ãã¨æãã¾ããã
*1:g' ã¯ããã©ã«ãã§å©ç¨ããã¦ããã使ã£ã¦ããªã