Question: My Problem
==========

I am editing a markdown file with some links in a `[link text](url)` format.

Some of these links lack a space after the closing parens, e.g.:

```
...fit the [Single Responsibility Principle](https://link...)and can ...

```

Which renders to a missing space after the link:

> 
> ...fit the [Single Responsibility Principle](https://link...)and can ...
> 
> 
> 

I am trying to build a regex search-replace to add a missing space after the closing parens where necessary.

What have I (naively) tried
===========================

Tried search-replacing with a regex:

```
%s#\)(\S)#\) (\1)#gc

%s#\)                 - Closing parens
%s#\)(\S)             - Followed by a non-space
%s#\)(\S)#            - Replaced with...
%s#\)(\S)#\)          - The closing parens followed by a space
%s#\)(\S)#\) (\1)#gc  - And the original character

```

And, of course, Googled the problem.

My question
===========

**How can I add a space after every closing parens that has a non-space character just after it?**

Answer: 
What about

```
%s#)\zs\ze\S# #g

```

By default unless you change the [`'magic'`](http://vimhelp.appspot.com/options.txt.html#%27magic%27) option, a closing parenthesis is matched by just `)`. BTW, here I've cheated with [`:h /\zs`](http://vimhelp.appspot.com/pattern.txt.html#%2f%5czs) and [`:h /\ze`](http://vimhelp.appspot.com/pattern.txt.html#%2f%5cze) to mark the in between characters that we want to expand with a single space.
Try these:

```
# match ) followed by zero or more spaces and replace with ) and space
s/) */) /

# match ) followed by optional space and replace with ) and space
s/) \?/) /

```

`)` is not escaped here, because by default `(` and `)` are not special

Add `g` flag if you need to replace multiple occurrences in a line