Vim 插件 popup.vim
Vim 插件 popup.vim
popup.vim 是一个 Vim 的一个菜单插件,通过对应的配置,可以添加自定义的菜单。
支持子菜单等,有一些常用的命令放进去挺方便,具体的配置可以到插件的 Github 上面去看,很详细。
" Popup
let plug = [
\['q', '清理插件', ":PlugClean\<cr>"],
\['e', '清理Undofiles', ":!d:/1-Program/Vim/Vimconf/clean.bat\<cr>"]]
let sub = [['s', '重复行', [
\['q', '删除重复行(相同的留下一行)', ":call Sgdd()\<cr>"],
\['w', '删除重复行(相同的保留最后的一行,保持顺序)', ":call Sgndd()\<cr>"],
\['e', '删除重复行(相同的保留最初的一行,保持顺序)', ":call Sgudd()\<cr>"],
\['r', '删除重复行(相同的完全删除)', ":call Sgdj()\<cr>"],
\['t', '删除非重复行', ":call Svdd()\<cr>"]]],
\['x', '全角转半角(部分)', ":call FtoH()\<cr>"],
\['c', '通话录音重命名', ":%s/\\(.*\\)_\\(.*\\)_\\(.*\\).amr/\\2_\\3_\\1.amr/g\<cr>"]]
let sting= [
\['q', '显示菜单栏', ":set guioptions=m\<cr>"],
\['w', '临时长行切换', ":call LonglineJK()\<cr>"],
\['e', '折叠切换', ":call Foldtoggle()\<cr>"],
\['r', '文件比较', ":browse vert diffsplit\<cr>"],
\['t', '转换为十六进制', ":%!xxd\<cr>"],
\['y', '从十六进制转回', ":%!xxd -r\<cr>"]]
let Alc = [
\['a', '插件相关', plug],
\['s', '常用替换' , sub],
\['d', '临时设置' , sting],
\['q', '更新插件', ":PlugUpdate \| PlugUpgrade\<cr>"]]
call popup#add('Alc', 'Alc', Alc)
nmap <expr><m-a> Popup('Alc')
" ### 重复行相关 {{{1
" **** Sgdd 删除重复行(相同的留下一行) {{{2
function! Sgdd()
silent sort u
endfunction
" **** Sgndd 删除重复行(相同的保留最后的一行,保持顺序) {{{2
function! Sgndd()
silent %s/^/\=line('.').' '
silent sort /\d\+ /
silent g/^\d\+ \(.*\)\n^\d\+ \1/d
silent sort n
silent %s/^\d\{-} //
endfunction
" **** Sgudd 删除重复行(相同的保留最初的一行,保持顺序) {{{2
function! Sgudd()
silent g/^/m 0
silent %s/^/\=line('.').' '
silent sort /\d\+ /
silent g/^\d\+ \(.*\)\n^\d\+ \1/d
silent sort n
silent %s/^\d\{-} //
silent g/^/m 0
endfunction
" **** Sgdj 删除重复行(相同的完全删除) {{{2
function! Sgdj()
silent sort
silent g/^\(.*\)$\n\1$/normal dj
endfunction
" **** Svdd 删除非重复行 {{{2
function! Svdd()
silent sort
silent v/^\(.*\)$\n\1$/d
endfunction
" ### FtoH 全角转半角(部分) {{{1
function! FtoH()
silent %s/\v(1|2|3|4|5|6|7|8|9|0)/\={'1':'1','2':'2','3':'3','4':'4','5':'5','6':'6','7':'7','8':'8','9':'9','0':'0'}[submatch(0)]/ge
silent %s/\v(A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z)/\={'A':'A','B':'B','C':'C','D':'D','E':'E','F':'F','G':'G','H':'H','I':'I','J':'J','K':'K','L':'L','M':'M','N':'N','O':'O','P':'P','Q':'Q','R':'R','S':'S','T':'T','U':'U','V':'V','W':'W','X':'X','Y':'Y','Z':'Z'}[submatch(0)]/ge
silent %s/\v(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z)/\={'a':'a','b':'b','c':'c','d':'d','e':'e','f':'f','g':'g','h':'h','i':'i','j':'j','k':'k','l':'l','m':'m','n':'n','o':'o','p':'p','q':'q','r':'r','s':'s','t':'t','u':'u','v':'v','w':'w','x':'x','y':'y','z':'z'}[submatch(0)]/ge
normal gg
endfunction
" 临时长行 {{{1
function! LonglineJK()
if !exists("b:longlinestatus")
nnoremap j gj
nnoremap k gk
silent let b:longlinestatus = 1
else
nnoremap j j
nnoremap k k
silent unlet b:longlinestatus
endif
endfunction
" 折叠设置 {{{1
function! Foldtoggle()
if !exists("b:foldstatus")
silent set foldmethod=marker
normal zN
silent let b:foldstatus = 1
else
normal zn
silent unlet b:foldstatus
endif
endfunction