2011-09-01 8 views
6

मैं vim में है:सामान्य मोड में vim में "vaw" का अर्थ क्या है (और "caw" और "daw")?

foo barba[r]bar 
foo 

[] को इंगित करता है कर्सर स्थिति

और जब मैं VAW का उपयोग करें या viw barbarbar higlithted है। और यह ठीक है।

लेकिन मुझे समझना है - क्यों? v दृश्य मोड के लिए है, ए - मैं नहीं जानता कि क्यों, और नए शब्द की शुरुआत के लिए मानक दृष्टिकोण।

मैंने भी कैव और सीवी की जांच की। सबसे पहले बारबारबार हटा देता है और अंतरिक्ष के बिना foo के बाद कर्सर छोड़ देता है, दूसरा foo के बाद स्थान छोड़ देगा, दोनों डालने मोड में प्रवेश करेगा ...

तो यह क्यों काम करता है? विम सहायता में इसके लिए कोई संदर्भ है? क्या कोई इसे विम भाषा के लिए अनुवाद कर सकता है?

उत्तर

22

:help text-object देखें। यह किसी भी लड़के की तुलना में यह सब बेहतर बता सकता है।

6. Text object selection   *object-select* *text-objects* 
         *v_a* *v_i* 

This is a series of commands that can only be used while in Visual mode or 
after an operator. The commands that start with "a" select "a"n object 
including white space, the commands starting with "i" select an "inner" object 
without white space, or just the white space. Thus the "inner" commands 
always select less text than the "a" commands. 

These commands are {not in Vi}. 
These commands are not available when the |+textobjects| feature has been 
disabled at compile time. 
          *v_aw* *aw* 
aw   "a word", select [count] words (see |word|). 
      Leading or trailing white space is included, but not 
      counted. 
      When used in Visual linewise mode "aw" switches to 
      Visual characterwise mode. 

          *v_iw* *iw* 
iw   "inner word", select [count] words (see |word|). 
      White space between words is counted too. 
      When used in Visual linewise mode "iw" switches to 
      Visual characterwise mode. 

          *v_aW* *aW* 
aW   "a WORD", select [count] WORDs (see |WORD|). 
      Leading or trailing white space is included, but not 
      counted. 
      When used in Visual linewise mode "aW" switches to 
      Visual characterwise mode. 

          *v_iW* *iW* 
iW   "inner WORD", select [count] WORDs (see |WORD|). 
      White space between words is counted too. 
      When used in Visual linewise mode "iW" switches to 
      Visual characterwise mode. 

          *v_as* *as* 
as   "a sentence", select [count] sentences (see 
      |sentence|). 
      When used in Visual mode it is made characterwise. 

          *v_is* *is* 
is   "inner sentence", select [count] sentences (see 
      |sentence|). 
      When used in Visual mode it is made characterwise. 

          *v_ap* *ap* 
ap   "a paragraph", select [count] paragraphs (see 
      |paragraph|). 
      Exception: a blank line (only containing white space) 
      is also a paragraph boundary. 
      When used in Visual mode it is made linewise. 

          *v_ip* *ip* 
ip   "inner paragraph", select [count] paragraphs (see 
      |paragraph|). 
      Exception: a blank line (only containing white space) 
      is also a paragraph boundary. 
      When used in Visual mode it is made linewise. 

