Vim配置文件

"所有的配色方案在这里
"ls /usr/share/vim/vim7*/colors/
"colorscheme default
colorscheme desert
"colorscheme blue
"colorscheme darkblue
"colorscheme delek
"colorscheme elflord
"colorscheme evening
"colorscheme koehler
"colorscheme morning
"colorscheme murphy
"colorscheme pablo
"colorscheme peachpuff
"colorscheme slate
"colorscheme ron
"colorscheme shine
"colorscheme torte
"colorscheme zellner

"关键字颜色
syntax on
"显示行号
set number
"立即显示查找匹配
set incsearch
"自动缩进
set autoindent
"自动缩进的尺寸
set shiftwidth=4
"backspace一次可删除4个空格
set softtabstop=4
"设置tab键一次4个空格宽度
set tabstop=4
"折叠功能开启
set foldenable
"设置折叠方式
"按照语法折叠
set foldmethod=syntax
"按照缩进折叠
"set foldmethod=indent 
"显示层级线
"set foldcolumn=1
"刚打开文件希望看到的文件夹层级,0代表能折叠的就折叠
set foldlevel=1
"光标移动到buffer的顶部和底部时保持3行距离
set scrolloff=2
"设置所有情况下可以使用鼠标
"n 普通模式
"v 可视模式
"i 插入模式
"c 命令模式
"a 所有模式
"可组合
set mouse=ni
"不兼容vi模式
set nocompatible
"覆盖文件时不产生备份文件
set nobackup
"显示中文帮助
set helplang=cn
set encoding=utf-8
"设置当文件被改动时自动载入
set autoread
"quickfix模式
"autocmd FileType c,cpp map <buffer> <leader><space> :w<cr>:make<cr>
"允许插件
"filetype plugin on           
"共享剪贴板
"set clipboard+=unnamed
"从不备份
set nobackup
"自动保存
set autowrite
"设置魔术
set magic
"隐藏工具栏
set guioptions-=T
"隐藏菜单栏
set guioptions-=m
"去掉输入错误的提示声音
set noeb
"在处理未保存或只读文件的时候,弹出确认
set confirm
"自动缩进
set autoindent
set cindent
"Tab键的宽度
set tabstop=4
"统一缩进为4
set softtabstop=4
set shiftwidth=4
"禁止生成临时文件
set nobackup
set noswapfile
"搜索忽略大小写
set ignorecase
"搜索逐字符高亮
"set hlsearch
set incsearch
"行内替换
set gdefault
"编码设置
set enc=utf-8
set fencs=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936
"语言设置
set langmenu=zh_CN.UTF-8
set helplang=cn
"侦测文件类型
filetype on
"载入文件类型插件
filetype plugin on
"为特定文件类型载入相关缩进文件
filetype indent on
"保存全局变量
set viminfo+=!
"为C程序提供自动缩进
set smartindent
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"filetype plugin indent on
"打开文件类型检测, 加了这句才可以用智能补全
"set completeopt=longest,menu
"代码补全 
"set completeopt=preview,menu 
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"新建.c,.h,.sh,.cpp,.py文件,自动插入文件头
autocmd BufNewFile *.{c,cpp,sh,py} exec ":call SetTitle()"
func SetTitle()
    "如果文件类型为.sh文件 
    if (&filetype == 'sh')||(&filetype == 'python')
        call setline(1,          "\#########################################################################")
        call append(line("."),   "\# File Name     : ".expand("%"))
        call append(line(".")+1, "\# Author        : chmodJack")
        call append(line(".")+2, "\# Mail          : 158754845@qq.com")
        call append(line(".")+3, "\# GitHub        : https://github.com/chmodJack ")
        call append(line(".")+4, "\# Created Time  : ".strftime("%c"))
        call append(line(".")+5, "\# Description   : ")
        call append(line(".")+6, "\#########################################################################")
        call append(line(".")+7, "")
        if(&filetype == 'sh')
            call append(line(".")+8, "\#!/bin/sh")
        elseif(&filetype == 'python')
            call append(line(".")+8, "\#!/usr/bin/python3")
        endif
        call append(line(".")+9, "")
        call append(line(".")+10, "")
        normal! G
    else
        call setline(1,          "/*************************************************************************")
        call append(line("."),   "    > File Name       : ".expand("%"))
        call append(line(".")+1, "    > Author          : chmodJack")
        call append(line(".")+2, "    > Mail            : 158754845@qq.com")
        call append(line(".")+3, "    > GitHub          : https://github.com/chmodJack ")
        call append(line(".")+4, "    > Created Time    : ".strftime("%c"))
        call append(line(".")+5, "    > Description     : ")
        call append(line(".")+6, "*************************************************************************/")
        call append(line(".")+7, "")
    endif
    if &filetype == 'cpp'
        call append(line(".")+8,  "#include<iostream>")
        call append(line(".")+9,  "")
        call append(line(".")+10, "using namespace std;")
        call append(line(".")+11, "")
        call append(line(".")+12, "int main(int argc,char* argv[])")
        call append(line(".")+13, "{")
        call append(line(".")+14, "    return 0;")
        call append(line(".")+15, "}")
        normal! G
    endif
    if &filetype == 'c'
        call append(line(".")+8,  "#include<stdio.h>")
        call append(line(".")+9,  "")
        call append(line(".")+10, "int main(int argc,char* argv[])")
        call append(line(".")+11, "{")
        call append(line(".")+12, "    return 0;")
        call append(line(".")+13, "}")
        normal! G
    endif
