Vimã®ããã¹ããªãã¸ã§ã¯ããæ¬æ°åºãã¦çºãã¦ã¿ã
Vimã§ã¨ãã£ããããã«ããããããã«ã¯ã©ã¼ãã§å²ã¾ããé¨åãã·ã³ã°ã«ã¯ã©ã¼ãã«ãããã¨ããå²ã¾ããé¨åã®å å´ãç½®æãããã¨ããããå æ¸ããã¹ããªãã¸ã§ã¯ãã使ãããªããããªã¨æã£ãã®ã§èª¿ã¹ã¤ã¤æ¶ãã¦ã¿ãã
Vimã®ã³ãã³ãã¯ä½ããã®åèªã®é æåã§ããã±ã¼ã¹ãæ®ã©ãªã®ã§ãã³ãã³ãã®æå³ãçºãã¦ã¿ãã
ããããããã¹ããªãã¸ã§ã¯ãã¨ã¯
ãªãã¸ã§ã¯ãåä½ã§é¸æ *object-select* *text-objects*
*v_a* *v_i*次ã®ãã®ã¯ãã¸ã¥ã¢ã«ã¢ã¼ãããªãã¬ã¼ã¿ã³ãã³ãã®å¾ã§ã®ã¿ä½¿ããã¨ãã§ããä¸é£ã® ã³ãã³ãã示ãã¦ãã¾ãã
"a" ã§å§ã¾ãã³ãã³ã㯠"a" (1ã¤ã®) ã¾ã¨ã¾ãããã¯ã¤ãã¹ãã¼ã¹ãå«ãã¦é¸æãã¾ãã
"i" ã§å§ã¾ãã³ãã³ãã¯ã¾ã¨ã¾ãã® "inner" (å é¨) ããã¯ã¤ãã¹ãã¼ã¹ãå«ã¾ãã«é¸æãããããããã¯ãã¯ã¤ãã¹ãã¼ã¹ã®ã¿ãé¸æãã¾ãã
ã§ãã®ã§ã"inner" ã³ãã³ãã¯å¸¸ã« "a" ã³ãã³ãããå°ãªãããã¹ããé¸æãã ãã¨ã«ãªãã¾ãã
:help text-objects
ããã
端çã«è¨ãã¨ã å¾æ¥åèªã®å
é ã«ã«ã¼ã½ã«ããããã¦ãã cw
ã¨ãã¦ãæãã
å
é ã«ã«ã¼ã½ã«ãããããã¨ã caw
ã§ãåèªå
¨ä½ãç·¨éãããããã ci'
ã§ã'ã§å²ãããå
é¨ãç·¨éããå¯è½ã¨ãããã¤ã¹ãªãªãã¸ã§ã¯ãã®ãã¨ã§ããã
ãªãã¬ã¼ã¿ã³ãã³ãã®ãããã
ä¸å¿ãªãã¬ã¼ã¿ã³ãã³ãã®ããããã
ã³ãã³ã | æå³ | æä½ |
---|---|---|
c | c hange |
å¤æ´ |
d | d elete |
åé¤ |
y | y ank |
ã¤ã³ã¯ |
~ | 大æå/å°æåå ¥ãæ¿ã | |
g~ | 大æå/å°æåå ¥ãæ¿ã | |
gu | å°æåã«ãã | |
gU | go Uppercase | 大æåã«ãã |
ä»ã«ãzf
ã§æãç³ã¿ãä½æãããªã©ããããã©ããã¹ããªãã¸ã§ã¯ãã¨çµã¿åããããã«ã¯ãªããããªã®ã§å²æã
詳細㯠:help operator
ãåç
§ã§ã
ããã¹ããªãã¸ã§ã¯ãã®aã¨iã³ãã³ã
ã³ãã³ã | æå³ | 対象 |
---|---|---|
a | a n object |
ã¾ã¨ã¾ã(è¨å·ãå«ã) |
i | i nner |
ã¾ã¨ã¾ãã®å å´(è¨å·ãå«ã¾ãªã) |
a + <移åã³ãã³ã>
ã®ããã«æå®ãããaw
ãªã "a word", iw
ãªã "inner word"ã¨ãªãã
移åã³ãã³ãã®ä¿®é£¾èªã®ãããªæ±ãã«ãªãã
aã¨iã³ãã³ãã®å¾ã«å©ç¨å¯è½ãªç§»åã³ãã³ã
ã³ãã³ã | æå³ | 対象 |
---|---|---|
w | w ord |
ã«ã¼ã½ã«åå¾ã®åèª |
W | W ORD |
ã«ã¼ã½ã«åå¾ã®åèª(ãã¯ã¤ãã¹ãã¼ã¹å«ã) |
s | s entence |
ã«ã¼ã½ã«åå¾ã®æ |
p | p aragraph |
ã«ã¼ã½ã«åå¾ã®æ®µè½ |
[ ] | ã«ã¼ã½ã«åå¾ã®[]block | |
( ) ã¾ã㯠b | b lock |
ã«ã¼ã½ã«åå¾ã®()block |
< > | ã«ã¼ã½ã«åå¾ã®<>block | |
t | t ag |
ã«ã¼ã½ã«åå¾ã®tag block. ããã§ããã¿ã°ã¨ã¯htmlã®<div>...</div> ãªã© |
{ } ã¾ã㯠B | B lock |
ã«ã¼ã½ã«åå¾ã®{}block |
" ã ' ã ` | ã«ã¼ã½ã«åå¾ã® " ã ' ã ` ããããã®quote block |
移åã³ãã³ãåä½ã§ã¯ä½¿ãæ¹ãè¯ãåãããªãã¨æãã®ã§æ¬¡ã¸ã©ããã
ããã¹ããªãã¸ã§ã¯ãã®ä½¿ãæ¹
ä¸è¿°ã® ãªãã¬ã¼ã¿ã³ãã³ã + a/i + 移åã³ãã³ã
ã®çµã¿åããã§ä½¿ãã®ãä¸è¬çãªããã¹ããªãã¸ã§ã¯ãã®å©ç¨æ¹æ³ã§ããã
以ä¸ã«å®éã®ä½¿ãæ¹ã®ä¸ä¾ã
ã³ãã³ã | æå³ | 対象 |
---|---|---|
daw | delete a word | ã«ã¼ã½ã«åå¾ã®åèªãåé¤ãã |
da( | delete a block | ã«ã¼ã½ã«åå¾()ã«å²ã¾ããé¨åã()ãå«ãã¦åé¤ãã |
di( | delete inner block | ã«ã¼ã½ã«åå¾ã®()ã«å²ã¾ããé¨åãåé¤ãã |
ca( | change a block | ã«ã¼ã½ã«åå¾()ã«å²ã¾ããé¨åã()ãå«ãã¦å¤æ´ãã |
ci( | change inner block | ã«ã¼ã½ã«åå¾ã®()ã«å²ã¾ããé¨åãå¤æ´ãã |
das | delete a sentence | ã«ã¼ã½ã«åå¾ã®æãåé¤ãã |
dat | delete a tag block | ã«ã¼ã½ã«åå¾ã®ã¿ã°ãåé¤ãã |
æããã使ãã®ã¯ c
ã¨ã®çµã¿åããã ããã
ci'
ã®ã¯ã©ã¼ãã«å²ãããé¨åã®å¤æ´ãç§ã¯æ¢ã«è¯ãå©ç¨ãã¦ããã
s
ã®sentenceã¯ãã¼ãã«ã¢ã¼ãã§ã¯(
, )
ã§ç§»åããåä½ã®ãã®ã
å©ç¨ããã®ã§ããã°æ¥é ããVimã®æã®åä½ãç解ãã¦ããããã¨ããã
t
ããã£ã¡ã使ããããã¨æã£ããã©ãçµç«¯ã¿ã° </something>
ãããã¿ã°ãããªãã¨ãã¡ãªã®ã§ ci<
ãªã©ã¨ä½¿ãåããæ±ããããã
æ®æ®µããhjkl以å¤ã®ç§»åã«ãæ
£ãã¦ããã¨ãããã¹ããªãã¸ã§ã¯ããæå¹ã«å©ç¨ã§ããããªã®ã§ãããã使ã£ã¦æ
£ãã¦ããã¾ãããã
Surround.vim
æ¬å¼§ãã¯ã©ã¼ããã¿ã°ãªã©ã®ãæååãå²ããã®ãç°¡åã«æä½ããVim Pluginã
ããã¹ããªãã¸ã§ã¯ãã¨ã»ããã§èªããããã¨ãå¤ãã®ã§ãã¡ããçºãã¦åãä¸ããã
Surround.vim ã®ä½¿ãæ¹
<ãªãã¬ã¼ã¿ã³ãã³ã> + s + <対象ã®æ¬å¼§/ã¯ã©ã¼ã/ããã¹ããªãã¸ã§ã¯ã> + (<ç½®æ, æ¿å
¥ããæ¬å¼§/ã¯ã©ã¼ã>)
ã¨ããå½¢ã§å©ç¨ããã
è±èªã®SVOåã¨SVOOåã®ãããªå½¢ãæèã㦠README.markdown ã試ãã¨ç解ãé²ãã
ã¾ãã¯ããã«"ã§æ¬ãããããã¹ããç¨æãã
"Hello world!"
cs"'
ã¨typeããã¨ã"ã'ã«ç½®æãã
'Hello world!'
cs'<span>
ã¨typeããã¨ã'ãspanã¿ã°ã«ç½®æãã
<span>Hello world!</span>
cst"
ã¨typeããã¨ãspanã¿ã°ã"ã«ç½®æãã
"Hello world!"
ds"
ã¨typeããã¨ã"ãåé¤ãã
Hello world!
ysiw]
ã¨typeããã¨ãinner wordã[]ã§å²ã
[Hello] world!
cs]{
ã¨typeããã¨ã[]ã{}ã«ç½®æãã *1
{ Hello } world!
yssb
ããã㯠yss)
ã¨typeããã¨ãæã()ã§å²ã
({ Hello } world!)
ds{ds{
ã¨typeããã¨ãæ¬å¼§ãåé¤ãã
Hello world!
ysiw<em>
ã¨typeããã¨ãinner wordãemã¿ã°ã§å²ã
<em>Hello</em> world!
V
ã§è¡é¸æå¾ãS<span class='info'>
ã¨typeããã¨ãè¡ãspan.infoã¿ã°ã§å²ã
<span class='info'> <em>Hello</em> world! </span>
ããããæ £ããã¨æé«ãªãã¤ã ã
c
ã¯cs + <å¤æ´å¯¾è±¡ã®æ¬å¼§> + <å¤æ´å¾ã®æ¬å¼§>
ã§æ¬å¼§ã®å¤æ´d
ã¯ds + <åé¤å¯¾è±¡ã®æ¬å¼§>
ã§æ¬å¼§ã®åé¤y
ã¯ys + <æ¬å¼§ã§å²ã対象ã®ããã¹ããªãã¸ã§ã¯ã> + æ¬å¼§
ã§ããã¹ããªãã¸ã§ã¯ããæ¬å¼§ã§å²ã- ãã¸ã¥ã¢ã«ã¢ã¼ãã§ã®å¼ã³åºãã¯
S
- ä»ã®ãªãã¬ã¼ã¿ã³ãã³ã
~
ã¨ãã¯ä½¿ããªã*2
ãæ¶ããã°åºæ¬ã¯OK.
Surround.vim ã®ã«ã¹ã¿ãã¤ãº
let g:surround_<ASCII code> = "<% \r %">
ã¨.vimrcã«æ¸ã㨠yss<ASCII code>
ãªã©ã§ç½®æã§ããããã«ãªãã*3
ãã£ã¨è©³ããã«ã¹ã¿ãã¤ãºããããã° :help surround
ãèªãã°OK.
ã¾ã¨ã
ããã¹ããªãã¸ã§ã¯ãã§æ¬å¼§å
ã®æååç·¨éã
Surroud.vimã§æ¬å¼§ã®ç·¨éã楽ã«ã§ãããã!!
Vimãã¯ããã¯ãã¤ãã«ã?ä½æ¥å¹çãã«ã¤ã¼ã³ãã150ã®æ
- ä½è : Vimãµãã¼ã¿ã¼ãº
- åºç社/ã¡ã¼ã«ã¼: æè¡è©è«ç¤¾
- çºå£²æ¥: 2011/09/23
- ã¡ãã£ã¢: åè¡æ¬ï¼ã½ããã«ãã¼ï¼
- è³¼å ¥: 19人 ã¯ãªãã¯: 661å
- ãã®ååãå«ãããã° (37件) ãè¦ã