-1

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!

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

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 acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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