Sign up to join this community. The best answers are voted up and rise to the top. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Learn more. Ask Question. Asked 5 years, 9 months ago. Active 5 years, 9 months ago. Viewed 12k times. Improve this question. Bruno Polaco Bruno Polaco 1 1 gold badge 2 2 silver badges 6 6 bronze badges. If you're interested in using Vim better, do checkout sister site Vi and Vim.
Add a comment. Active Oldest Votes. Community Bot 1 1 1 silver badge. Gang Gang 2, 3 3 gold badges 14 14 silver badges 36 36 bronze badges. Add a comment. Active Oldest Votes. Improve this answer. This is much neater imho. Really useful but does not create file if you need — zahir. Instead of using :wa, you can also use :wqa to write everything and quit immediately. Gaut Gaut 1, 1 1 gold badge 14 14 silver badges 32 32 bronze badges.
I love both solutions, they has different edges in different scenarios. DavisDude DavisDude 9 9 silver badges 22 22 bronze badges. Sign up or log in Sign up using Google. Sign up using Facebook.
The first command clears register a :help q. The second appends all matching lines to that register :help quotea. The above procedure captures only the first line of each match. See below for copying multiline matches. It is also easy to delete lines containing single-line matches. The first of the following commands deletes all lines containing pattern , while the second deletes all lines matching the last search:.
If a search pattern may find multiline matches, the above procedures to delete matching lines fail. In that case, use the following which works with any kind of match. The simple script shown here copies only the text that matches search hits.
It works with multiline matches. After sourcing the following, search for a pattern, then enter :CopyMatches to copy all matches to the clipboard, or :CopyMatches x where x is any register to hold the result. The above code works after any search, including searches which match text in more than one line.
The expression used in the substitute replacement uses len as a trick to call add which returns the list after appending a match to it. The script in this section provides more features. It works with multiline matches, and provides a CopyMatches command to copy only matching text, as well as a CopyLines command to copy all lines that contain a match. Each command accepts a range of lines, and can copy into any register by default, the clipboard.
The first of the following commands copies all text matching the last search into the clipboard, while the second copies all matches in lines 1 to 10 inclusive to register a , and the third copies matches from the current line.
Matches can be copied into a scratch buffer instead of a register. To do that, use - as the register name.
0コメント