[20170612]vim bccalc插件.txt

[20170612]vim bccalc插件.txt

--//上午修改bccacl插件,加入10,16,dba,scn之类转换.由于linux版本,与windows版本存在一些差异,分别贴上来:

1.windows版本:
"" calculate expression entered on command line and give answer, e.g.:
" :Calculate sin (3) + sin (4) ^ 2
command! -nargs=+ Calculate echo "<args> = " . Calculate ("<args>")

"" calculate expression from selection, pick a mapping, or use the Leader form
"vnoremap ;bc "ey`>:call CalcLines()<CR>
"vnoremap <Leader>bc "ey`>:call<SID>CalcBC(1)<CR>
vnoremap ;bc "ey`>:call CalcLines(0)<CR>
vnoremap ;10 "ey`>:call CalcLines(10)<CR>
vnoremap ;16 "ey`>:call CalcLines(16)<CR>
vnoremap ;22 "ey`>:call CalcLines(22)<CR>
vnoremap ;32 "ey`>:call CalcLines(32)<CR>

"" calculate expression on current line, pick a mapping, or use the Leader
nnoremap  <Leader>bc "eyy$:call CalcLines(0)<CR>
nnoremap   <Leader>bx <Esc>A=<Esc>"eyy:call CalcLines(0)<CR>
nnoremap   <Leader>10 <Esc>A=<Esc>"eyy:call CalcLines(10)<CR>
nnoremap   <Leader>16 <Esc>A=<Esc>"eyy:call CalcLines(16)<CR>
nnoremap   <Leader>22 <Esc>A=<Esc>"eyy:call CalcLines(22)<CR>
nnoremap   <Leader>32 <Esc>A=<Esc>"eyy:call CalcLines(32)<CR>

"nnoremap  <Leader>bc "eyy$:call<SID>CalcBC(0)<CR>

"" calculate from insertmode
inoremap =: = <Esc>"eyy:call CalcLines()<CR>a

" ---------------------------------------------------------------------
"  Calculate:
"    clean up an expression, pass it to bc, return answer
function! Calculate (s,flag)

    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
    " let str = escape (str, '*();&><|^')

    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)
    endif
    if a:flag == 16
         let answer = system ("echo obase=16 ;" . str .  " \| bc -l " . preload)
         let answer = "0x" . tolower ( answer )
    endif
    if a:flag == 10
         let str = toupper ( str )
         let answer = system ("echo ibase=16 ;" . str .  " \| bc -l " . preload)
    endif
    if a:flag == 22
         let answer = system ("echo " . str . "/4194304" . " \| bc " . preload)
         let answer1 = system ("echo " . str . "%4194304" . " \| bc " . preload)
         let answer = " set dba " . answer . "," . answer1
    endif

    if a:flag == 32
         let answer = system ("echo " . str . "/4294967296" . " \| bc " . preload)
         let answer1 = system ("echo " . str . "%4294967296" . " \| bc " . preload)
         let answer = " scn_wrap,scn_base: " . answer . " " . answer1
    endif

    " strip newline
    let answer = substitute (answer, "\n", "", "g")

    " strip trailing 0s in decimals
    let answer = substitute (answer, '\.\(\d*[1-9]\)0\+', '.\1', "")

    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

2.linux版本:
"" calculate expression entered on command line and give answer, e.g.:
" :Calculate sin (3) + sin (4) ^ 2
command! -nargs=+ Calculate echo "<args> = " . Calculate ("<args>")

"" calculate expression from selection, pick a mapping, or use the Leader form
"vnoremap ;bc "ey`>:call CalcLines()<CR>
"vnoremap <Leader>bc "ey`>:call<SID>CalcBC(1)<CR>
vnoremap ;bc "ey`>:call CalcLines(0)<CR>
vnoremap ;10 "ey`>:call CalcLines(10)<CR>
vnoremap ;16 "ey`>:call CalcLines(16)<CR>
vnoremap ;22 "ey`>:call CalcLines(22)<CR>
vnoremap ;32 "ey`>:call CalcLines(32)<CR>

"" calculate expression on current line, pick a mapping, or use the Leader
nnoremap  <Leader>bc "eyy$:call CalcLines(0)<CR>
nnoremap   <Leader>bx <Esc>A=<Esc>"eyy:call CalcLines(0)<CR>
nnoremap   <Leader>10 <Esc>A=<Esc>"eyy:call CalcLines(10)<CR>
nnoremap   <Leader>16 <Esc>A=<Esc>"eyy:call CalcLines(16)<CR>
nnoremap   <Leader>22 <Esc>A=<Esc>"eyy:call CalcLines(22)<CR>
nnoremap   <Leader>32 <Esc>A=<Esc>"eyy:call CalcLines(32)<CR>

"nnoremap  <Leader>bc "eyy$:call<SID>CalcBC(0)<CR>

"" calculate from insertmode
inoremap =: = <Esc>"eyy:call CalcLines()<CR>a

