[20191031]完善vim的bccalc插件7.txt
[20191031]完善vim的bccalc插件7.txt
--//增加/ 2^16 %2^16功能,输入\tx,例子:
1398145029 = /2^16 %2^16 (type and mode) = 21334,5 = 0x53560005
0x53560005 = /2^16 %2^16 (type and mode) = 21334,5 = 1398145029
--//5356 =SV(对应asc码SV)
--//增加处理输入逗号过滤问题,这个有点麻烦的是有时候逗号是合法的。单独增加快捷使用\c,
--//而\bc的功能不动。
noremap <Leader>c, Yp!!sed "s/,//g" \|bc -lq\| tr -d '\n\\\r' \| sed -e "s/\.\([0-9]*[1-9]\)0\+$/.\1/" -e "s/\.0\+$//"<CR>kA = <ESC>J
12,345+1,000 = 13345 --//输入\c.
--//代码如下bccalc_win.vim:
"" calculate expression entered on command line and give answer, e.g.:
" :Calculate sin (3) + sin (4) ^ 2
command! -nargs=+ Calculate echo "<args> = " . Calculate ("<args>",0)
"" calculate expression from selection, pick a mapping, or use the Leader form
vnoremap ;bc "ey`>:call CalcLines(0)<CR>
vnoremap ;bb "ey`>:call CalcLines(0)<CR>
vnoremap ;10 "ey`>:call CalcLines(10)<CR>
vnoremap ;16 "ey`>:call CalcLines(16)<CR>
vnoremap ;tx "ey`>:call CalcLines(1616)<CR>
vnoremap ;22 "ey`>:call CalcLines(22)<CR>
vnoremap ;dba "ey`>:call CalcLines(22)<CR>
vnoremap ;32 "ey`>:call CalcLines(32)<CR>
vnoremap ;scn "ey`>:call CalcLines(32)<CR>
vnoremap ;ss "ey`>:call CalcLines(10016)<CR>
vnoremap ;rr "ey`>:call CalcLines(20016)<CR>
vnoremap ;hd "ey`>:call CalcLines(30016)<CR>
vnoremap ;hh "ey`>:call CalcLines(30016)<CR>
vnoremap ;dh "ey`>:call CalcLines(30016)<CR>
"" calculate expression on current line, pick a mapping, or use the Leader
nnoremap <Leader>bx <Esc>A <Esc>"eyy$:call CalcLines(0)<CR>
nnoremap <Leader>bc <Esc>A = <Esc>"eyy:call CalcLines(0)<CR>
nnoremap <Leader>bb <Esc>A = <Esc>"eyy:call CalcLines(0)<CR>
"noremap <Leader>cc Yp!!bc -lq<CR>kA = <ESC>J
noremap <Leader>cc Yp!!bc -lq\| tr -d '\n\\\r' \| sed -e "s/\.\([0-9]*[1-9]\)0\+$/.\1/" -e "s/\.0\+$//"<CR>kA = <ESC>J
noremap <Leader>c, Yp!!sed "s/,//g" \|bc -lq\| tr -d '\n\\\r' \| sed -e "s/\.\([0-9]*[1-9]\)0\+$/.\1/" -e "s/\.0\+$//"<CR>kA = <ESC>J
" convert hexdecimal to decimal
nnoremap <Leader>10 <Esc>A = <Esc>"eyy:call CalcLines(10)<CR>
" convert decimal to hexdecimal
nnoremap <Leader>16 <Esc>A = <Esc>"eyy:call CalcLines(16)<CR>
" split event P1 to TYPE and MODE
nnoremap <Leader>tx <Esc>A = <Esc>"eyy:call CalcLines(1616)<CR>
" split dba(10) or dba(16) to file# and block#
nnoremap <Leader>22 <Esc>A = <Esc>"eyy:call CalcLines(22)<CR>
nnoremap <Leader>dba <Esc>A = <Esc>"eyy:call CalcLines(22)<CR>
" split scn(10) or scn(16) into scn_wrap,scn_base
nnoremap <Leader>32 <Esc>A = <Esc>"eyy:call CalcLines(32)<CR>
nnoremap <Leader>scn <Esc>A = <Esc>"eyy:call CalcLines(32)<CR>
" convert scn_wrap,scn_base(10) or scn_wrap,scn_base(16) to 10 or 16 base
nnoremap <Leader>ss <Esc>A = <Esc>"eyy:call CalcLines(10016)<CR>
" convert file#,block# dba(10) or file#,block# dba(16) to 10 or 16 base
nnoremap <Leader>rr <Esc>A = <Esc>"eyy:call CalcLines(20016)<CR>
" convert hexdecimal to decimal or decimal to hexdecimal
nnoremap <Leader>hd <Esc>A = <Esc>"eyy:call CalcLines(30016)<CR>
nnoremap <Leader>hh <Esc>A = <Esc>"eyy:call CalcLines(30016)<CR>
nnoremap <Leader>dh <Esc>A = <Esc>"eyy:call CalcLines(30016)<CR>
"" calculate from insertmode
inoremap =: = <Esc>"eyy:call CalcLines(0)<CR>a
" ---------------------------------------------------------------------
" Calculate:
" clean up an expression, pass it to bc, return answer
function! Calculate (s,flag)
let has_hex = 0
let str = a:s
" remove newlines and trailing spaces
let str = substitute (str, "\n", "", "g")
let str = substitute (str, '\s*$', "", "g")
" sub common func names for bc equivalent
let str = substitute (str, '\csin\s*(', 's (', 'g')
let str = substitute (str, '\ccos\s*(', 'c (', 'g')
let str = substitute (str, '\catan\s*(', 'a (', 'g')
let str = substitute (str, "\cln\s*(", 'l (', 'g')
let str = substitute (str, '\clog\s*(', 'l (', 'g')
let str = substitute (str, '\cexp\s*(', 'e (', 'g')
" alternate exponitiation symbols
let str = substitute (str, '\*\*', '^', "g")
let str = substitute (str, '`', '^', "g")
let str = substitute (str, '\^', '^^^^', "g")
" escape chars for shell
if has("unix")
let str = escape (str, '*();&><|^')
endif
let preload = exists ("g:bccalc_preload") ? g:bccalc_preload : ""
" run bc
" return str
" let answer = system ("echo " . str . " \| bc -l " . preload)
if a:flag == 0
let answer = system ("echo " . str . " \| bc -l " . preload)
" let answer = answer . " --- ". str
endif
if a:flag == 10
let str = toupper (str)
let str = substitute (str, "0x", "", "g")
let answer = system ("echo ibase=16 ;" . str . " \| bc -l " . preload)
endif
if a:flag == 16
let answer = system ("echo obase=16 ;" . str . " \| bc -l " . preload)
let answer = "0x" . tolower ( answer )
endif
let has_hex = Check_hex(str)
if a:flag == 1616
if has_hex == 1
let str = toupper (str)
let str = substitute (str, "0x", "", "g")
" 0x10000 hexdecimal = 65536 (10) = 2^16(10)
let answer = system ("echo ibase=16 ;" . str . "/10000" . " \| bc " . preload)
let answer1 = system ("echo ibase=16 ;" . str . "%10000" . " \| bc " . preload)
let answer2 = system ("echo ibase=16 ;" . str . " \| bc -l " . preload)
else
let answer = system ("echo " . str . "/65536" . " \| bc " . preload)
let answer1 = system ("echo " . str . "%65536" . " \| bc " . preload)
let answer2 = "0x" . system ("echo obase=16 ;" . str . " \| bc -l " . preload)
endif
let answer = "/2^16 %2^16 (Type | Mode) = " . answer . "," . answer1 ." = " . tolower(answer2)
endif
if a:flag == 22
if has_hex == 1
let str = toupper (str)
let str = substitute (str, "0x", "", "g")
" 0x400000 hexdecimal = 4194304 (10) = 2^22(10)
let answer = system ("echo ibase=16 ;" . str . "/400000" . " \| bc " . preload)
let answer1 = system ("echo ibase=16 ;" . str . "%400000" . " \| bc " . preload)
let answer2 = system ("echo ibase=16 ;" . str . " \| bc -l " . preload)
else
let answer = system ("echo " . str . "/4194304" . " \| bc " . preload)
let answer1 = system ("echo " . str . "%4194304" . " \| bc " . preload)
let answer2 = "0x" . system ("echo obase=16 ;" . str . " \| bc -l " . preload)
endif
" let answer = "set dba " . answer . "," . answer1
let answer = "set dba " . answer . "," . answer1 ." = alter system dump datefile " . answer . " block " . answer1 ." = " . tolower(answer2)
endif
if a:flag == 32
if has_hex == 1
let str = toupper (str)
let str = substitute (str, "0x", "", "g")
" 0x100000000 hexdecimal = 4294967296(10) = 2^32(10)
let answer = system ("echo ibase=16 ;" . str . "/100000000" . " \| bc " . preload)
let answer1 = system ("echo ibase=16 ;" . str . "%100000000" . " \| bc " . preload)
let answer2 = system ("echo obase=16 ;ibase=16 ;" . str . "/100000000" . " \| bc " . preload)
let answer3 = system ("echo obase=16 ;ibase=16 ;" . str . "%100000000" . " \| bc " . preload)
else
let answer = system ("echo " . str . "/4294967296" . " \| bc " . preload)
let answer1 = system ("echo " . str . "%4294967296" . " \| bc " . preload)
let answer2 = system ("echo obase=16 ;" . str . "/4294967296" . " \| bc " . preload)
let answer3 = system ("echo obase=16 ;" . str . "%4294967296" . " \| bc " . preload)
endif
let answer = "scn_wrap,scn_base(10): " . answer . "," . answer1 . " = scn_wrap,scn_base(16): " . "0x" . tolower (answer2) . "," . "0x" . tolower(answer3)
endif
if a:flag == 10016
if has_hex == 1
let str = toupper (str)
let str = substitute (str, "0x", "", "g")
" 0x100000000 hexdecimal = 4294967296(10) = 2^32(10)
let str = substitute (str, "[,.]", "*100000000+", "g")
let answer = system ("echo obase=10 ;ibase=16 ;" . str . " \| bc -l " . preload)
let answer1 = system ("echo obase=16 ;ibase=16 ;" . str . " \| bc -l " . preload)
else
let str = substitute (str, "[,.]", "*4294967296+", "g")
let answer = system ("echo " . str . " \| bc -l " . preload)
let answer1 = system ("echo obase=16 ;" . str . " \| bc -l " . preload)
endif
let answer = "scn(10): " . answer . " = scn(16): " . "0x" . tolower (answer1)
endif
if a:flag == 20016
if has_hex == 1
let str = toupper ( str )
let str = substitute (str, "0x", "", "g")
" 0x400000 hexdecimal = 4194304 (10) = 2^22(10)
let str = substitute (str, "[,.]", "*400000+", "g")
let answer = system ("echo obase=10 ;ibase=16 ;" . str . " \| bc -l " . preload)
let answer1 = system ("echo obase=16 ;ibase=16 ;" . str . " \| bc -l " . preload)
else
let str = substitute (str, "[,.]", "*4194304+", "g")
let answer = system ("echo " . str . " \| bc -l " . preload)
let answer1 = system ("echo obase=16 ;" . str . " \| bc -l " . preload)
endif
let answer = "file#,block# dba(10): " . answer . " = file#,block# dba(16): " . "0x" . tolower (answer1)
endif
if a:flag == 30016
if has_hex == 1
let str = substitute (str, "0x", "", "g")
let str = toupper ( str )
let answer = system ("echo ibase=16 ;" . str . " \| bc -l " . preload)
else
let answer = system ("echo obase=16 ;" . str . " \| bc -l " . preload)
let answer = "0x" . tolower ( answer )
endif
endif
" strip newline and \
let answer = substitute (answer, "[\\\n]", "", "g")
" strip trailing 0s in decimals
let answer = substitute (answer, '\.\(\d*[1-9]\)0\+$', '.\1', "")
let answer = substitute (answer, '\.0\+$', '', "")
return answer
endfunction
" ---------------------------------------------------------------------
" CalcLines:
"
" take expression from lines, either visually selected or the current line,
" pass to calculate function, echo or past answer after '='
function! CalcLines(flag)
let has_equal = 0
" remove newlines and trailing spaces
let @e = substitute (@e, "\n", "", "g")
let @e = substitute (@e, '\s*$', "", "g")
" if we end with an equal, strip, and remember for output
if @e =~ "=$"
let @e = substitute (@e, '=$', "", "")
let has_equal = 1
endif
" if there is another equal in the line, assume chained equations, remove
" leading ones
let @e = substitute (@e, '^.\+=', '', '')
let answer = Calculate (@e,a:flag)
" append answer or echo
if has_equal == 1
exec "normal a" . answer
else
echo "answer = " . answer
endif
endfunction
" ---------------------------------------------------------------------
" Check_hex:
"
" Check if the string contains 0x, a, b, c, d, e, f return has_hex=1
function! Check_hex(str)
let has_hex = 0
let ss = a:str
let ss = tolower ( ss )
if ss =~ "0x"
let has_hex = 1
return has_hex
endif
if ss =~ "[abcdef]"
let has_hex = 1
return has_hex
endif
endfunction
[20191031]完善vim的bccalc插件7.txt的更多相关文章
- [20191101]完善vim的bccalc插件8.txt
[20191101]完善vim的bccalc插件8.txt --//今天移植bccalc插件到linux,发现一些问题.我自己已经在windows下使用一段时间,从来没有在linux下测试.看来很少人 ...
- [20190913]完善vim的bccacl插件2.txt
[20190913]完善vim的bccacl插件2.txt --//继续完善vim的bccacl插件.--//\bc 计算也可以直接使用 \bb 操作,这样操作更快一些.--//增加直接写好算式计算的 ...
- [20190909]完善vim的bccacl插件.txt
[20190909]完善vim的bccacl插件.txt http://blog.itpub.net/267265/viewspace-2140886/http://blog.itpub.net/26 ...
- [20190920]完善vim调用sqlplus脚本.txt
[20190920]完善vim调用sqlplus脚本.txt --//以前写的http://blog.itpub.net/267265/viewspace-2140936/=>[20170617 ...
- vim配置及插件安装管理(超级详细)
1 写在前面 Linux下编程一直被诟病的一点是: 没有一个好用的IDE, 但是听说Linux牛人, 黑客之类的也都不用IDE. 但是对我等从Windows平台转移过来的Coder来说, 一个好用 ...
- vim配置及插件安装管理(超级详细)[转]
1 写在前面 Linux下编程一直被诟病的一点是: 没有一个好用的IDE, 但是听说Linux牛人, 黑客之类的也都不用IDE. 但是对我等从Windows平台转移过来的Coder来说, 一个好用 ...
- vim配置文件和插件管理
本文通过总结零碎的资料总结而成,更多是去引导学习vim配置文件及插件使用. .vimrc配置文件,内容如下(备注清晰) "引入插件pathogen使用 execute pathogen#in ...
- vim 代码注释插件
参考: 1.http://www.vim.org/scripts/script.php?script_id=1218 2.http://www.dutor.net/index.php/2010/05/ ...
- vundle就是vim bundle的插件管理成ide
如何配置一个高效的php编辑环境, 很好 对vundle的操作, 除了仓库名称是vundle.git (*.git就是仓库) 和 本地目录名是 vundle之外, 其他的操作都是bundle git ...
随机推荐
- luoguP4449 于神之怒加强版
题意 默认\(n\leqslant m\). 一波莫反后可得: \(\sum\limits_{T=1}^{n}\frac{n}{T}\frac{m}{T}\sum\limits_{d|T}d^k\mu ...
- 局域网地址为什么是192.168.X.X?为什么连上公司的VPN就上不了网?
注:本文主要目的是给程序员讲述一些局域网/VPN的基本知识,并不涉及到具体的实操.关于如何安装VPN服务器.配置VPN客户端及修改Windows路由表等具体实操内容,请自行搜索. RFC 局域网地址为 ...
- 使用ReentrantLock
/** * java.util.concurrent.locks包提供的ReentrantLock用于替代synchronized加锁* 因为synchronized是Java语言层面提供的语法,所以 ...
- SpringBoot2 配置多数据源,整合MybatisPlus增强插件
本文源码:GitHub·点这里 || GitEE·点这里 一.项目案例简介 1.多数据简介 实际的项目中,经常会用到不同的数据库以满足项目的实际需求.随着业务的并发量的不断增加,一个项目使用多个数据库 ...
- Java 添加超链接到Word文档
对特定元素添加超链接后,用户可以通过点击被链接的元素来激活这些链接,通常在被链接的元素下带有下划线或者以不同的颜色显示来进行区分.按照使用对象的不同,链接可以分为文本超链接,图像超链接,E-mail链 ...
- 小程序实现日期时间控件picker
小程序自带的组件中有日期跟时间的picker,但就缺个日期时间picker组件,那没办法,只能自己弄一个,这个组件不是很难,比较难的地方是要根据不同年份(是否闰年)跟月份决定一个月里有多少天. 我直接 ...
- Angular中innerHTML标签的样式不起作用详解
1.背景 在最近angular的项目中,需要用到[innerHTML]标签来指定一个div的样式: //HTML部分 <div class="contents" [inner ...
- react学习之js-xlsx导入和导出excel表格
前记:最近真的挺忙的,一件事接着一件,都忘了我的React项目,尽管这是一个没写概率没写离散的夜晚,我决定还是先做做我的React 好了,进入正题 项目需求,需要导入和导出表单,发现前端已经强大到无所 ...
- Zabbix自定义监控项(模板)
虽然Zabbix提供了很多的模板(简单理解为监控项的集合),在zabbix界面点击share按钮就可以直接跳到模板大全的官方网站,但是由于模板内的监控项数量太多不好梳理且各种模板质量参差不齐,还是建议 ...
- 【转】#define 定义别名和 typedef 声明类型的区别
下面一段程序的执行结果是: #include <stdio.h>#define CHAR2 char*int main(){ typedef char* CHAR; CHAR ...