New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Surround a text/word with special characters #1307

danielschmitz opened this Issue Dec 14, 2015 · 12 comments



danielschmitz commented Dec 14, 2015

Surround a text/word with special characters by selecting it and pressing the special character.



This comment has been minimized.


hashhar commented Dec 14, 2015

Woah!!! We need this, but this looks to be better suited as an extension really. It should have some kind of modifier key though because I sometimes would like to replace a word with a special character.

Maybe Alt + special character?


This comment has been minimized.


dbaeumer commented Dec 15, 2015

@bpasero Ben, start with you here since this sounds like a mark down feature. I think there is no underlying support needed in the editor to make this happen.

@bpasero bpasero removed their assignment Dec 15, 2015


This comment has been minimized.

danielschmitz commented Dec 15, 2015

Hello guys, its a mark down "native" feature.



This comment has been minimized.

OceanAirdrop commented Jan 3, 2016

Yes, this is similar to the plugin for the brackets IDE.

Very useful for wrapping html elements around selected text.

+1 from me!


This comment has been minimized.

JVimes commented Apr 12, 2016

Great in any language for quotes/brackets/parens. User expects to be able to overwrite text by highlighting and typing, so @hashhar's suggestion is on the right track. Alt might not work right on Mac, since it's already used by the system to insert special characters (like ÷«“‘ªº). But other modifier(s) should.


This comment has been minimized.

jorgeas80 commented Nov 20, 2016

Need this!


This comment has been minimized.


hashhar commented Nov 20, 2016

Maybe someone can take a look at how they implemented the surround with quotes to get an idea to extend it. I think after v1.6 we could select text and press " or ' and that surrounded the text.

EDIT: Found it.

EDIT 2: See this for learning how to achieve this currently. Currently this feature is available when autoClosingBrackets is enabled.


This comment has been minimized.

M-Zuber commented Dec 20, 2016

What I would want is full surround with like exists in Visual Studio see here for super quick intro which would let me use any snippet in addition to punctuation.
It is very handy for things like moving code into an if or try/catch.

The far dream would have us be able to declare an arbitrary punctuation pair and use that like we can now with (), [], ect.

Most of this functionality could be hidden behind a shortcut like ctrl+k, s for those who are worried about it interfering with basic typing.


This comment has been minimized.

stannynuytkens commented Dec 30, 2016

Was suprised to see the behaviour for markdown files concerning surrounding selected text with the typed character is different from say js, html, css, ... files. Was this by design intended to exclude md files from this behaviour?


This comment has been minimized.

sethlivingston commented Jan 1, 2017

Parity with Visual Studio would be great here. I know it can be an extension, but IMHO this should be built in or a pre-installed extension.


This comment has been minimized.

spacegoing commented Jan 16, 2017

How can I enable this feature in markdown files? Which command implements this?

@mjbvz mjbvz self-assigned this Mar 24, 2017

@mjbvz mjbvz added the help wanted label Apr 7, 2017

@mjbvz mjbvz modified the milestones: April 2017, Backlog Apr 7, 2017

@mjbvz mjbvz removed the help wanted label Apr 7, 2017

@mjbvz mjbvz closed this in 8fbad6e Apr 7, 2017


This comment has been minimized.


mjbvz commented Apr 7, 2017

I just pushed 8fbad6e which adds this feature for markdown. To use it, select some text in markdown and trigger the insert snippet command. The bold, Italic, and inline code snippets for markdown all have this enabled now.

Here's the reason a snipped based approach was selected and how other extensions/languages can implement this sort of functionality:

For basic surround logic, extensions can use the surroundWith language configuration option. Adding * for the surroundWith in the markdown language configuration allows the behavior that @danielschmitz originally described. surroundWith can also be configured separately from autoClosingPairs.

However, in testing, I was concerned that surroundWith for * and other special characters may get in the way of too many users. That's why I went with a more explicit snippet based approach. This makes use of the TM_SELECTED_TEXT value present in snippets:

	"Insert bold text": {
		"prefix": "bold",
		"body": "**${1:${TM_SELECTED_TEXT}}**$0",
		"description": "Insert bold text"

Any extension can contribute snippets that make use of this pattern. Feel free to submit a PR if you would like any of the other markdown snippets to use the surround logic as well

Please let me know if you have any questions or concerns about the current approach

@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 18, 2017

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.