" Base Settings 基本设置" all function by myself"==========================================function! RunShell(Msg, Shell)echo a:Msg . '...'call system(a:Shell)echon 'done'endfunctionfunction! ReName()let old_name = expand("<cword>")let old_name = input("old name:",old_name)let new_name = input("new name:",old_name)let exec = input("are sure to refactor(y/n|Y/N):")if 'y' == exec || 'Y' == execlet cmd = printf("/opt/sys/settings/bin/vim/shell/ref.sh %s %s",old_name,new_name)echo cmd:call RunShell("refactoring",cmd)endifendfunctionlet g:spx_begin = 0function! GetCurrentCursor()let g:spx_begin = line('.')let g:spx_begin = g:spx_begin + 0echo "get current line idx:".g:spx_beginendfunctionfunction! ClearCurrentCursor()let g:spx_begin = 0echo "clear current cursor is success"endfunctionfunction! CopyLinesToSystem()let begin_idx = 0if 0 != g:spx_beginlet begin_idx = g:spx_beginlet g:spx_cpy_begin = 0elselet begin_idx = line(".")let begin_idx = input("begin line idx:",begin_idx)endiflet end_idx = line(".")let end_idx = input("end line idx:",end_idx)let begin_idx = begin_idx + 0let end_idx = end_idx + 0if begin_idx > end_idxlet tmp = begin_idxlet begin_idx = end_idxlet end_idx = tmpendiflet list = getline(begin_idx,end_idx)let lines = join(list,"\n")if "xterm" == &termcall setreg("",lines)elsecall setreg("+",lines)endifecho "copy lines to system begin:" . begin_idx . " end:" . end_idxendfunctionfunction! DeleteLines()let begin_idx = 0if 0 != g:spx_beginlet begin_idx = g:spx_beginlet g:spx_cpy_begin = 0elselet begin_idx = line('.')let begin_idx = input("begin line idx:",begin_idx)endiflet end_idx = line('.')let end_idx = input("end line idx:",end_idx)let begin_idx = begin_idx + 0let end_idx = end_idx + 0if begin_idx > end_idxlet tmp = begin_idxlet begin_idx = end_idxlet end_idx = tmpendiflet cur = getpos('.')let cur[1] = begin_idx + 0let result = setpos('.',cur)if(0 != result)echo "delete lines begin:" . begin_idx . " end:" . end_idx ." is fail"returnendiflet lines = abs(begin_idx - end_idx) + 1 "add the line self"for foldexecute ":". begin_idx . "," . end_idx . "de"echo "delete lines begin:" . begin_idx . " end:" . end_idxendfunctionnoremap <leader>fg :call GetCurrentCursor()<cr>noremap <leader>fc :cal ClearCurrentCursor()<cr>noremap <leader>fy :call CopyLinesToSystem()<cr>noremap <leader>fd :call DeleteLines()<cr>noremap <leader>fr :call ReName()<cr>nmap <M-g> :call GetCurrentCursor()<cr>nmap <M-c> :call ClearCurrentCursor()<cr>nmap <M-y> :call CopyLinesToSystem()<cr>nmap <M-d> :call DeleteLines()<cr>nmap <M-r> :call ReName()<cr>function! DeleteShiftLines()let lines = input("input above lines count:")if 0 == linesreturnendifexec "normal ".lines."k"exec "normal ".lines."dd"endfunctionnoremap <leader>sd :call DeleteShiftLines()<cr>"设定当前列高亮function! SetColorColumn(cnum)let col_num = 0if 0 < a:cnumlet col_num = a:cnumecho col_numelselet col_num = virtcol(".")endiflet cc_list = split(&cc, ',')if count(cc_list, string(col_num)) <= 0execute "set cc+=".col_numelseexecute "set cc-=".col_numendifendfunctionmap <leader>ch :call SetColorColumn(0)<CR>autocmd BufNewFile *.c,*.py,*.md exec ":call SetColorColumn(80)"" 定义函数AutoSetFileHead,自动插入文件头autocmd BufNewFile *.sh,*.py,*.md exec ":call AutoSetFileHead()"function! AutoSetFileHead()"如果文件类型为.sh文件if &filetype == 'sh'call setline(1, "\#!/bin/bash")endif"如果文件类型为pythonif &filetype == 'python'call setline(1, "\#!/usr/bin/env python")call append(1, "\# -*- encoding: utf-8 -*-")endifif &filetype == 'mkd' || &filetype == 'md'call setline('.',"---")normal ==ocall setline('.',"layout: post")normal ==ocall setline('.',"categories: []")normal ==ocall setline('.',"title: \" \"")normal ==ocall setline('.',"tags: []")normal ==ocall setline('.',"---")normal ==oendifnormal Gnormal onormal oendfunc" 保存文件时删除多余空格" Delete trailing white space on save, useful for Python and CoffeeScript ;)func! DeleteTrailingWS()exe "normal mz"%s/\s\+$//geexe "normal `z"endfuncautocmd BufWrite *.py :call DeleteTrailingWS()autocmd BufWrite *.c :call DeleteTrailingWS()autocmd BufWrite *.h :call DeleteTrailingWS()autocmd BufWrite *.vimrc :call DeleteTrailingWS()" 相对行号 行号变成相对,可以用 nj nk 进行跳转 5j 5k 上下跳5行set relativenumber numberau FocusLost * :set norelativenumber numberau FocusGained * :set relativenumber" 插入模式下用绝对行号, 普通模式下用相对autocmd InsertEnter * :set norelativenumber numberautocmd InsertLeave * :set relativenumberfunction! NumberToggle()if(&relativenumber == 1)set norelativenumber numberelseset relativenumberendifendfuncnnoremap <C-t> :call NumberToggle()<cr>function! SpxFormat()python << endpythonimport vimimport sysspx_linecount = 40newlines = [ ]b = vim.current.bufferfor line in b :sline = line.decode("utf8")llen = len(sline)times = llen / spx_linecountif 0 != (llen % spx_linecount) :times = times + 1for i in range(times) :begin = i * spx_linecountend = (i + 1) * spx_linecountif end > llen :end = llennewline = sline[begin : end]newlines.append(newline.encode("utf8"))del b[ : ]b.append(newlines)endpythonendfunctionlet g:rnd = localtime() % 0x10000function! Random(n) abort"let i = 0"let al = []"while i < 100let g:rnd = (g:rnd * 31421 + 6927) % 0x10000let r = g:rnd * a:n/0x10000"call add(al,r)"let i = i + 1"endwhile"echo alreturn rendfunctionfunction! RandomHex() abortreturn Random(0x7FFFFFFF)endfunctionfunction! GenFileRandom()let currLine = line('.')let sourcefilename=expand("%:t")let definename=substitute(sourcefilename,' ','','g')let definename=substitute(definename,'\.','_','g')let definename = toupper(definename)exe 'normal '.currLine.'GO'let randFF = RandomHex()call setline('.', '/* random integer for file generate by automatic ')normal ocall setline('.', '* it use for memory allocator and debug ')normal ocall setline('.', '* so do not delete and keep name start with current filename */')normal ocall setline('.', 'static int '.definename.'_RANDOMS = '.randFF.';')normal oendfunctionnmap la :call GenFileRandom()<CR>"替换命令fun! SetupCommandAlias(from, to)exec 'cnoreabbrev <expr> '.a:from\ .' ((getcmdtype() is# ":" && getcmdline() is# "'.a:from.'")'\ .'? ("'.a:to.'") : ("'.a:from.'"))'endfunfunction! IndentIgnoringComments()let in_comment = 0for i in range(1, line('$'))if !in_comment" Check if this line starts a commentif getline(i) =~# '^\s*/\*'"if getline(i) =~# '^\s*/\*\*'let in_comment = 1else" Indent line 'i'execute i . "normal =="endifelse" Check if this line ends the commentif getline(i) =~# '\*\/\s*$'let in_comment = 0endifendifendforendfunctionnnoremap <leader>= :call IndentIgnoringComments()<CR>" -- New file .h .C .cpp, add file header --autocmd BufNeWFile *.[ch] exec ":call CFileHeader( )"autocmd BufNeWFile *.hpp,*.cc exec ":call CPPFileHeader( )"func CFileHeader()call setline(1,"/*************************************************************")normal ocall setline(("."),"*")normal ocall setline(("."),"* You can copy the software or lib under the terms of the gnu")normal ocall setline(("."),"* general public license v3,which may be found in the source")normal ocall setline(("."),"* kit.")normal ocall setline(("."),"*")normal ocall setline(("."),"* Warning:")normal ocall setline(("."),"* If use the code for bussiness or any act of gain, you must")normal ocall setline(("."),"* get my green light with mail or any documentary evidence.")normal ocall setline(("."),"*")normal ocall setline(("."),"*")normal ocall setline((".") ,"* Author: Seapeak.Xu (www.94geek.com)")normal ocall setline((".") ,"* Mail: xvhfeng@gmail.com")normal ocall setline((".") , "* Date: " .strftime ("%Y/%m/%d %H:%M:%S"))normal ocall setline((".") ,"*")normal ocall setline((".") ,"*")normal ocall setline((".") , "* File: ".strftime( expand( '%d')))normal ocall setline((".") ,"* -- ")normal ocall setline(("."),"***************************************************************/")normal ocall setline((".") , "")normal oexec "$"endfuncfunc CPPFileHeader()call setline(1,"/*************************************************************")normal ocall setline(("."),"*")normal ocall setline(("."),"* You can copy the software or lib under the terms of the gnu")normal ocall setline(("."),"* general public license v3,which may be found in the source")normal ocall setline(("."),"* kit.")normal ocall setline(("."),"*")normal ocall setline(("."),"* Warning:")normal ocall setline(("."),"* If use the code for bussiness or any act of gain, you must")normal ocall setline(("."),"* get my green light with mail or any documentary evidence.")normal ocall setline(("."),"*")normal ocall setline(("."),"*")normal ocall setline((".") ,"* Author: Seapeak.Xu (www.94geek.com)")normal ocall setline((".") ,"* Mail: xvhfeng@gmail.com")normal ocall setline((".") , "* Date: " .strftime ("%Y/%m/%d %H:%M:%S"))normal ocall setline((".") ,"*")normal ocall setline((".") ,"*")normal ocall setline((".") , "* File: ".strftime( expand( '%d')))normal ocall setline((".") ,"* -- ")normal ocall setline(("."),"***************************************************************/")normal ocall setline((".") , "")normal oexec "$"endfuncfunction! SpxInsertHeadDef(firstLine, lastLine)if a:firstLine <1 || a:lastLine> line('$')echoerr 'InsertHeadDef : Range overflow !(FirstLine:'.a:firstLine.';LastLine:'.a:lastLine.';ValidRange:1~'.line('$').')'return ''endiflet sourcefilename=expand("%:t")let definename=substitute(sourcefilename,' ','','g')let definename=substitute(definename,'\.','_','g')let definename = toupper(definename)exe 'normal '.a:firstLine.'GO'call setline('.', '#ifndef _'.definename."_")normal ocall setline('.', '#define _'.definename."_")normal ocall setline('.', '#ifdef __cplusplus')normal ocall setline('.', 'extern "C" {')normal ocall setline('.', '#endif')normal oexe 'normal =='.(a:lastLine-a:firstLine+1).'jo'call setline('.', '#ifdef __cplusplus')normal ocall setline('.', '}')normal ocall setline('.', '#endif')normal ocall setline('.', '#endif')let goLn = a:firstLine+2exe 'normal =='.goLn.'G'endfunctionfunction! SpxInsertHeadDefN()let firstLine = 21let lastLine = line('$')let n=21"50 is the magic number"if you file init context size is more than 50,"plesae set larger again.while n < 80let line = getline(n)if n==21if line =~ '^\/\*.*$'let n = n + 1continueelsebreakendifendifif line =~ '^.*\*\/$'let firstLine = n+1breakendiflet n = n + 1endwhilecall SpxInsertHeadDef(firstLine, lastLine)endfunctionnmap ha :call SpxInsertHeadDefN()<CR>autocmd BufNewFile *.h,*.hpp :call SpxInsertHeadDefN()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。