" ---------------------------------------------------------------------
"  Calculate:
"    clean up an expression, pass it to bc, return answer
function! Calculate (s,flag)

    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
    let str = escape (str, '*();&><|^')

    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)
    endif

    if a:flag == 16
         let answer = system ("echo 'obase=16 ;" . str .  "' \| bc -l " . preload)
         let answer = "0x" . tolower ( answer )
    endif
    if a:flag == 10
         let str = toupper ( str )
         let answer = system ("echo 'ibase=16 ;" . str .  "' \| bc -l " . preload)
    endif

    if a:flag == 22
         let answer = system ("echo " . str . "/4194304" . " \| bc " . preload)
         let answer1 = system ("echo " . str . "%4194304" . " \| bc " . preload)
         let answer = " set dba " . answer . "," . answer1
    endif

    if a:flag == 32
         let answer = system ("echo " . str . "/4294967296" . " \| bc " . preload)
         let answer1 = system ("echo " . str . "%4294967296" . " \| bc " . preload)
         let answer = " scn_wrap,scn_base: " . answer . " " . answer1
    endif

    " strip newline
    let answer = substitute (answer, "\n", "", "g")

    " strip trailing 0s in decimals
    let answer = substitute (answer, '\.\(\d*[1-9]\)0\+', '.\1', "")

    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

时间: 2024-09-24 09:53:40

[20170612]vim bccalc插件.txt的相关文章

[20170725]vim调用bccalc插件问题.txt

[20170725]vim调用bccalc插件问题.txt http://blog.itpub.net/267265/viewspace-2140886/ http://blog.itpub.net/267265/viewspace-2140823/ http://blog.itpub.net/267265/viewspace-2140602/ --//我个人很喜欢在vim调用bc做各种计算,使用插件bccale,参考前面的链接. --//今天在使用时遇到1个问题,做一个记录与分析: 1/300

[20150310]vim persistent undo.txt

[20150310]vim persistent undo.txt --寻找一个vim插件,上了www.vim.org网站,看到如下一段: Did you know about persistent undo? [2014-10-31] A feature I enjoy using myself is not known to many users, as I found out last weekend. Besides undo with as many levels as you lik

vim srcexpl插件与youcompleteme 冲突

问题描述 vim srcexpl插件与youcompleteme 冲突 大神好: 我安装了youcompleteme 与 srcexpl.如果我打开srcexpl窗口,然后使用上下左右或者hjkl) 进行代码浏览,当我按j或者下箭头 浏览时,总是出现光标突然跳转到代码的第一行,也就是文件头.这个问题大家有遇到过吗 哪位大神能帮帮我. 解决方案 两个插件不能同时用,看下是不是快捷键重复了

CCTree 1.60发布 一个Vim 7插件

CCTree 1.60该版本一个性能speed-up为tree的深度使用增量被更新. CCTree是一个Vim 7插件,显示层次的功能或使用cscope数据库文件调用树.该功能类似于其他IDE和源分析应用,提供了像Kscope,源导航,和http://www.aliyun.com/zixun/aggregation/13428.html">Eclipse. CCTree功能为C符号的依赖关系树分析仪使用cscope数据库.它基本支持函数和宏,及全局变量,宏,枚举和类型自定义扩展支持. 安装

如何优雅地使用 VIM 文件管理插件 NERDTree

相信所有使用 vim 的同学都知道文件管理插件 NERDTree,这个几乎是所有拥护 vim 的开发人员都会使用的插件,可是我在刚开始使用的时候,完全用错了这个插件,使用起来反而是负担了.今天就总结一下如何优雅的使用 NERDTree. 安装和基本用法 安装插件建议使用 Vundle 进行安装, Vundle 的用法很简单,可以到 GitHub 上面查看. 在 NERDTree 操作区的一些基本操作: ?: 快速帮助文档 o: 打开一个目录或者打开文件,创建的是 buffer,也可以用来打开书签

VIM常用插件

Asciitable:ASCII字符表 该插件可以在新窗口内以8进制.10进制或16进制生成ASCII字符表. 主页:http://www.vim.org/scripts/script.php?script_id=616 calendar:日历插件 该插件可以在屏幕左侧或下方生成指定月份的日历. 主页:http://www.vim.org/scripts/script.php?script_id=52 ColorSel:颜色选择器 该插件允许你像使用Windows的颜色选择器一样来选择颜色. 主

eclim 1.7.6发布 Eclipse集成到vim的插件

eclim 是一套用于 http://www.aliyun.com/zixun/aggregation/13428.html">Eclipse 的 Vim插件,用于将Eclipse开发环境集成到Vim编辑器中.最初的目标是提供了在vim中的Eclipse Java功能,现在支持各种其他语言(c/c++, php, python, ruby, css, html, xml, 等). eclim 1.7.6该版本修正eclim Vim帮助文件的安装位置和其他小的错误修复. 软件信息:http:

eclim 1.7.5发布 Eclipse集成到vim的插件

eclim 是一套用于 http://www.aliyun.com/zixun/aggregation/13428.html">Eclipse 的 Vim插件,用于将Eclipse开发环境集成到Vim编辑器中.最初的目标是提供了在vim中的Eclipse Java功能,现在支持各种其他语言(c/c++, php, python, ruby, css, html, xml, 等). eclim 1.7.5该版本进和地一些小的改进与修正错误. 软件信息:http://eclim.org/

vim的插件SuperTab

很早就知道vim的插入补全操作,但是命令比较繁琐,很少去记忆.. 我以前使用如下命令来实现tab的插入补全.. function! CleverTab() if strpart( getline('.'), 0, col('.')-1 ) =~ '^s*$' return "" else return "" endfunction inoremap =CleverTab() 今天看了http://vim.sourceforge.net/scripts/script.