# Yank the characters that replace concealed strings?

For example, in .tex files, the expression $\sum$ is replaced with ∑. I would like to yank ∑, but when I try I get one of the characters that compose $\sum$, even when I set concealcursor. What is the simplest way to do this?

• do you want to yank the hidden text or the character that is shown on top of the concealed text? Nov 10 '20 at 9:23
• The character shown on top. I have rephrased my question, hopefully it is clearer now. Nov 10 '20 at 11:28

Concealing characters is just a visual representation of the physical text. Vim commands however work with the actual text, so that yanking actually yanks what is in the buffer and not what is displayed.

If you want to capture what is displayed, there are a couple of ways around it. The easiest solution is, if you are using Vim in the terminal and let the terminal handle mouse selection by pressing shift when visually selecting with the mouse. Since the terminal handles the mouse selection, you can paste it using middle mouse button wherever you need it (and the terminal is not aware of what the actual text is, it will copy verbatim whatever is on the screen, like numbering, list characters etc.).

Another solution is to make use of the various screen...() functions provided by Vim. E.g. Start reading at :h screenattr() and make use of whatever function you need. Those functions have initially been created for Vims test suite to make assert what is displayed on the screen. But of course you can make use of it.

See also this answer on how to copy what is displayed in the current viewport. For your usecase, you just need to get rid of the loop and use screencol() and screenrow() or winline(). Note, you might need to adjust the line number for the tabline.

Update: Note, there also exists the synconcealed() function, that returns whether the item at the given position is concealed.

• There is also synconcealed(line, col) which returns a list with three items: a flag whether the character at the given position is concealed, its replacement text if concealed, and a number which allows to differentiate between adjacent concealed regions. Nov 10 '20 at 14:16
• Oh yes, I remember. This has been added for the 2html plugin. Thanks for reminding Nov 10 '20 at 14:29
• Thank you. Is there a way to let the terminal handle mouse selection in gVim on Windows? Nov 10 '20 at 16:00
• If you are running gvim, then there is no controlling terminal around it, so no. Nov 10 '20 at 18:23
• Because when you enter :echo screenrow() your cursor is in the last line. The the remark at :h screencol() Nov 11 '20 at 7:06