vim how to search for URL

后端 未结 5 865
借酒劲吻你
借酒劲吻你 2021-01-12 15:12

How would you search for the following string in vim?

http://my.url.com/a/b/c

I\'ve tried (a la Very No Magic)

:/\\Vhttp://         


        
相关标签:
5条回答
  • 2021-01-12 15:34

    Can also set the search register directly.

    :let @/='\Vhttp://my.url.com/a/b/c'
    

    Then you can use n and N like normal.

    0 讨论(0)
  • 2021-01-12 15:35

    Use MacVim (or GVim). Open the non-regex GUI search using f (or ctrlf on Windows). This is the recommended way to do a non-regex search in Vim. GUI Vim has many improvements over terminal vim like this one and I would highly suggest using it full time if you aren't already.

    0 讨论(0)
  • 2021-01-12 15:40

    another way to search forward (from the position of your cursor) without escaping is use :s command.

    you could do:

    :%s@http://my.url.com/a/b/c@@n
    

    then press n to navigate matched text forward, N backwards

    If you want to know how many matches in the buffer, use gn instead of n

    note that, I said "without escaping", I was talking about the slash, if you want to do search precisely, you have to escape the period. .. since in regex, . means any char.

    0 讨论(0)
  • 2021-01-12 15:44

    Searching in vim is just /, not :/. You can search for that string escaping only the slashes: /http:\/\/my.url.com\/a\/b\/c

    0 讨论(0)
  • 2021-01-12 15:48

    I'm not sure why you get not an editor command since I don't. The simplest way to search without having to escape slashes is to use ? instead, e.g.

    :?http://my.url.com/a/b/c
    " or since the : is not necessary
    ?http://my.url.com/a/b/c
    

    This does search in the other direction, so just keep that in mind

    0 讨论(0)
提交回复
热议问题