endfunc
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"自动添加头文件卫士
function! s:InsertGates()
    call setline(1,          "/*************************************************************************")
    call append(line("."),   "    > File Name       : ".expand("%"))
    call append(line(".")+1, "    > Author          : chmodJack")
    call append(line(".")+2, "    > Mail            : 158754845@qq.com ")
    call append(line(".")+3, "    > GitHub          : https://github.com/chmodJack ")
    call append(line(".")+4, "    > Created Time    : ".strftime("%c"))
    call append(line(".")+5, "    > Description     : ")
    call append(line(".")+6, "*************************************************************************/")
    call append(line(".")+7, "")
    normal! 8j
    let gatename = substitute(toupper(expand("%:t")), "\\.", "_", "g")
    execute "normal! i#ifndef __" . gatename ."__"
    execute "normal! o#define __" . gatename . "__"
    execute "normal! Go\n#endif//__". gatename . "__"
    normal! k
endfunction
autocmd BufNewFile *.{h,hpp,H} call <SID>InsertGates()
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function! s:InsertMakerules()
    call setline(1,           "TARGET:=main")
    call append(line("."),    "CROSS:=")
    call append(line(".")+1,  "CC:=$(CROSS)gcc")
    call append(line(".")+2,  "ECHO:=@")
    call append(line(".")+3,  "")
    call append(line(".")+4,  "SSRC+=$(shell find . -name '*.s')")
    call append(line(".")+5,  "CSRC+=$(shell find . -name '*.c')")
    call append(line(".")+6,  "CPPSRC+=$(shell find . -name '*.cpp')")
    call append(line(".")+7,  "OBJS+=$(SSRC:%.s=%.o)")
    call append(line(".")+8,  "OBJS+=$(CSRC:%.c=%.o)")
    call append(line(".")+9,  "OBJS+=$(CPPSRC:%.cpp=%.o)")
    call append(line(".")+10,  "")
    call append(line(".")+11,  "ALLPATHS:=$(shell ls -R | grep :)")
    call append(line(".")+12,  "CFLAGS+=$(ALLPATHS:%:=-I%)")
    call append(line(".")+13,  "CFLAGS+=-c -Ofast -DDEBUG -I.")
    call append(line(".")+14,  "")
    call append(line(".")+15,  "CSFLAGS+=$(CFLAGS)")
    call append(line(".")+16,  "CCFLAGS+=$(CFLAGS) -std=c11")
    call append(line(".")+17,  "CCPPFLAGS+=$(CFLAGS) -std=c++11")
    call append(line(".")+18,  "")
    call append(line(".")+19,  "LDFLAGS+=$(ALLPATHS:%:=-L%)")
    call append(line(".")+20,  "LDFLAGS+=-lc -lm -lstdc++ -pthread")
    call append(line(".")+21,  "")
    call append(line(".")+22,  ".PHONY:all clean")
    call append(line(".")+23,  "all:$(TARGET)")
    call append(line(".")+24,  "    @echo -e '\033[33m[GO] \033[32m$<\033[0m'")
    call append(line(".")+25,  "    $(ECHO)./$<")
    call append(line(".")+26,  "$(TARGET):$(OBJS)")
    call append(line(".")+27,  "    @echo -e '\033[33m[LD] \033[32m$@\033[0m'")
    call append(line(".")+28,  "    $(ECHO)$(CC) -o $@ $^ $(LDFLAGS)")
    call append(line(".")+29,  "%.o:%.s")
    call append(line(".")+30,  "    @echo -e '\033[33m[CC] \033[32m$@\033[0m'")
    call append(line(".")+31,  "    $(ECHO)$(CC) -o $@ $< $(CSFLAGS)")
    call append(line(".")+32,  "%.o:%.c")
    call append(line(".")+33,  "    @echo -e '\033[33m[CC] \033[32m$@\033[0m'")
    call append(line(".")+34,  "    $(ECHO)$(CC) -o $@ $< $(CCFLAGS)")
    call append(line(".")+35,  "%.o:%.cpp")
    call append(line(".")+36,  "    @echo -e '\033[33m[CC] \033[32m$@\033[0m'")
    call append(line(".")+37,  "    $(ECHO)$(CC) -o $@ $< $(CCPPFLAGS)")
    call append(line(".")+38,  "clean:")
    call append(line(".")+39,  "    @echo -e '\033[33m[RM] \033[32m$(TARGET) $(OBJS) cscope.* tagsa.out \033[0m'")
    call append(line(".")+40,  "    $(ECHO)rm -rf $(TARGET) $(OBJS) cscope.* tags a.out")
