I want to copy the parameters foo(bar).baz
in the following code:
function(foo(bar).baz)
First attempt: Cursor on one of the parentheses, then y%
. This gives me the parameters plus a bit extra:
(foo(bar).baz)
Second attempt: Cursor on opening parenthesis. Set a mark ma
, jump to end with
%
then y`a
to copy back to the mark. This gives me:
(foo(bar).baz
Setting a mark at the end and going the other way gives me exactly the same. Setting a
mark on the f
, then typing mah%y`a
does give me the foo(bar).baz
that I want, but maybe there's something more concise. Is there?
In this mode, you can run Vim commands and navigate through the file. To go back to normal mode from any other mode, just press the Esc key. Vim has its own terminology for copying, cutting, and pasting. Copy is called yank ( y ), cut is called delete ( d ), and paste is called put ( p ).
lh-brackets simply binds ( to surround the selection with the brackets. Unlike surround it doesn't follow the vim usual keybinding philosophy as does. Instead less keys are required.
Use text objects:
yi( (or ya( if you want to include the parenthesis).
You can also use "
to work inside quotes, etc. See the link for details, or type :help text-objects
in Vim.
A slightly shorter alternative to yi( is yib. Similarly yiB is equivalent to yi{ - yanks the contents inside braces.
Personally I usually do vib (visual select the text inside braces) first to make sure that the expected text is selected, followed by a y.
For more text object goodness, see :help text-objects
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With