Skip to content

Surround

Surrounds are another useful feature of Helix which allow you to perform common actions such as:

  • Surround selection with character
  • Replace surrounding character
  • Delete surrounding character

You can use any character for a surround add, replace or delete operation — such as x.

Some surround characters are more advanced, for having a selecting and surrounding it with ( with add ( at the beginning of the selection and ) at the end.

Surround selection with character

You can surround selections with specific characters with ms for make surrounding. For example, with the following state:

    1  const obj =              
    2    [key, "value"];        
    ~                           
 NOR   file.ts [+]   1 sel  2:6 
                                

Pressing ms(, you surround the selection with (:

    1  const obj =              
    2    [(key), "value"];      
    ~                           
 NOR   file.ts [+]   1 sel  2:8 
                                

Replace surrounding character

But what if we actually meant to surround it with { instead? That’s fine! We can make replace the surrounding character with mr

For instance, mr({ replaces the surrounding ( with a {:

    1  const obj =              
    2    [key, "value"];        
    ~                           
 NOR   file.ts [+]   1 sel  2:7 
                                

Delete surrounding character

If we wanted to delete the surrounding character, we could also use md for make delete. For example to delete the nearest surrounding pair of {, use md{.

    1  const obj =              
    2    [key, "value"];        
    ~                           
 NOR   file.ts [+]   1 sel  2:6 
                                

List of surrounds

Helix has support for the following pairs of surrounds:

  • { and }
  • ( and )
  • [ and ]
  • < and >

Use any character

You can also use any other character which will act on the literal characters. For instance, if we have a markdown file like follows:

    1  Hello _*world*_!         
    ~                           
                                
 NOR   file.md [+]   1 sel  1:9 
                                
  1. Pressing md* will delete the nearest *.
    1  Hello _world_!           
    ~                           
                                
 NOR   file.md [+]   1 sel  1:8 
                                
  1. Using mro{ will replace the nearest pairs of o character with {:
    1  Hell{ _w}rld_!           
    ~                           
                                
 NOR   file.md [+]   1 sel  1:8 
                                

Next steps

With multiple cursors, macros, text objects and finally surround you now have all of the most important tools for efficiently working with text.

Let’s learn how to configure editor tooling next, with setting up language support.