a]      *v_a]* *v_a[* *a]* *a[* 
a[   "a [] block", select [count] '[' ']' blocks. This 
      goes backwards to the [count] unclosed '[', and finds 
      the matching ']'. The enclosed text is selected, 
      including the '[' and ']'. 
      When used in Visual mode it is made characterwise. 

i]      *v_i]* *v_i[* *i]* *i[* 
i[   "inner [] block", select [count] '[' ']' blocks. This 
      goes backwards to the [count] unclosed '[', and finds 
      the matching ']'. The enclosed text is selected, 
      excluding the '[' and ']'. 
      When used in Visual mode it is made characterwise. 

a)       *v_a)* *a)* *a(* 
a(       *v_ab* *v_a(* *ab* 
ab   "a block", select [count] blocks, from "[count] [(" to 
      the matching ')', including the '(' and ')' (see 
      |[(|). Does not include white space outside of the 
      parenthesis. 
      When used in Visual mode it is made characterwise. 

i)       *v_i)* *i)* *i(* 
i(       *v_ib* *v_i(* *ib* 
ib   "inner block", select [count] blocks, from "[count] [(" 
      to the matching ')', excluding the '(' and ')' (see 
      |[(|). 
      When used in Visual mode it is made characterwise. 

a>      *v_a>* *v_a<* *a>* *a<* 
a<   "a <> block", select [count] <> blocks, from the 
      [count]'th unmatched '<' backwards to the matching 
      '>', including the '<' and '>'. 
      When used in Visual mode it is made characterwise. 

i>      *v_i>* *v_i<* *i>* *i<* 
i<   "inner <> block", select [count] <> blocks, from 
      the [count]'th unmatched '<' backwards to the matching 
      '>', excluding the '<' and '>'. 
      When used in Visual mode it is made characterwise. 

         *v_at* *at* 
at   "a tag block", select [count] tag blocks, from the 
      [count]'th unmatched "<aaa>" backwards to the matching 
      "</aaa>", including the "<aaa>" and "</aaa>". 
      See |tag-blocks| about the details. 
      When used in Visual mode it is made characterwise. 

         *v_it* *it* 
it   "inner tag block", select [count] tag blocks, from the 
      [count]'th unmatched "<aaa>" backwards to the matching 
      "</aaa>", excluding the "<aaa>" and "</aaa>". 
      See |tag-blocks| about the details. 
      When used in Visual mode it is made characterwise. 

a}       *v_a}* *a}* *a{* 
a{       *v_aB* *v_a{* *aB* 
aB   "a Block", select [count] Blocks, from "[count] [{" to 
      the matching '}', including the '{' and '}' (see 
      |[{|). 
      When used in Visual mode it is made characterwise. 

i}       *v_i}* *i}* *i{* 
i{       *v_iB* *v_i{* *iB* 
iB   "inner Block", select [count] Blocks, from "[count] [{" 
      to the matching '}', excluding the '{' and '}' (see 
      |[{|). 
      When used in Visual mode it is made characterwise. 

a"       *v_aquote* *aquote* 
a'       *v_a'* *a'* 
a`       *v_a`* *a`* 
      "a quoted string". Selects the text from the previous 
      quote until the next quote. The 'quoteescape' option 
      is used to skip escaped quotes. 
      Only works within one line. 
      When the cursor starts on a quote, Vim will figure out 
      which quote pairs form a string by searching from the 
      start of the line. 
      Any trailing white space is included, unless there is 
      none, then leading white space is included. 
      When used in Visual mode it is made characterwise. 
      Repeating this object in Visual mode another string is 
      included. A count is currently not used. 

i"       *v_iquote* *iquote* 
i'       *v_i'* *i'* 
i`       *v_i`* *i`* 
      Like a", a' and a`, but exclude the quotes and 
      repeating won't extend the Visual selection. 
      Special case: With a count of 2 the quotes are 
      included, but no extra white space as with a"/a'/a`. 

When used after an operator: 
For non-block objects: 
    For the "a" commands: The operator applies to the object and the white 
    space after the object. If there is no white space after the object 
    or when the cursor was in the white space before the object, the white 
    space before the object is included. 
    For the "inner" commands: If the cursor was on the object, the 
    operator applies to the object. If the cursor was on white space, the 
    operator applies to the white space. 
For a block object: 
    The operator applies to the block where the cursor is in, or the block 
    on which the cursor is on one of the braces. For the "inner" commands 
    the surrounding braces are excluded. For the "a" commands, the braces 
    are included. 

When used in Visual mode: 
When start and end of the Visual area are the same (just after typing "v"): 
    One object is selected, the same as for using an operator. 
When start and end of the Visual area are not the same: 
    For non-block objects the area is extended by one object or the white 
    space up to the next object, or both for the "a" objects. The 
    direction in which this happens depends on which side of the Visual 
    area the cursor is. For the block objects the block is extended one 
    level outwards. 

For illustration, here is a list of delete commands, grouped from small to big 
objects. Note that for a single character and a whole line the existing vi 
movement commands are used. 
    "dl" delete character (alias: "x")  |dl| 
    "diw" delete inner word   *diw* 
    "daw" delete a word    *daw* 
    "diW" delete inner WORD (see |WORD|)  *diW* 
    "daW" delete a WORD (see |WORD|)  *daW* 
    "dd" delete one line    |dd| 
    "dis" delete inner sentence   *dis* 
    "das" delete a sentence   *das* 
    "dib" delete inner '(' ')' block  *dib* 
    "dab" delete a '(' ')' block   *dab* 
    "dip" delete inner paragraph   *dip* 
    "dap" delete a paragraph   *dap* 
    "diB" delete inner '{' '}' block  *diB* 
    "daB" delete a '{' '}' block   *daB* 

Note the difference between using a movement command and an object. The 
movement command operates from here (cursor position) to where the movement 
takes us. When using an object the whole object is operated upon, no matter 
where on the object the cursor is. For example, compare "dw" and "daw": "dw" 
deletes from the cursor position to the start of the next word, "daw" deletes 
the word under the cursor and the space after or before it. 

ध्यान दें कि आप दो आदेश (के साथ अपना स्वयं का पाठ वस्तुओं बना सकते हैं, उदाहरण के लिए आप "K" चाहते हैं एक नया पाठ ऑब्जेक्ट होने की:

यहाँ पूरे अनुभाग है जब ऑपरेटर मोड में आप केंद्र में कर्सर के साथ तीन पात्रों का चयन करना चाहते है, और दृश्य मोड में आप दोनों सिरों को 1 चरित्र द्वारा चयन का विस्तार करना चाहते हैं (बशर्ते कि अपने कर्सर चयन के अंत में है):

"operator-pending mapping 
onoremap K :normal! hv2l<return> 
"visual mapping (xmap preferred over vmap because vmap also works in select mode) 
"note that in visual mode o goes to the other end. Therefore this will expand selection if you were at the end and restrict it otherwise. 
xnoremap K ohol 
+0

का दायरा है, मुझे आपके अपने ऑपरेटर को फिर से परिभाषित करने के बारे में पता नहीं था। –

2

देखें

:he text-objects 

vaw - 'आस-पास' शब्द का चयन करें। viw - 'आंतरिक' शब्द का चयन करें।

आपके द्वारा दिया गया उदाहरण दो ऑपरेशन के बीच अंतर नहीं दिखाएगा।

एकल या डबल-कोटेड शब्द के साथ यह कोशिश करो और आप अंतर देखेंगे:

"Sasq[u]atch" 

कोशिश viw और इसके बाद के संस्करण पर VAW और आप इसे देखेंगे।

+0

मैंने कोशिश की है, और यह कुछ भी नहीं बदलता है ?? "myword" -> viw या vaw: शब्द का चयन करें (उद्धरण नहीं)। लेकिन ... 'myword' -> viw: शब्द और उद्धरण का चयन करें। vaw: शब्द और उद्धरण और सही जगह के बगल में चुनें। वैसे भी, उद्धरण (सिंगल या डबल) के साथ, मैं उद्धरण के बिना शब्द प्राप्त करने के लिए: vi "/ vi" का उपयोग करूंगा। लेकिन vaw और viw डबल कोट्स के साथ कुछ भी नहीं बदलता है। – ThePhi

+0

@ThePhi आप शायद पढ़ना चाहते हैं ': 'iskeyword' मदद करें – holygeek

6

यह टेक्स्ट-ऑब्जेक्ट से संबंधित है।

  • vaw का मतलब है "का चयन करें (दृश्य मोड) एक वर्ड (निम्नलिखित खाली स्थान के सहित)"
  • caw का अर्थ है "बदलें एक वर्ड (निम्नलिखित खाली स्थान के सहित)"
  • daw का अर्थ है "एक वर्ड (सहित निम्नलिखित खाली स्थान के हटाएं) "

यदि आप" मैं "का उपयोग कर रहे हैं तो यह एक ही चीज है, सिवाय इसके कि यह एक" आंतरिक "चयन है, इसलिए यह आसपास के सफेद जगहों का चयन नहीं करता है।अनुच्छेद के लिए

  • पी वाक्य के लिए
  • रों
  • (के लिए कोष्ठक
  • ] के लिए कोष्ठक
  • आदि
  • ब्लॉक के लिए
  • ख:

    जैसे अन्य पाठ वस्तुओं रहे हैं

तो वर्तमान पैराग्राफ को हटाने के लिए आप dip करते हैं। अधिक जानकारी के लिए

:help text-objects देखें।

यह एक बहुत ही शक्तिशाली विम सुविधा है। एक बार जब आप टेक्स्ट-ऑब्जेक्ट्स मास्टर करते हैं, तो आप उन्हें अधिकांश परिचालनों के लिए उपयोग करने जा रहे हैं। उदाहरण के लिए यदि आप एक (सी जैसे) फ़ंक्शन को दोबारा सुधारना चाहते हैं, तो आप =i} का उपयोग कर सकते हैं और यह हो गया है! (= रीफ्रेट करने का आदेश है, और i} वर्तमान {ब्लॉक)

संबंधित मुद्दे