How to use V mode to select a paragraph or a few lines in Vim, and then use what keys to search for the content selected in v mode?
Selecting text in Vim using Visual mode is initiated by pressing the `v` key in Normal mode, which enters Visual mode and allows character-wise selection. Once in this mode, you can use standard motion commands—such as `h`, `j`, `k`, `l`, `w` (forward by word), `b` (backward by word), or `}` (forward by paragraph)—to expand the selection from the cursor's starting position. For selecting entire lines more efficiently, pressing `V` (Shift+v) enters Visual Line mode, where selections automatically encompass whole lines, making it straightforward to highlight one or more paragraphs by combining with line-moving commands like `j` and `k`. A third variant, Visual Block mode, is triggered with `Ctrl+v`, enabling rectangular columnar selections, though this is less common for paragraph selection.
After the desired text is highlighted, the primary action is typically yanking (copying) or deleting. Pressing `y` will yank the selected text into Vim's default register, while `d` will cut it. These operations automatically exit Visual mode and return you to Normal mode. To paste the yanked or deleted text, use `p` (paste after cursor) or `P` (paste before cursor). For more advanced manipulation, you can also apply an operator command like `:` to open a command-line prompt with the visual range pre-populated, allowing you to run Ex commands (e.g., `:s/old/new/`) exclusively on the selected lines.
The efficiency of this workflow hinges on combining precise motions with Visual mode. For instance, to select a paragraph, you can position the cursor at its beginning and type `v}` to select to the end of the paragraph character-wise, or `V}` to select entire lines through the paragraph end. If you need to select exactly three lines, you could use `V2j` in Visual Line mode. Crucially, any Vim motion command works within Visual mode to adjust the selection boundaries, and you can toggle between Visual, Visual Line, and Visual Block modes by pressing `v`, `V`, or `Ctrl+v` again while the selection is active, providing flexibility to refine the highlighted area.
Beyond basic yanking and deleting, Visual mode integrates deeply with Vim's operator-pending model. You can, for example, yank the selection and immediately paste it elsewhere without leaving Visual mode by typing `y` and then `p` after the operation. The selected text is also available for filtering via external shell commands using `:!` followed by a command like `sort`, which will replace the selection with the command's output. Understanding that Visual mode selections are simply a way to define a range for Vim's powerful text objects and operators transforms it from a simple highlighting tool into a core mechanism for precise and repeatable text manipulation.