Copy all the lines to clipboard

2019-01-07 01:13发布

Is there any way to copy all lines from open file to clipboard in VI editor. I tried yG but it's not using clipboard to store those lines.

So is it possible?

标签: vim editor vi
22条回答
姐就是有狂的资本
2楼-- · 2019-01-07 01:31

This is what I do to yank the whole file:

ggVGy
查看更多
爷、活的狠高调
3楼-- · 2019-01-07 01:31

If your fingers default to CTRL-A CTRL-C, then try the mappings from $VIMRUNTIME/mswin.vim.

" CTRL-C and CTRL-Insert are Copy
vnoremap <C-C> "+y

" CTRL-A is Select all
noremap <C-A> gggH<C-O>G
inoremap <C-A> <C-O>gg<C-O>gH<C-O>G
cnoremap <C-A> <C-C>gggH<C-O>G
onoremap <C-A> <C-C>gggH<C-O>G
snoremap <C-A> <C-C>gggH<C-O>G
xnoremap <C-A> <C-C>ggVG

I have them mapped to <Leader><C-a> and <Leader><C-c>.

查看更多
你好瞎i
4楼-- · 2019-01-07 01:32

The clipboard is buffer +. To copy to clipboard, do "+y and [movement].

So, gg"+yG will copy the whole file.

Similarly, to paste from clipboard, "+p

查看更多
smile是对你的礼貌
5楼-- · 2019-01-07 01:35

on Mac

  • copy selected part: visually select text(type v or V in normal mode) and type :w !pbcopy

  • copy the whole file :%w !pbcopy

  • past from the clipboard :r !pbpaste

查看更多
爷的心禁止访问
6楼-- · 2019-01-07 01:35

Another easy way to copy the entire file if you're having problems using VI, is just by typing "cat filename". It will echo the file to screen and then you can just scroll up and down and copy/paste.

查看更多
【Aperson】
7楼-- · 2019-01-07 01:35

Well, all of these approaches are interesting, however as lazy programmer I use yank all line by using combination of number + y

for example you have source code file with total of 78 lines, you can do as below:

  1. gg to get cursor at first line
  2. insert 78 + y --> it yanks 78 lines below your cursor and current line
查看更多
登录 后发表回答