nvim-surround
nvim-surround copied to clipboard
blod text in markdown ysw**
Checklist
- [X] Have you read through
:h nvim-surroundto see if there might be any relevant information?
wo*rd --> **wo*rd***
the result would:
word
at know, it's difficult for men to use two asterisks to surround text, because, I lost my selection
I don't quite understand what your issue is here. What keypresses are you inputting? Where is the cursor in the text?
i want a feature like that
" using register d
vnoremap ** "ddi**<C-r>d**<Esc>gv
I use the following custom surround:
require("nvim-surround").setup {
surrounds = {
["*"] = {
add = { "**", "**" },
find = "%*%*.-%*%*",
delete = "^(%*%*?)().-(%*%*?)()$",
change = {
target = "^(%*%*?)().-(%*%*?)()$",
},
},
},
}
Then you can do ysiw* to surround a word with **.
Or you can use require("nvim-surround").buffer_setup in a filetype/markdown.lua file in your config if you only want the mapping to be active for a specific filetype.
Thanks to @kylechui for the original patterns! :) (https://github.com/kylechui/nvim-surround/discussions/121#discussioncomment-3340224)
@ayoubelmhamdi Assuming that the above solution works for you; feel free to tag me or reopen this issue if any other related issues appear.
@kylechui yes it's work, but not better, with this method, I lose the way to set one asterisk for italic,
if possible is this a trick to use ysiw* and ysiw** together.
Multi-character surrounds are not supported (nor do I plan on it). One "workaround" for your use case is to have ysiW* for italicizing the current word, and then . to dot-repeat a second set of asterisks.
that great Mr @kylechui, and sufficient now, particularly with ysiW* then .
do you have a plan to make ysiw* then . to do this thing also?
That particular use case has less to do with nvim-surround as a plugin and more to do with how text-objects work in (Neo)Vim. The iw text-object selects the current word, but stops at certain delimiter characters, including *. On the other hand, the iW object (to my knowledge) selects up to the surrounding whitespace. If you try ysiw*. then the dot-repeat will surround the left asterisk with another pair of asterisks, since the cursor is hovering over the left asterisk. Some alternatives are to:
- Use
ysiw*l.- This will move the cursor over the original word before you dot-repeat, surrounding the correct object
- Remap
iwtoiWviaonoremap(probably ill-advised)
yak, thanks @kylechui, probably treesittre could help, in this case!
I'm not entirely sure how Tree-sitter would help in this particular case; but if you have any follow-up questions you can ask here.
I use the markdowny.nvim plugin to incorporate bold, italic, and link formatting within markdown or other documents. I hope this will be beneficial for someone.