[vim] How to select all and copy in vim?

how to select all and copy in vim insert mode? and is there another way to do it in normal mode?

I have tried visual mode and gg and shift + gg to select all and then yank, however that doesn't transfer it to the clipboard to be able to paste it in another application like skype or chrome browser.

I am sure this is a common task, and there are a lot of varieties by smarter ppl than me out there, please feel free to share yours.

This question is related to vim

The answer is


ggVG 

will select from beginning to end


In normal mode:

gg"+yG

In ex mode:

:%y+


@swpd's answer improved

I use , as a leader key and ,a shortcut does the trick

Add this line if you prefer ,a shortcut

map <Leader>a :%y+<CR> 

I use Ctrl y shortcut to copy

vmap <C-y> y:call system("xclip -i -selection clipboard", getreg("\""))<CR>:call system("xclip -i", getreg("\""))<CR>

And ,v to paste

nmap <Leader>v :call setreg("\"",system("xclip -o -selection clipboard"))<CR>p

Before using this you have to install xclip

$ sudo apt-get install xclip

Edit: When you use :%y+, it can be only pasted to Vim vim Ctrl+Insert shortcut. And

map <C-a> :%y+<Esc>

is not conflicting any settings in my Vimrc.