iTranslated by AI
The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
📚
Introduction to surround.vim for Intermediate Vim Users
Official repository https://github.com/tpope/vim-surround
Why
- Manipulating surroundings (quotes, parentheses, tags, etc.) becomes much easier.
- It's often included by default in Vim plugins, so it's ready to use right away.
VSCodeVim (VSCode), IdeaVIM (JetBrains)
Plug 'tpope/vim-surround'
Demos
I will introduce the basic commands following the official Introduction.
vim-surround/surround.txt at master · tpope/vim-surround
cs "change surround"
Changing existing surroundings. This modifies the surroundings outside the cursor position.
"Hello world!"
↓cs"'
'Hello world!'
"Hello world!"
↓cs"<q>
<q>Hello world!</q>
(123+456)/2
↓cs)]
[123+456]/2
In the case of an opening parenthesis/bracket, a space is inserted inside the surroundings.
(123+456)/2
↓cs)[
[ 123+456 ]/2
<div>Yo!</div>
↓cst<p>
<p>Yo!</p>
ds "delete surround"
Deleting surroundings. One level outside from the cursor position.
"Hello world!"
↓ds"
Hello world!
(123+456)/2
↓ds)
123+456/2
<p>Yo!</p>
↓dst
Yo!
ys "you surround"
Hello w\*orld!
↓ysiw)
Hello (world)!
virtual select → S
Hello w\*orld!
↓viwS)
Hello (world)!
Discussion