0

i want to write a makro and need to know how i can move to the end and to the beginning of a string, respektively i want to visually select the link so that i can surround it with brackets.

my line in vim looks like this

- test test http://www.test.tets/

the cursor is positioned somewhere in the link. this case is somehow special, because the link ends on the end of the line. i need a general solution, which also runs, when the link is in the middle of a line:

- test http://test.test   tset and so on

i want to visually select the link and than surround it with brackets. this is for a markdown file.

i already tried to use the word movements, but they do not work in links.

thx in advance!

2
  • 1
    Read :help word-motions. Also interesting: :help text-objects. And have a look at the plugin vim-surround.
    – Ralf
    Jan 11, 2019 at 8:55
  • With @Ralf ‘s suggestion, you could easily do ysiW"
    – D. Ben Knoble
    Jan 11, 2019 at 15:19

1 Answer 1

1

You should probably begin with reading the help topics suggested by @Ralf along with :h word and :h WORD. This should lead you to :h E and :h B.

So without any plugin you macro could use the following commands

Ea"<Esc>Bi"<Esc>

which means:

E                  Go to the end of the WORD (i.e. http://www.test.tets/)
 a"                Append a double quote after the word
   <Esc>           Go back to normal mode
        B          Move to the beginning of the WORD
         i"        Insert a double quote before the WORD
           <Esc>   Go back to normal mode again and continue your macro

Also as suggested in the comments Tim Pope's vim-surround is a very good plugin which allows you to use built-in text objects and visual selection to surround some text with different characters.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.