سؤال

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.

هل كانت مفيدة؟

المحلول 2

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

نصائح أخرى

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

IIUC, you want to copy the closed fold text heading . You can do this with modeless selection (see :help modeless-selection). Mark the text with Ctrl+Shift depressed.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top