4

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.

lifeng.luck
  • 601
  • 3
  • 10

3 Answers3

5

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

Kent
  • 189,393
  • 32
  • 233
  • 301
3

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

Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324
3

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.

Thor
  • 45,082
  • 11
  • 119
  • 130
  • Have been looking for this, did know how to mark but not how to copy it, (when GUI). It's not easy to know what to do `:help` on. – 244an Feb 27 '13 at 20:15
  • @244an: On Unix systems (including OSX) marking _is_ copying, not sure if it works on Windows though. – Thor Feb 28 '13 at 08:39
  • I know, but on Windows it's trickier, you have to enter command mode and do `` - if for some reason you don't copy it the usual way. – 244an Feb 28 '13 at 09:11
  • 1
    On Windows (or other systems, really) you can just do `:set guioptions+=A` to make it copy as you select with a modeless selection. – Ben Jan 06 '15 at 20:25