How do I select all the content of a file in Vim and VsVim? Like in other editors Ctrl-A does the job for select all.

  • 3
    SibiCoder's answer is good, but it would be useful to know what you intend to do with the content you copied.
    – Law29
    Commented Jul 31, 2016 at 8:22
  • 6
    First, you "select" some text in a "buffer", not in a "file". Two, "selecting" is often useless in Vim so you must be clear about what you want to do with that "selection". For you and for us.
    – romainl
    Commented Jul 31, 2016 at 9:33
  • 3
    @romainly I think the OP means selecting the whole file in visual mode, considering that ctrl+a in other editors visually highlights the entire file. Commented Jul 31, 2016 at 13:14
  • @statox Why did you edit vsvim out? It's not a huge deal to me, but I think the tag is perfectly appropriate, and I didn't want to get in an edit war. (I would have pinged you in :chat!, but you haven't been in that room recently, so it wouldn't let me)
    – DJMcMayhem
    Commented Aug 1, 2016 at 23:28
  • @DJMcMayhem: It was an error: I first thought that vsvim was like vimperator and this kind of plugins for other softwares and thus was off topic so I removed it, then I had a doubt so I checked meta and saw that it was on topic so I approved your tag edit but forgot to edit the question again. I'm changing that right now, sorry for that.
    – statox
    Commented Aug 2, 2016 at 7:35

9 Answers 9


ggVG selects all content. gg moves to first line. V starts visual mode. G jumps to last line thereby selecting from first to last line

  • 1
    I keep getting no a vim command for ggVG and gg, even G Commented Oct 7, 2020 at 16:09
  • 2
    Both mine and yours are correct. Visual mode works both ways
    – SibiCoder
    Commented Mar 21, 2021 at 15:00
  • It may be unnecessary to capitalize the 'V' here, since the "whole line" part seems moot because the two boundaries are at the very beginning and the very end of the file. Commented Apr 16, 2023 at 16:21

Along with SibiCoder's answer, if you have a clear idea of what you want to do you can use the following:


Where X is a command, for example:

:%d             -> delete every line
:%y             -> yank every line
:%normal! >>    -> indent every line

You have also the global command :g which, with the search pattern ^, can do the same thing:

:g/^/d             -> delete every line
:g/^/y             -> yank every line
:g/^/normal! >>    -> indent every line

If what you want is selecting the text, then ggVG is fine, but keep in mind these method, in the case you already know what is the next step. Note that it won't leave the cursor in visual mode.

See: :h :% and :h :g for reference.

Note that, even though the C-A mapping is used in vim (see :h CTRL-A), you can map it to do what other editors do:

nnoremap <C-A> ggVG

Just be aware that mapping C-A could clash with other plugins' mappings or with screen's default prefix.

  • Note that :> is an Ex command, so :%> works
    – D. Ben Knoble
    Commented May 3, 2022 at 13:57

The other answers are good. Here's another alternative.

Since you mention that you are using VsVim, you can change which keys are handled by visual Studio, and which keys are handled by vsvim. Go to

Tools -> Options -> VsVim -> Keyboard

From there you can set Ctrl-a to be handled by Visual Studio, rather than VsVim.

Although I do not recommend this since you will not be able to use vim's <C-a>, which I find to be an essential feature. Though it's up to you.


As @SibiCoder mentioned ggVG does the trick, but I like something closer to Ctrl+A.

So I added this line to my .vimrc

nnoremap <leader>a ggVG

Now pressing <leader>a will select everything, in my case it's \a.


If you'd like a faster/more intuitive way to do this and don't mind adding a plugin, this looks handy: https://github.com/kana/vim-textobj-entire


I used to use map <leader>a ggVG to select all, but later I found that Cmd+V/Ctrl+V pasting has an extra new line. So nowadays, I use:

map <leader>a G$vgg0

Which works without side effects.

  • +1 for pointing out the carriage return issue with the Visual Line mode. Also, your your suggested mapping could be just <Leader>a ggv$G$
    – ranemirusG
    Commented Feb 11 at 19:15
  • @ranemirusG Thanks for the suggestion, edited.
    – Wenfang Du
    Commented Feb 18 at 9:42

you can use a big number like 99999yy to select all the content of your file

  • 5
    Files larger than 100000 lines are possible, though rare. Also, using yy will yank them, not select them.
    – DJMcMayhem
    Commented Aug 3, 2016 at 6:43
  • 1
    yah sure you are right but when selecting something it's for the most cases to cut,copy or delete them :)
    – Adel Kihal
    Commented Aug 4, 2016 at 8:51
  • That's what i needed. Select all and yank.
    – Ivan
    Commented Jan 31, 2020 at 15:57
  • 3
    Just :%y is enough. Or :%y + to yank everything in the + register. Commented Nov 20, 2020 at 14:09

:1 puts your cursor at the beginning of the 1st line. Then VG selects everything.

Then you do whatever you want with the selection: yank, delect, copy, ...


Go to Edit-->SelectAll from toolbar

  • 1
    Works in GUI mode. You will notice that behind "SelectAll" it says ggVG. Many experienced vi users will find it cumbersome to take their hands of their keyboards ;)
    – Friedrich
    Commented Jan 24, 2023 at 16:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.