Reputation: 2253
what is the vim command can put something into Parentheses efficiently and then I can use .
to repeat it? ?
for example, data['max']
to (data['max'])
Upvotes: 0
Views: 2038
Reputation: 696
You can use a map in vimrc:
xnoremap <leader>a <ESC>`>a)<ESC>`<i(<ESC>
And use <leader>
and a
to add parentheses efficiently
Upvotes: 0
Reputation: 196476
visually select your text:
viW
change it with the opening parenthesis, followed by the selected text, followed by the closing parenthesis:
c(<C-r><C-o>")<Esc>
If you are confident with text-objects, this can be done in one step:
ciW(<C-r><C-o>")<Esc>
which can be repeated with .
.
Upvotes: 7
Reputation: 28169
I'd recommend using two plugins for this. Tim Pope's vim-surround
and vim-repeat
.
Just follow the links and install those plugins.
Inorder to put parenthesis around a word, just do ysiw)
Otherwise, select text in visual mode, press S(Capital S) and type in paranthesis
Upvotes: 3
Reputation: 1496
You can use a map for that.
:nmap \. I(<ESC>A)
You can put this line in your ~/.vimrc file.
When you press \
and .
in normal mode, it will add a opening bracket at the start of the line and closing bracket at the end of the line.
Assuming that you are using a language like Tcl and surround the hash element with a bracket, You can try this by keeping the cursor anywhere on the hash name,
: nmap \. bi(<Esc>f]li)
This will surround the expected one with circular braces.
Upvotes: 2