如何使用'',“”,(),[],{}等在vim中包装一些文本?

时间:2016-10-31 05:16:12

标签: vim

我是vim的新手。我正在按太多按钮进行基本文本换行:

  1. SELECT Emp_Name, date_format(Emp_DOB, '%d-%b') AS Emp_DOB FROM mldob.tbl_mldob WHERE (MONTH(Emp_DOB ), DAY(Emp_DOB )) = (MONTH(NOW()),DAY(curdate()-1)) OR (MONTH(Emp_DOB ), DAY(Emp_DOB )) = (MONTH(NOW()),DAY(curdate())) OR (MONTH(Emp_DOB ), DAY(Emp_DOB )) = (MONTH(NOW()),DAY(curdate()+1)) ; - > string
  2. "string" - > long string with many words
  3. 'long string with many words' - > a + b * c
  4. (a + b) * c - > (elem0, elem1, elem2) (可选)
  5. 我手动完成所有操作:转到开始,插入模式,按键,普通模式,(第二个字符相同)。

    怎么做更快?例如:在视觉上选择文本,用你需要的东西进行智能包装。甚至没有视觉选择。

2 个答案:

答案 0 :(得分:2)

  1. string - > "string"

    ciw"<C-r>""
    
  2. long string with many words - &gt; 'long string with many words'

    veeeeec'<C-r>"'
    
  3. a + b * c - &gt; (a + b) * c

    vwwc(<C-r>")
    
  4. (elem0, elem1, elem2) - &gt; [elem0, elem1, elem2](可选)

    "edibxs[<C-r>e]
    

    那个有点复杂:

    "edib        cut the content of those parentheses into
                 an arbitrary register, here I used "e
    
    xs           cut the closing parenthese then cut the opening one
                 and enter insert mode
    
    [<C-r>e]     insert the opening bracket, followed by the content of
                 register e, followed by the closing bracket
    
  5. 但是,请使用Tim Pope的Surround。

答案 1 :(得分:1)

您可以使用visuall模式。例如,您有string^将是光标定位。以正常模式启动

1. string # press viwc(your word will be selected and deleted to unnamed register)
   ^
2. # press " and then <C-r>"(this will paste your selected text) and then press again "

此方法可以使用任何周围的括号或括号以及任意数量的单词。你只需要在视觉模式下改变你的选择