kylechui / nvim-surround

Add/change/delete surrounding delimiter pairs with ease. Written with :heart: in Lua.
MIT License
3.09k stars 61 forks source link

blod text in markdown ysw** #151

Closed ayoubelmhamdi closed 1 year ago

ayoubelmhamdi commented 1 year ago

Checklist

kylechui commented 1 year ago

I don't quite understand what your issue is here. What keypresses are you inputting? Where is the cursor in the text?

ayoubelmhamdi commented 1 year ago

i want a feature like that

" using register d

vnoremap ** "ddi**<C-r>d**<Esc>gv
smjonas commented 1 year ago

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)

kylechui commented 1 year ago

@ayoubelmhamdi Assuming that the above solution works for you; feel free to tag me or reopen this issue if any other related issues appear.

ayoubelmhamdi commented 1 year ago

@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.

kylechui commented 1 year ago

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.

ayoubelmhamdi commented 1 year ago

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?

kylechui commented 1 year ago

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:

ayoubelmhamdi commented 1 year ago

yak, thanks @kylechui, probably treesittre could help, in this case!

kylechui commented 1 year ago

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.

ful1e5 commented 1 year ago

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.