nvim-surround icon indicating copy to clipboard operation
nvim-surround copied to clipboard

blod text in markdown ysw**

Open ayoubelmhamdi opened this issue 3 years ago • 3 comments

Checklist

  • [X] Have you read through :h nvim-surround to 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

ayoubelmhamdi avatar Sep 14 '22 08:09 ayoubelmhamdi

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

kylechui avatar Sep 14 '22 22:09 kylechui

i want a feature like that

" using register d

vnoremap ** "ddi**<C-r>d**<Esc>gv

ayoubelmhamdi avatar Sep 15 '22 10:09 ayoubelmhamdi

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)

smjonas avatar Sep 15 '22 10:09 smjonas

@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 avatar Sep 27 '22 20:09 kylechui

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

ayoubelmhamdi avatar Sep 28 '22 16:09 ayoubelmhamdi

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.

kylechui avatar Sep 28 '22 17:09 kylechui

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?

ayoubelmhamdi avatar Sep 28 '22 18:09 ayoubelmhamdi

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 iw to iW via onoremap (probably ill-advised)

kylechui avatar Sep 28 '22 18:09 kylechui

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

ayoubelmhamdi avatar Sep 28 '22 18:09 ayoubelmhamdi

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.

kylechui avatar Sep 28 '22 18:09 kylechui

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.

ful1e5 avatar Jan 20 '23 12:01 ful1e5