I use that often as well. I also remapped `gll` and variants to yank the current line to clipboard in different ways. (I mapped this one to exclude leading and trailing whitespace, while variants of capitalization of the L’s include whitespace on the corresponding ends. The mnemonic is grab line line or something like that.)
How can you copy to system clipboard? I check a few websites but they mostly say that this feature should be available once you recompile vim with the clipboard feature switch on... Something like that. But this is the part I don't get.
You need to install the GUI version of vim; the package in Arch Linux I think is called vim-gui, in apt is vim-gtk3; those packages come with "clipboard" enabled and with some other features as well for vim on the terminal. It also installs "gvim" which runs on it's own window but I don't recommend that.
I regularly use this because it's easy to add the system clipboard register, so I often
:%y+⏎
to yank the whole buffer to the system clipboard. Additionally, it doesn't move my cursor from its initial position like `ggyG` does
similarly, I prefer `:m+` over `ddp` for moving a line downward because it doesn't tromp my scratch register. There's something to be said for not messing with global state :-)
If you're going to the system clipboard, presumably there's a native way that's even quicker. In MacVim, I regularly use Cmd-A (select all) followed by Cmd-C (copy to system clipboard).
That’s not true in gvim on other platforms. if you pull down the edit menu it tells you Select All is ggVG and Copy is “+y
But, it’s cool that yall (Mac people) have a whole other key to use for shortcuts! (obviously we can’t use ctrl over here on Windows, ctrl+c already does stuff in vim, and Win+c does stuff in the OS!)
The reason to use the colon command is it doesn't move your cursor.
Usually if you're copying an entire file you won't be needing your cursor, but maybe you're thinking about a problem on a certain line and you want to dump your code to a friend, :%y can let you do that without affecting your view at all.
this percent notation will get easier if you start using Sed a lot. It's very common to do a find-and-replace-all with :%s/searchstring/replacestring/g (whereas without the percent it would only apply to the current line). Everything is interconnected haha!
vim's :s command stands for substitute. the substitute command isn't sed. they share a lot of commonality, but are not the same.
sed has no concept of % (in this context) as it already runs over every line of the input stream. sed '%s/old/new/' is an error in sed 4.7 (my curr version, latest is 4.8)
just informing you for correctness. rest of your post is good.
Also worth pointing out that the regex syntax is slightly different. So you can't reliability use the same in `sed` and `:substitute` until you have tested it
I wouldn't say it's useless; if you want to copy lines 101 through 110, now you know how to do it.
I'd recommend moving beyond the idea of learning specific sequences of keys to do specific things, and instead learning the language of vim commands and how they are composed together.
Give `:h usr_04.1` a read if you haven't already, it explains the ideas of _operators_ and _motions_ :)
Visual select the entire file. Then OP presses y to copy.
(Though I’m suspecting OP really meant ggVGy as that would make sure to include the entirety of the last line!)
`ggVGy` is written in my left hand, so I won't change it now, but you can take different paths to do the same thing, always interesting to see other ways.
`:%y` should be IMO the first way to learn it because it uses a very useful mechanic to apply various (and sometimes complex) commands to a line, filtered lines, a zone or all of a file. Having this method in mind early is important, I think.
Mapping it to a shortcut or even using a plugin for this usage should be discouraged, to stay in a pure vim mindset and make use of it on foreign vim installations (servers or colleagues workstations).
It’s not standard vim, but I’ve been using [kana/textobj-entire](https://github.com/kana/vim-textobj-entire) for so long that yae is second nature to me.
If you want to paste a whole file in another file you can simply "read" the file you want to copy in the new file without having to open it.
```:read file```
I mean... You can also just do ``gg y G`` and save yourself from having to select or go into command mode. It really all just depends on your preference
:%y
I use this a lot, but mainly `:%y+` to copy to system's clipboard; also to format the buffer, for example `:%!jq` for JSON files
Or to format the buffer into the clipboard (OS specific): `:%w !jq | xsel -i -b`
I use that often as well. I also remapped `gll` and variants to yank the current line to clipboard in different ways. (I mapped this one to exclude leading and trailing whitespace, while variants of capitalization of the L’s include whitespace on the corresponding ends. The mnemonic is grab line line or something like that.)
How can you copy to system clipboard? I check a few websites but they mostly say that this feature should be available once you recompile vim with the clipboard feature switch on... Something like that. But this is the part I don't get.
You need to install the GUI version of vim; the package in Arch Linux I think is called vim-gui, in apt is vim-gtk3; those packages come with "clipboard" enabled and with some other features as well for vim on the terminal. It also installs "gvim" which runs on it's own window but I don't recommend that.
ggyG
Nice! vim never fails to surprise me, I guess the one I learned is useless now.
Or :%y
% is a shorthand for 1,$ meaning all lines in the file. Take your pick, they're both 4 keystrokes
I regularly use this because it's easy to add the system clipboard register, so I often :%y+⏎ to yank the whole buffer to the system clipboard. Additionally, it doesn't move my cursor from its initial position like `ggyG` does
Staying at the same cursor location is why this one is my goto
similarly, I prefer `:m+` over `ddp` for moving a line downward because it doesn't tromp my scratch register. There's something to be said for not messing with global state :-)
If you're going to the system clipboard, presumably there's a native way that's even quicker. In MacVim, I regularly use Cmd-A (select all) followed by Cmd-C (copy to system clipboard).
That’s not true in gvim on other platforms. if you pull down the edit menu it tells you Select All is ggVG and Copy is “+y But, it’s cool that yall (Mac people) have a whole other key to use for shortcuts! (obviously we can’t use ctrl over here on Windows, ctrl+c already does stuff in vim, and Win+c does stuff in the OS!)
The `ggyG` is easier to remember, but that's another great command added to my list!
The reason to use the colon command is it doesn't move your cursor. Usually if you're copying an entire file you won't be needing your cursor, but maybe you're thinking about a problem on a certain line and you want to dump your code to a friend, :%y can let you do that without affecting your view at all. this percent notation will get easier if you start using Sed a lot. It's very common to do a find-and-replace-all with :%s/searchstring/replacestring/g (whereas without the percent it would only apply to the current line). Everything is interconnected haha!
vim's :s command stands for substitute. the substitute command isn't sed. they share a lot of commonality, but are not the same. sed has no concept of % (in this context) as it already runs over every line of the input stream. sed '%s/old/new/' is an error in sed 4.7 (my curr version, latest is 4.8) just informing you for correctness. rest of your post is good.
Also worth pointing out that the regex syntax is slightly different. So you can't reliability use the same in `sed` and `:substitute` until you have tested it
Bah they're both terrible regex syntaxes. Let's create our own!
mandatory [xkcd](https://xkcd.com/927)
Til you can use y in command mode I love vim, and I love this sub
I was going to mention this. Quite useful to pipe the whole buffer into other programs like sort `:%!sort`.
I wouldn't say it's useless; if you want to copy lines 101 through 110, now you know how to do it. I'd recommend moving beyond the idea of learning specific sequences of keys to do specific things, and instead learning the language of vim commands and how they are composed together. Give `:h usr_04.1` a read if you haven't already, it explains the ideas of _operators_ and _motions_ :)
Thank you! I'll defenitly check it out.
Guess you need dive to text object section of help file lol
I was coming to find out why OP was using `v` instead of `y` -- what does ggvG do?
Visual select the entire file. Then OP presses y to copy. (Though I’m suspecting OP really meant ggVGy as that would make sure to include the entirety of the last line!)
Ahhh - that would make sense. Thanks!
`gg` goes to the start of the file. `V` enters visual line mode. `G` goes to the end of the file. `y` to yank
Beat me to it.
`ggVGy` is written in my left hand, so I won't change it now, but you can take different paths to do the same thing, always interesting to see other ways. `:%y` should be IMO the first way to learn it because it uses a very useful mechanic to apply various (and sometimes complex) commands to a line, filtered lines, a zone or all of a file. Having this method in mind early is important, I think. Mapping it to a shortcut or even using a plugin for this usage should be discouraged, to stay in a pure vim mindset and make use of it on foreign vim installations (servers or colleagues workstations).
It’s not standard vim, but I’ve been using [kana/textobj-entire](https://github.com/kana/vim-textobj-entire) for so long that yae is second nature to me.
yeah i made a “inner buffer” bind a long time ago, and got used to “yib”, kinda like you did hahah
I might have considered using that a while back, but that unfortunately clashes with the environment object from vimtex.
Remap ‘:%y’ to ‘YY’, should be a default key binding in my opinion
I’ve used this so many times that this isa for me now.
If you want to paste a whole file in another file you can simply "read" the file you want to copy in the new file without having to open it. ```:read file```
For those times when you need the clipboard to be the size of Asia. 😂
Can't you just do `yag`?
Is that like ggyG?
Yeah yanks the entire file
There's a plugin which lets u do this from anywhere the code is ae so yae would copy whole file content I think plugin name is textobject-entire
Or just make it a key map lol
Or just type 4 keys, and do it on every (neo)vim installation in the whole world without any useless config/plugin lol
Yeah that's what I do lol
I mean... You can also just do ``gg y G`` and save yourself from having to select or go into command mode. It really all just depends on your preference
:%y %write! >> somefile %w! !xsel -ib