Learn Essential Vim Skills
with Drew Neil, author of Practical Vim
Copy and Paste
category applies to 9 screencasts and 3 articles:
Yanking and pasting works seemlessly between Neovim’s regular buffers and terminal buffers. In this video, we’ll look at how the Normal mode paste command works in a terminal buffer, and we’ll create a mapping to help with pasting text directly from Terminal mode.
Watch screencastThis video covers a couple of small but delightful Neovim features. You’ll see how to make Neovim show a live preview of how the substitute command will change our document. And you’ll find out how to make the yank operation highlight the range of text that it copied.
Watch screencastTo the newcomer, Vim’s way of doing things may seem strange, but with familiarity it becomes natural. Many of Vim’s features seemed odd to me at first, but when I got used to them I recognised that they had their own particular elegance. However, there’s one feature of Vim that still feels awkward to me: using registers for copy and paste. The deeper my understanding of registers becomes, the more they frustrate me!
Continue readingEpisodes 51, 52, 53, 54, 55, 58, and 59 are all on the topic of copy and paste in Vim. I think that this is one area where Vim is especially confusing, partly because of Vim’s non-standard jargon for cut, copy and paste operations. It’s not the most intuitive copy/paste system, but it’s usable when you get the hang of certain concepts and techniques.
Continue readingWhen Vim is compiled without the +clipboard
feature, we can still insert text from the clipboard using the system paste command (ctrl-v
or cmd-v
). This can produce strange effects, but we can avoid them by toggling the paste
option each time we use the system paste command.
Many systems ship with a version of Vim that was compiled with the -clipboard
feature disabled, which is a damned nuisance! Being able to access the system clipboard from Vim is an essential feature. Let’s look at a few ways of getting the +clipboard
feature on OS X and Ubuntu.
In some environments, Vim lets us access the system clipboard using the quoteplus register, "+
. When this feature is enabled, we can use it with the delete, yank and put operations in much the same way that we use Vim’s other registers. Pasting from this register usually produces better results than using the system paste command in Insert mode.
We don’t have to be in Normal mode to paste the contents of a register. The <C-r>{reg}
command lets us paste a register from Insert mode (and it works in commandline mode too!) Using this command allows us to make changes that can be repeated with the dot command.
When used in Visual mode the p
command replaces the selection with the contents of a register. This makes for a smooth workflow when you want to overwrite a selection, or swap the order of two regions of text.
We’ve met Vim’s default register and the yank register. This time, we’re going to look at the named registers, which are handy if you want to cut or copy some text that you intend to paste multiple times.
Watch screencastVim’s default register is not a safe place to keep yanked text that you want to paste later. It’s all too easy to clobber the default register with a d
or x
command. Luckily, the last yanked text is kept safe in Vim’s yank register.
Vim’s default register makes it easy to perform some of the most basic types of cut, copy, and paste operations. That’s partly thanks to the p
command, which behaves differently depending on whether the default register contains a characterwise or linewise region of text.