Wiki

by yszheda

View project onGitHub

Tip 78: Escape Problem Characters

Return to the top: <<Practical Vim>>

Escape / Characters When Searching Forward

Example:

  • yank the URL into register u with the command "uyi[
  • /\V<C-r>u<CR> to populate the search field with the contents of that same register.
    /\Vhttp://vimdoc.net/search?q=/\\
    

Vim interpreted the first / character as a search field terminator.

Escape ? Characters When Searching Backward

Example:

?http://vimdoc.net/search?q=/\\

Escape \ Characters Every Time

Example:

/\Vhttp:\/\/vimdoc.net\/search?q=\/\\\\

Escape Characters Programmatically

escape({string}, {chars})

References:

# If you open the file in vim,
# then you can \"ayy@a the next line to execute the vim command: 
:h escape()

Example:

  • Store the URL in the u register:
  • Enter the \V literal switch and then type <C-r>=.
    =escape(@u, getcmdtype().'\')
    

References:

# If you open the file in vim,
# then you can \"ayy@a the next line to execute the vim command: 
:h getcmdtype()

Search Field Terminators

:promptfind command: entering a pattern without having to worry about search field terminators (works only in GVim)

References:

# If you open the file in vim,
# then you can \"ayy@a the next line to execute the vim command: 
:h :promptfind