Skip to content

Text selection and vim surround

Dennis Cual edited this page Oct 16, 2020 · 4 revisions

You must install the vim-surround to apply the tricks. Also need to make sure that you are on the normal mode before you try.

    Vim
    Hello world

Put the cursor at the Vim, any word, then type ysw + <h1>. This will surround the text into h1 element. Then cursor on the Hello world press V + S + <span> will surround the paragraph into span` element.

   <h1>Vim</h1>
   <span>Hello world</span>

Press V then go to next line until you select the whole line. Press S + <header>. This will contain all of the elements inside teh header element

   <header>
     <h1>Vim</h1>
     <span>Hello world</span>
   </header>

Move the cursor at <span> then press cst + <p>, will change from span into p.

   <header>
     <h1>Vim</h1>
     <p>Hello world</p>
   </header>

Cursor at the <p> then pressing dit will delete the content. Alternatively, you can use cit to write immediately. Change the content into A clever boy.

   <header>
     <h1>Vim</h1>
     <p>A clever boy</p>
   </header>

Cursor at the <header> then press vat to visually select the element and its content. vit will select its content but not the parent element. Then press S + <article> will surround the elements by the article.

  <article>
     <header>
       <h1>Vim</h1>
       <p>A clever boy</p>
     </header>
  </article>

Place the cursor at the header element or any line as long the cursor is not placed on other element, then press dst, this will delete the header.

  <article>
      <h1>Vim</h1>
      <p>A clever boy</p>
  </article>

Resources

Clone this wiki locally