Adding parenthesis around highlighted text in Vim

vim

Is there a functionality in Vim that allows parenthesis to be added around the highlighted text?

For instance, if I highlight n = getchar() in if (n = getchar() == '\n'), I would want to put parenthesis around that.

Best Answer

You need an awesome and must-have plugin surround. Then, it will happily do what you want if you select text and type Sb (surround-braces), or S) (note the capital S !).

It actually can do a lot of surrounding: various quotes, tags, etc. It allows you to put cursor in the double-quoted word and change double quotes to single quotes by typing: cs"' (change-surround " to '). Or you can completely delete quotes by typing ds" (delete-surround ").

Read the docs by link, it is really awesome!