I'm new to vim. And I'm pressing too many buttons doing basic text wrapping:
string -> "string"long string with many words -> 'long string with many words'a + b * c -> (a + b) * c(elem0, elem1, elem2) -> [elem0, elem1, elem2] (optional)I'm doing all that manually: go to begin, Insert mode, press key, Normal mode, (the same for second character).
How to do it faster? E.g.: visually select the text, smart-wrap it with what you need. Or even without visual selection.
string -> "string"
ciw"<C-r>""
long string with many words -> 'long string with many words'
veeeeec'<C-r>"'
a + b * c -> (a + b) * c
vwwc(<C-r>")
(elem0, elem1, elem2) -> [elem0, elem1, elem2] (optional)
"edibxs[<C-r>e]
That one is a bit more complicated:
"edib cut the content of those parentheses into
an arbitrary register, here I used "e
xs cut the closing parenthese then cut the opening one
and enter insert mode
[<C-r>e] insert the opening bracket, followed by the content of
register e, followed by the closing bracket
But yeah, use Tim Pope's Surround.
You can use visuall mode for this. For example you have string. ^ will be cursor positioning. Start in normal mode
1. string # press viwc(your word will be selected and deleted to unnamed register)
^
2. # press " and then <C-r>"(this will paste your selected text) and then press again "
This method can be with any surrounding parenthesis or brackets and with any number of words. you just need to change your selection in visual mode
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With