How can I select part of a line in Vim
Pergunta
I have a line of text that looks like this
foo bar http://www.example.com -> baz
I want yank the url part using ex. Anyone have any ideas on how to do this?
To clarify. I want to do something like this :y/http:.*\.com/
from the command line. But that doesn't work.
Solução
While on the beginning of a line,
wwviWy
will yank the URL part while not changing the cursor position.
If you want to do it as a command
:execute "normal! wwviWy0"
does the same thing.
Outras dicas
The URL fits the definition of a WORD, so you can do it with yW
when the cursor is at the beginning.
I would use /http
to get at the begining of the URL if I were on a different line, or fh if I were on the same line and then yt (last key is space).
normal /http^v^m^v^mv2fm <Enter>
Where ^v = Ctrl + v and ^m = Enter
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow