Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to yank a code block without folded content?

Tags:

vim

yank

fold

I write a blog that describe the fold of vim. So I need the code like this.

+-- 15 lines: set_up_socket_dir () {--------------------------------------------

But when I yank the line, actually yank the folded code. how can i get that line from vim.

like image 792
lifeng.luck Avatar asked Dec 26 '22 08:12

lifeng.luck


2 Answers

there is a vim function you may want to check out:

:h foldclosed(

you could write a :g command line with this function:

:g/^/if line('.')==foldclosed('.') || foldclosed('.')==-1|y Z |endif

So your workflow would be:

qzq to clear register z

...visual select lines...

'<,'>g/^/if line('.')==foldclosed('.') || foldclosed('.')==-1|y Z |endif

"zp do paste

you could create a mapping or command if you use it often.

it works like:

enter image description here

like image 86
Kent Avatar answered Jan 21 '23 08:01

Kent


To render the buffer / a range as you see it in Vim (including syntax highlighting and folding), you can use the built-in :TOhtml command. This gets you HTML. For the entire window layout, there's the ScreenShot plugin.

If you just want the plain text, I would launch console Vim, select the entire contents with the mouse, and use your terminal's copy functionality to copy the selection to the system's clipboard. (I believe you can also do this with screen or tmux.)

like image 22
Ingo Karkat Avatar answered Jan 21 '23 07:01

Ingo Karkat