bracketed paste mode:命令行终端粘贴文本,开头出现^[[200~,结尾出现~

现象:

08:19:07 SQL> ^[[200 粘贴文本 ~

在命令行终端粘贴文本,首尾会自动添加其它特殊字符。

原因:

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

解决方案:

1、命令行:输出 printf '\e[?2004l'  ;回车即可关闭 bracketed paste mode。

2、vim 编辑器关闭 bracketed paste mode,需要编辑 .vimrc 文件,添加如下配置:

" 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

注意:不要使用 :set paste 粘贴上面文本

以下是一个简单的 Matlab 代码示例,使用二分法求解函数 $f(x)$ 的根: ```matlab function [root, fx, ea, iter] = bisection(f, xl, xu, es, maxit) % Bisection method for root finding % Input: % - f: the function handle to the function to be solved % - xl, xu: the lower and upper bounds of the interval containing the root % - es: the desired relative error (default: 0.0001%) % - maxit: the maximum number of iterations (default: 50) % Output: % - root: the estimated root of f(x) % - fx: the function value at the root % - ea: the approximate relative error (%) % - iter: the number of iterations performed if nargin < 4 || isempty(es), es = 0.0001; end if nargin < 5 || isempty(maxit), maxit = 50; end % check if the root is bracketed if f(xl) * f(xu) > 0 error('The root is not bracketed!'); end % initialize variables iter = 0; xr = xl; ea = 100; % main loop while ea > es && iter < maxit xrold = xr; xr = (xl + xu) / 2; iter = iter + 1; if xr ~= 0 ea = abs((xr - xrold) / xr) * 100; end test = f(xl) * f(xr); if test < 0 xu = xr; elseif test > 0 xl = xr; else ea = 0; end end % output results root = xr; fx = f(xr); end ``` 使用示例: ```matlab % define the function to be solved f = @(x) x^2 - 2; % call the bisection function [root, fx, ea, iter] = bisection(f, 0, 2, 0.0001, 50); % display results fprintf('Root: %f\n', root); fprintf('Function value: %f\n', fx); fprintf('Approximate relative error: %f%%\n', ea); fprintf('Number of iterations: %d\n', iter); ``` 其中,`f` 是要求解根的函数句柄,`xl` 和 `xu` 是根所在的区间的下限和上限,`es` 是期望的相对误差,`maxit` 是最大迭代次数。函数返回根 `root`、函数值 `fx`、近似相对误差 `ea` 和迭代次数 `iter`。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

戴国进

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值