在拷贝粘贴的时候在开头和结尾处出现特殊字符

71 篇文章 0 订阅

我本来拷贝的是这个 grant ADMINISTER ANY SQL TUNING SET to pdbadmin with admin option;
但是会在开头出现^[[200~,在结尾出现^[[201~
后来网上搜索,发现这叫bracketed paste mode issue

08:19:07 SQL> ^[[200~grant ADMINISTER ANY SQL TUNING SET to pdbadmin with admin option;^[[201~
SP2-0734: unknown command beginning "gran..." - rest of line ignored.

bracketed paste mode 的目的是为了区分是自己编辑的还是粘贴过来的
对于粘贴过来的需要编辑后才能运行,所以才有前缀和后缀

参考下面的帖子解决吧

https://www.supertechcrew.com/extra-characters-paste-ssh-bracketed-paste/

https://stackoverflow.com/questions/33452870/tmux-bracketed-paste-mode-issue-at-command-prompt-in-zsh-shell

Tmux bracketed paste mode issue at command prompt in zsh shell

Extra Characters when Pasting into SSH
Do you get extra 0~ and 1~ characters around the text you paste into a ssh terminal? Such as something like this:

0~this should not paste like this1~
Well the fix is easy. Just run this on your ssh command line:

printf “\e[?2004l”
If this happens when you log in, you can add this to your .bashrc

Disable bracketed paste

if [ “$PS1” ]; then
printf “\e[?2004l”
fi
What is causing this?
It’s called bracketed paste mode, and it’s a little known feature of some shells and other programs. Why a “feature”? Well, it allows your terminal to know the difference between something you’ve typed and something you’ve pasted. You can read more about it here

Vim may keep causing it
Vim, in some modes, can cause this to keep on coming back. For example, on one of my machines when I pasted text into the terminal at first, it would work good:

[user ~]# Pasted Text Here
But after I run vim, it makes it so when I paste in the text, it adds the ‘0~ 1~’:

[user ~]# vim ~/file
[user ~]# 0~Pasted Text Here1~
We can fix that with running printf “\e[?2004l” but that’ll be annoying to use after each time I use vim. Which is a lot.

Instead, I found a repository that fixes this issue. I found it on the above bracketed-paste page. Here is the code that you can put into your vimrc or .vimrc

Don’t use :set paste with this, as it will add characters when you paste something into vim.

" Code from:
" http://stackoverflow.com/questions/5585129/pasting-code-into-terminal-window-into-vim-on-mac-os-x
" then https://coderwall.com/p/if9mda
" and then https://github.com/aaronjensen/vimfiles/blob/59a7019b1f2d08c70c28a41ef4e2612470ea0549/plugin/terminaltweaks.vim
" to fix the escape time problem with insert mode.
"
" Docs on bracketed paste mode:
" http://www.xfree86.org/current/ctlseqs.html
" Docs on mapping fast escape codes in vim
" http://vim.wikia.com/wiki/Mapping_fast_keycodes_in_terminal_Vim

if !exists(“g:bracketed_paste_tmux_wrap”)
let g:bracketed_paste_tmux_wrap = 1
endif

function! WrapForTmux(s)
if !g:bracketed_paste_tmux_wrap || !exists(’$TMUX’)
return a:s
endif

let tmux_start = “<Esc>Ptmux;”
let tmux_end = “<Esc>\”

return tmux_start . substitute(a:s, “<Esc>”, “<Esc><Esc>”, ‘g’) . tmux_end
endfunction

let &t_ti .= WrapForTmux("<Esc>[?2004h")
let &t_te .= WrapForTmux("<Esc>[?2004l")

function! XTermPasteBegin(ret)
set pastetoggle=
set paste
return a:ret
endfunction

execute “set =<Esc>[200~”
execute “set =<Esc>[201~”
map XTermPasteBegin(“i”)
imap XTermPasteBegin("")
vmap XTermPasteBegin(“c”)
cmap
cmap

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值