首页 > 解决方案 > ZSH 一直在我粘贴的 URLS 中添加反斜杠

问题描述

我已经尝试过如何使用 URL 和反斜杠禁用 zsh 替换/自动完成的解决方案,但这不再有效。

如果我粘贴一个 URL,它会一直加上反斜杠。很烦人。

例如:

https://www.google.com?test=sample1&test2=sample3

会变成:

curl -X POST "https://www.google.com\?test\=sample1\&test2\=sample3"

~/.zshrc这是我文件的顶部:

# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH

# Path to your oh-my-zsh installation.
DISABLE_MAGIC_FUNCTIONS=true
export ZSH=/Users/myuser/.oh-my-zsh

我已经尝试重新调用源,没有运气。我能够解决这个问题的唯一方法是打开一个 bash shell,这可能非常不方便。

标签: zsh

解决方案


搜索后这对我有用

  1. 打开文件~/.oh-my-zsh/lib/misc.zsh
  2. 在下面评论这些行
if [[ $ZSH_VERSION != 5.1.1 ]]; then
  for d in $fpath; do
    if [[ -e "$d/url-quote-magic" ]]; then
      if is-at-least 5.1; then
        autoload -Uz bracketed-paste-magic
        zle -N bracketed-paste bracketed-paste-magic
      fi
      autoload -Uz url-quote-magic
      zle -N self-insert url-quote-magic
      break
    fi
  done
fi

最终结果是

autoload -Uz is-at-least

# *-magic is known buggy in some versions; disable if so
# if [[ $DISABLE_MAGIC_FUNCTIONS != true ]]; then
#   for d in $fpath; do
#     if [[ -e "$d/url-quote-magic" ]]; then
#       if is-at-least 5.1; then
#         autoload -Uz bracketed-paste-magic
#         zle -N bracketed-paste bracketed-paste-magic
#       fi
#       autoload -Uz url-quote-magic
#       zle -N self-insert url-quote-magic
#     break
#     fi
#   done
# fi

## jobs
setopt long_list_jobs

env_default 'PAGER' 'less'
env_default 'LESS' '-R'

## super user alias
alias _='sudo '

## more intelligent acking for ubuntu users
if (( $+commands[ack-grep] )); then
  alias afind='ack-grep -il'
else
  alias afind='ack -il'
fi

# recognize comments
setopt interactivecomments

相对链接

https://github.com/ohmyzsh/ohmyzsh/issues/5499

如何使用 URL 和反斜杠禁用 zsh 替换/自动完成


推荐阅读