Regex to match beginning and end of line in Vim (quote around whole line)

regular expressiontext processingvim

For an initial file with lines like this example:

1
12
123
1234
12345

The desired state of the file is

'1'
'12'
'123'
'1234'
'12345'

I've been doing this with two commands, :%s/^/'/g and :%s/$/'/g, that I would like to get into one. However, when I try

:%s/[$^]/'/g

I get the error

E486: Pattern not found: [$^]

I know the leading ^ in brackets means exclusion, so I figured putting $ first would mean match both the beginning and end of lines, which is obviously not happening.

How can I match both the beginning and end of lines in vim?

Best Answer

How about:

:%s/.*/'&'/

"Replace zero or more characters with those characters preceded and succeded by a single-quote".

Related Question