1

Very often I need to enclose a selected piece of text or anything else with braces:

Lorem ipsum dolor sit met.
     [-----] <- selection

but when I hit for example { the selectecd text is replaced with the { instead. However I'd like it to be enclosed with {} like:

Lorem {ipsum} dolor sit met.

Is it possible to do with ReSharper v9?

t3chb0t
  • 16,340
  • 13
  • 78
  • 118

1 Answers1

2

Fortunately, in case of text selection it is possible to do with Surround Templates called by Alt+Enter (Visual Studio keyboard scheme). ReSharper has built-in template for braces: {}. It places the braces on separate lines, so in your case better to define custom template in Tools -> Templates Explorer. It's easy, you need to add something like {$SELECTION$} in template definition and it will be inline.

P.S. R# If you select code, not a text piece inside a string definition, then R# prevents braces placing on the same line. So custom inline template will not work in code case.

Ilya Chumakov
  • 23,161
  • 9
  • 86
  • 114
  • I know VS templates and I even created my own but I've never come up to the idea to look at the `Surround Templates`, how embarassing. I'll try it out. ;-) Thanks. – t3chb0t Oct 26 '15 at 11:21
  • I got it ;-) I edited the default `{}` `Surround Template` and removed the line breaks, then I disabled the `Reformat` option and `R#` doesn't add any line breaks anymore. Now I just need to repeat it for `()` and `[]`. – t3chb0t Oct 26 '15 at 17:09
  • @t3chb0t, interesting, I was sured that `Reformat` option doesn't change braces position, thanks! Also there is a lot of brace auto-format options in R#, so the formatting may work unexpectingly sometimes. These settings may be easily filtered by promting "brace" in R# `Options` searchbox. – Ilya Chumakov Oct 26 '15 at 19:49