endfunction
autocmd BufNewFile Makefile call <SID>InsertMakerules()
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"键盘命令F5 make;F6 make clean;
map <F5> :call Make()<CR>
fun!Make()
    exec "w"
    exec "!make"
endfunc
map <F6> :call MakeClean()<CR>
fun!MakeClean()
    exec "w"
    exec "!make clean"
endfunc
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"F4切换屏幕;设置鼠标后即可用鼠标拖动;
map <C-h> <C-w><
map <C-l> <C-w>>
map <C-j> <C-w>-
map <C-k> <C-w>+
map <F4> <C-w><C-w>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

"if has("cscope")
"   set csprg=/usr/bin/cscope
"   set csto=0
"   set cst
"   set nocsverb
"   " add any database in current directory
"   if filereadable("cscope.out")
"   "   cs add cscope.out
"       " else add database pointed to by environment
"   elseif $CSCOPE_DB != ""
"   "   cs add $CSCOPE_DB
"   "endif
"   set csverb
"endif

"0 or s: Find this C symbol
"1 or g: Find this definition
"2 or d: Find functions called by this function
"3 or c: Find functions calling this function
"4 or t: Find this text string
"6 or e: Find this egrep pattern
"7 or f: Find this file
"8 or i: Find files #including this file

map 0<C-\> :cs find 0 <C-R>=expand("<cword>")<CR><CR>
map 1<C-\> :cs find 1 <C-R>=expand("<cword>")<CR><CR>
map 2<C-\> :cs find 2 <C-R>=expand("<cword>")<CR><CR>
map 3<C-\> :cs find 3 <C-R>=expand("<cword>")<CR><CR>
map 4<C-\> :cs find 4 <C-R>=expand("<cword>")<CR><CR>
map 6<C-\> :cs find 6 <C-R>=expand("<cword>")<CR><CR>

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
func! AddCscopeIndex()
    exec "w"
    exec "cscope add ./cscope.out"
endfunc
map <C-F9> :call AddCscopeIndex()<CR>
"""""""""""""""""""""""""""""
func! KillCscopeIndex()
    exec "w"
    exec "cscope kill -1"
endfunc
map <C-F10> :call KillCscopeIndex()<CR>
"""""""""""""""""""""""""""""
func! CreateIndexFile()
    exec "w"
"有什么其他想加入搜索的文件就在此find命令的命令行参数里面加入
    exec "!find . -name '*.s' -o -name '*.c' -o -name '*.h' -o -name '*.cpp' -o -name '*.hpp' -o -name Makefile -o -name '*.sh' -o -name '*.py' -o -name '*.java' -o -name '*.scala' > cscope.files ; cscope -bq -i ./cscope.files ; ctags -R *"
endfunc
map <F9> :call CreateIndexFile()<CR>
"""""""""""""""""""""""""""""
func! CleanIndexFile()
    exec "w"
    exec "!rm -f cscope* tags"
endfunc
map <F10> :call CleanIndexFile()<CR>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"   echo 命令控制参数
"   0   重新设置属性到缺省设置
"   1   设置粗体
"   2   设置一半亮度(模拟彩色显示器的颜色)
"   4   设置下划线(模拟彩色显示器的颜色)
"   5   设置闪烁
"   7   设置反向图象
"   22  设置一般密度
"   24  关闭下划线
"   25  关闭闪烁
"   27  关闭反向图象
"   30  设置黑色前景
"   31  设置红色前景
"   32  设置绿色前景
"   33  设置黄色前景
"   34  设置蓝色前景
"   35  设置紫色前景
"   36  设置青色前景
"   37  设置白色(灰色)前景
"   38  在缺省的前景颜色上设置下划线
"   39  在缺省的前景颜色上关闭下划线
"   40  设置黑色背景
"   41  设置红色背景
"   42  设置绿色背景
"   43  设置黄色背景
"   44  设置蓝色背景
"   45  设置紫色背景
"   46  设置青色背景
"   47  设置白色(灰色)背景
"   49  设置缺省黑色背景

"    其他有趣的代码还有:
"    \033[2J      清除屏幕
"    \033[0q      关闭所有的键盘指示灯
"    \033[1q      设置"滚动锁定"指示灯(Scroll Lock)
"    \033[2q      设置"数值锁定"指示灯(Num Lock)
"    \033[3q      设置"大写锁定"指示灯(Caps Lock)
"    \033[15:40H   把关闭移动到第15行,40列
"    \007        发蜂鸣生beep
"
"    scala语法高亮:
"    #!/bin/sh
"    mkdir -p ~/.vim/{ftdetect,indent,syntax}
"    for d in ftdetect indent syntax
"    do wget --no-check-certificate -O ~/.vim/$d/scala.vim
"    https://raw.githubusercontent.com/derekwyatt/vim-scala/master/$d/scala.vim;
"    done

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值