[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
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2140602/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- [20170725]vim呼叫bccalc外掛問題.txt
- [20210507]完善vim bccalc_win外掛.txt
- [20210810]完善vim bccalc_win外掛.txt
- [20191031]完善vim的bccalc外掛7.txt
- [20210812]完善vim bccalc_linux外掛.txtLinux
- [20191101]完善vim的bccalc外掛8.txt
- [20220117]呼叫bccalc_win.vim外掛失效.txt
- [20200225]vim bccalc外掛與utl-8編碼.txt
- [20170617]vim 8.0外掛安裝.txt
- [20200424]vim visSum.vim合計外掛.txt
- [20220316]完善vim gdb.vim外掛.txt
- Vim 外掛管理
- VIM外掛AutoClose
- [20131125]vim的bccalc.vim外掛有關問題以及10,16進位制轉換的簡單方法.txt
- vim外掛之Taglist
- 關於vim外掛
- 如何管理 Vim 外掛
- Vim外掛入門
- VIM 外掛安裝
- vim的外掛SuperTab
- eclipse vim外掛Eclipse
- [20190909]完善vim的bccacl外掛.txt
- 如何安裝 Vim 外掛
- vim 外掛的安裝
- vim外掛的安裝
- [20190913]完善vim的bccacl外掛2.txt
- vim外掛的安裝方式 -- vim註釋外掛和doxygen函式註釋生成外掛-ctrlp外掛-tabular等號對齊 外掛...函式
- [20131215]安裝vim外掛gundo.txt
- vim外掛 NERDTree安裝使用
- vim配置檔案和外掛
- Vim配置、外掛和使用技巧
- Vim-plug:極簡 Vim 外掛管理器
- [20211224]vim外掛格式化sql語句.txtSQL
- [20231226]vim Align外掛使用例子.txt
- 配置vim外掛遇到youcompleteme外掛問題解決方案
- 5 個好用的開發者 Vim 外掛
- 關於vim的實用外掛
- python vim外掛是什麼Python