nvim-surround
What is nvim-surround
- Add/change/delete surrounding delimiter pairs with ease
- A plugin for Neovim written in Lua
kylechui/nvim-surround
Text objects
In Vim, text objects allow you to select pieces of text based on their structure or syntax. Here is a list of common text objects in ascending order by their typical size:
- a character (
v
orV
):v
- a word (
w
andiw
):iw
- a WORD (an entire string of non-blank characters,
W
andiW
):iW
- a sentence (
as
andis
):is
- a paragraph (
ap
andip
):ip
- a block of text enclosed in delimiters (
a(
,a)
,ab
,aB
,a{
,a}
,i(
,i)
,ib
,iB
,i{
,i}
):i(
,a)
- a block of text enclosed in quotes (
a'
,a"
,i'
,i"
):i'
,a"
These text objects are invaluable when working with the nvim-surround
plugin for efficient text editing within Vim.
Use examples
Old text Command New text
surr*ound_words ysiw) (surround_words)
*make strings ys$" "make strings"
[delete ar*ound me!] ds] delete around me!
remove <b>HTML t*ags</b> dst remove HTML tags
'change quot*es' cs'" "change quotes"
<b>or tag* types</b> csth1<CR> <h1>or tag types</h1>
delete(functi*on calls) dsf function calls
Normal mode
Mnemonics
ys
(you surround/add):ys<motion><delimiter>
cs
(change surrounding):cs<old delimter><new delimiter>
ds
(delete surrounding):ds<delimiter>
examples
ysiw"
to add double quote around a wordysa")
to add parenthesis around quoted contentysl'
yst;}
ys8jt
+ HTML tag, add tags around contentyss
: Add a surrounding pair around the current line (normal mode)yS
: Add a surrounding pair around a motion, on new lines (normal mode)ySS
: Add a surrounding pair around the current line, on new lines (normal mode)ds"
to delete double quote around a worddst
to delete the surrounding tagscs"'
to replace double quote by single quotecst
+ HTML tag, change surrounding tags with new tagsyswf
csf
dsf
This is a paragraph.
Insert mode
- ??
Visual mode
S'
S>
Use :h nvim-surround.usage
to learn more