永发信息网

最近在学LINUX遇到到一个难题,是关于VI编辑器的,回答的精彩必有加分!

答案:1  悬赏:40  手机版
解决时间 2021-03-28 05:12
  • 提问者网友:蓝琪梦莎
  • 2021-03-27 21:40
最近在学LINUX遇到到一个难题,是关于VI编辑器的,回答的精彩必有加分!
最佳答案
  • 五星知识达人网友:醉吻情书
  • 2021-03-27 22:58
回答这个问题很蛋疼啊

有一部分参考了插件calendar.vm

将下面2个函数放入vimrc或者在plugin文件夹新建一个.vim文件
调用:
:call Reply_Baidu()

function MY_Calendar(vyear,vmnth)
" get arguments
let vyear = a:vyear
let vmnth = a:vmnth
" start with last 6 month
let vmnth = vmnth - 6
if vmnth < 1
let vmnth = 12 - vmnth
let vyear = vyear - 1
endif
" reset display variables
let vmcnt = 0
while vmcnt < 12
let vcolumn = 22
let vnweek = -1
"--------------------------------------------------------------
"--- calculating
"--------------------------------------------------------------
" set boundary of the month
if vmnth == 1
let vmdays = 31
let vparam = 1
let vsmnth = 'Jan'
elseif vmnth == 2
let vmdays = 28
let vparam = 32
let vsmnth = 'Feb'
elseif vmnth == 3
let vmdays = 31
let vparam = 60
let vsmnth = 'Mar'
elseif vmnth == 4
let vmdays = 30
let vparam = 91
let vsmnth = 'Apr'
elseif vmnth == 5
let vmdays = 31
let vparam = 121
let vsmnth = 'May'
elseif vmnth == 6
let vmdays = 30
let vparam = 152
let vsmnth = 'Jun'
elseif vmnth == 7
let vmdays = 31
let vparam = 182
let vsmnth = 'Jul'
elseif vmnth == 8
let vmdays = 31
let vparam = 213
let vsmnth = 'Aug'
elseif vmnth == 9
let vmdays = 30
let vparam = 244
let vsmnth = 'Sep'
elseif vmnth == 10
let vmdays = 31
let vparam = 274
let vsmnth = 'Oct'
elseif vmnth == 11
let vmdays = 30
let vparam = 305
let vsmnth = 'Nov'
elseif vmnth == 12
let vmdays = 31
let vparam = 335
let vsmnth = 'Dec'
else
echo 'Invalid Year or Month'
return
endif
if vyear % 400 == 0
if vmnth == 2
let vmdays = 29
elseif vmnth >= 3
let vparam = vparam + 1
endif
elseif vyear % 100 == 0
if vmnth == 2
let vmdays = 28
endif
elseif vyear % 4 == 0
if vmnth == 2
let vmdays = 29
elseif vmnth >= 3
let vparam = vparam + 1
endif
endif

" calc vnweek of the day
if vnweek == -1
let vnweek = ( vyear * 365 ) + vparam
let vnweek = vnweek + ( vyear/4 ) - ( vyear/100 ) + ( vyear/400 )
if vyear % 4 == 0
if vyear % 100 != 0 || vyear % 400 == 0
let vnweek = vnweek - 1
endif
endif
let vnweek = vnweek - 1
endif

" fix Gregorian
if vyear <= 1752
let vnweek = vnweek - 3
endif

let vnweek = vnweek % 7

"--------------------------------------------------------------
"--- displaying
"--------------------------------------------------------------
" build header
let vdisplay2=vyear.'/'.vmnth.'('
let vdisplay2=strpart(" ",
\ 1,(vcolumn-strlen(vdisplay2))/2-2).vdisplay2
let vdisplay2=vdisplay2.vsmnth.')'."\n"
let vwruler = "Su Mo Tu We Th Fr Sa"
let vdisplay2 = vdisplay2.' '.vwruler."\n"

" build calendar
let vinpcur = 0
while (vinpcur < vnweek)
let vdisplay2=vdisplay2.' '
let vinpcur = vinpcur + 1
endwhile

let vdaycur = 1
let vdisplay2 = vdisplay2.' '
while (vdaycur <= vmdays)
if vmnth < 10
let vtarget =vyear."0".vmnth
else
let vtarget =vyear.vmnth
endif
if vdaycur < 10
let vtarget = vtarget."0".vdaycur
else
let vtarget = vtarget.vdaycur
endif
let vsign = ''

if vdaycur < 10
let vdisplay2=vdisplay2.' '
endif
let vdisplay2=vdisplay2.vdaycur
let vdaycur = vdaycur + 1

" fix Gregorian
if vyear == 1752 && vmnth == 9 && vdaycur == 3
let vdaycur = 14
endif

let vinpcur = vinpcur + 1
if vinpcur % 7 == 0
let vdisplay2=vdisplay2."\n"
endif
let vdisplay2 = vdisplay2.' '
endwhile
let vmnth = vmnth + 1
let vmcnt = vmcnt + 1
if vmnth > 12
let vmnth = 1
let vyear = vyear + 1
endif
silent put =vdisplay2
endwhile

return
endfunction

function Reply_Baidu()

exe "normal ggdG"
" 插入日历
call MY_Calendar(2009,7)
exe "w 2009.txt"

" 标题变为2009全年日历
call append(1,"\t2009 Calendar")

" 每个月的行数
let jan = search("Jan")
let feb = search("Feb")
let mar = search("Mar")
let apr = search("Apr")
let may = search("May")
let jun = search("Jun")
let jul = search("Jul")
let aug = search("Aug")
let sep = search("Sep")
let oct = search("Oct")
let nov = search("Nov")
let dec = search("Dec")

" 移动4-6月
let line = apr
while line < jul
call cursor(line,1)
exe ">"
let line = line + 1
endwhile

" 删除123 再恢复 这不蛋疼么
let line = apr-jan
call cursor(jan,1)
exe "normal d".line."d"
exe "normal kp"

" 7 8 9 移动到最后
let line = oct - jul
call cursor(jul,1)
exe "normal d".line."d"
exe "normal Gp"

" 检测30 并删除
let line = 1
echo line('$')
while line <= line('$')
if getline(line) =~ '\<30\>'
if getline(line) =~ '\<31\>' || getline(line+1) =~ '\<31\>'
let line = line + 1
continue
else
call cursor(line,1)
exe "normal f3d$"
endif
endif
let line = line + 1
endwhile

" 最后保存
exe "w 2009.txt"

endfunction
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