How do I put selected text inside quotes or brackets manually?
Answer
c""<Esc>P
Explanation
Without a surround plugin, you can manually wrap selected text by changing it, typing the delimiters, and pasting the original text back. This is a basic technique that works in vanilla Vim.
How it works
- Select the text in visual mode
cchanges (deletes and enters insert mode)- Type the opening and closing delimiters:
"" <Esc>returns to normal modePpastes the deleted text before the cursor (between the delimiters)
Example
hello
Select hello with viw, then type c""<Esc>P:
"hello"
Tips
- For parentheses:
c()<Esc>P - For brackets:
c[]<Esc>P - The
vim-surroundplugin makes this much easier S"with vim-surround wraps the selection in quotes- This technique uses the default register, so be mindful of what you have yanked