zoukankan      html  css  js  c++  java
  • 新vim配置文件

      1 "******************************************************特殊设置**********************************************************
      2 if strftime("%H") < 19                      "时间在7:00前
      3     colorscheme guodesert
      4 elseif strftime("%H") > 18                  "时间在19:00后
      5     colorscheme guodesert
      6     else                                    "时间在7:00~19:00之间
      7     colorscheme github
      8 endif
      9 "autocmd InsertLeave * set nocul            "浅色显示高亮行,离开时关闭
     10 autocmd InsertLeave * set nocuc             "浅色显示高亮行,离开时关闭
     11 autocmd InsertEnter * set cul               "浅色显示高亮行,进入时浅色显示打开
     12 autocmd InsertEnter * set cuc               "浅色显示高亮行,进入时浅色显示打开
     13
     14 let &t_SI = "<Esc>]50;CursorShape=0x7"
     15 let &t_EI = "<Esc>]50;CursorShape=1x7"
     16 "******************************************************特殊设置**********************************************************
     17 syntax on                                   "语法高亮
     18 filetype indent on                          "文件类型侦测
     19 filetype plugin on                          "文件类型插件启用
     20 match OverLength /\%109v.+/
     21 "******************************************************选项设置**********************************************************
     22 set autochdir                           "自动切换当前目录为当前文件所在的目录
     23 set autoindent                          "插入模式下输入<cr>或使用"o""O"命令开新行,从当前行复制缩进距离
     24 set cindent                             "使用C/C++的缩进方式缩进
     25 set autoread                            "当文件在外部被修改时,自动重新读取
     26 set autowrite                           "自动保存文件
     27 set completeopt=preview,menu
     28 set complete+=k                         "关键字补全,扫描 'dictionary' 选项给出的文件
     29 "set comments                           "关键字补全,扫描 'dictionary' 选项给出的文件
     30 set cursorline                          "突出显示当前行
     31 set foldlevel=99                        "设置折叠级别: 高于此级别的折叠会被关闭
     32 set foldclose=all                       "设置为自动关闭折叠
     33 set foldenable                          "开始折叠
     34 set foldmethod=syntax                   "语法高亮项目指定折叠
     35 set foldcolumn=0                        "设置折叠区域的宽度,显示折叠列
     36 set history=512                         "命令的历史和最近搜索模式的历史被记住。本项决定分别记多少项历史
     37 set hlsearch                            "搜索时高亮显示被找到的文本
     38 set helplang=cn                         "设置帮助语言
     39 set ignorecase                          "搜索模式里忽略大小写
     40 set smartcase                           "搜索模式里包含大写字符,不使用ignorecase选项
     41 set incsearch                           "输入搜索命令时,显示目前输入的模式的匹配位置。匹配的字符串被高亮
     42 set iskeyword+=_,$,@,%,#,-              "带有这些字符的单词不要被换行分割
     43 set mousehide                           "在输入时隐藏鼠标指针,移动鼠标时恢复指针
     44 set nocompatible                        "关闭vi兼容模式
     45 set noexpandtab                         "不用空格展开<Tab>
     46 set nosplitbelow                        "窗口的分割会把新窗口放到当前窗口之下
     47 set nosplitright                        "窗口的分割会把新窗口放到当前窗口之右
     48 set number                              "在每行前面显示行号
     49 set numberwidth=3                       "行号使用的最小列数
     50 "set rulerformat =%65(%2*%<%=最近修改: \%{strftime("%H:%M",getftime(expand("%")))} | 光标: \%l行 %c%V列 | 比例:%p%%%)
     51 set rulerformat =%75(%2*%<%=字符: \%b | 修改: \%{strftime("%H:%M",getftime(expand("%")))} | 光标: \%l行 %c%V列 | \%Y \%M \%R %p%% | 编号: \%n\%)
     52 set scrolloff=1                         "光标上下两侧最少保留的屏幕行数
     53 set showcmd                             "在屏幕最后一行显示 (部分的) 命令
     54 set showmode                            "在插入、替换和可视模式里,在最后一行提供消息
     55 set showmatch                           "插入括号时,短暂地跳转到匹配的对应括号
     56 set matchtime=5                         "短暂跳转到匹配括号的时间
     57 set shiftwidth=4                        "(自动)缩进每一步使用的空白数目
     58 "set smartindent                        "开启新行时使用智能自动缩进
     59 set softtabstop=4                       "执行插入时,<Tab>算作空格的数目,可以改为4
     60 "set rtp+=/usr/lib/python3.6/site-packages/powerline/bindings/vim/ "启用powerline, laststatus=2
     61 set laststatus=1                        "2总显示最后一个窗口的状态行,1窗口多于一个时显示最后一个窗口的状态行,0不显示最后一个窗口的状态行
     62 set tabstop=4                           "执行插入时,<Tab>算作空格的数目,可以改为4
     63 set t_Co=256                            "开启vim的256颜色支持
     64 set textwidth=122                       "设定文本的宽度为122个字符时自动断行
     65 set virtualedit+=block                  "在可视模式下可以选择一个方块
     66 set wrap                                "设置文本达到textwidth宽度时自动换行,但实际文件还是一行
     67 set wildignore+=*.svn                   "文件名补全时忽略.svn
     68 set wildmenu                            "'wildmenu'打开时,命令行补全以增强模式运行
     69 set wildmode=list:full                  "用'widechar'指定的字符所用的补全模式
     70 set visualbell
     71 "set completeopt=longest,menu
     72 "set nobackup                           "覆盖文件时不备份
     73 "set writebackup                        "覆盖文件时自动备份
     74 "set hidden                             "放弃时隐藏缓冲区
     75 "set novisualbell                       "不使用可视响铃
     76 "set backspace=2                        "使用回格键
     77 "set backspace=indent,eol,start         "影响 <BS>、<Del>、CTRL-W和CTRL-U在插入模式下的工作方式
     78 "set noswapfile                         "没有交换文件
     79 "set fencs=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936 "设置编码
     80 "以下用的比较少,酌情选择
     81 "set formatoptions+=q                   "描述自动排版如何进行的字母序列
     82 "set formatoptions+=r
     83 "set formatoptions+=n
     84 "set formatoptions+=1
     85 "set colorcolumn=+1
     86 "set columns=108                        "设置文本达到columns宽度时自动换行
     87 "set list                               "让tab显示成>-------->--------
     88 "set listchars=tab:>-,trail:-,extends:>,precedes:<      "配合上边的语句完成
     89 "set nowrap                             "设置文本达到textwidth宽度时不自动换行
     90 "set sidescrolloff=5                    "如果设置'nowrap',光标左右两侧保留的最少屏幕列数
     91 "set sidescroll=2                       "水平滚动时滚动的最少列数
     92 "set background=dark                    "设置背景为暗色
     93 "set cmdheight=2                        "设定命令行的行数为1
     94 "set cursorcolumn                       "突出显示当前列
     95 "set undofile                           "持久撤销功能
     96 "set ruler                              "显示状态栏标尺
     97 set tags+=./tags
     98 set tags=~/WORKM/ANDROID_SRC/
     99 "******************************************************选项设置**********************************************************
    100
    101 "******************************************************杂项设置**********************************************************
    102 ab psvm public static void main                 "试试缩写好用吗
    103 let NERDTreeQuitOnOpen=1
    104 let NERDTreeDirArrows=0
    105 let NERDTreeWinSize=40
    106 let NERDRemoveExtraSpaces=0
    107 let g:bufExplorerDisableDefaultKeyMapping = 1
    108 let g:acp_behaviorKeywordCommand = "<C-o>"
    109 let g:acp_behaviorKeywordLength = -1
    110 let g:acp_behaviorFileLength = -1
    111 let g:SuperTabDefaultCompletionType = "<c-n>"
    112 let g:SuperTabLongestHighlight = 1
    113 let g:tagbar_sort=0
    114 let g:tagbar_compact=1
    115 let g:tagbar_foldlevel=1
    116 let g:tagbar_iconchars=['+', '-']
    117 let OmniCpp_SelectFirstItem = 2
    118 let OmniCpp_ShowPrototypeInAbbr = 1
    119 let OmniCpp_MayCompleteScope = 1
    120 "******************************************************杂项设置**********************************************************
    121
    122 "======================================================跳转位置==========================================================
    123 if has("autocmd")                       "打开文件时,自动跳转到光标最后所在的位置
    124    au BufReadPost * if line("'"") > 0 && line("'"") <= line("$")
    125      | exe "normal! g'"" | endif
    126 endif
    127 "######################################################跳转位置##########################################################
    128
    129 "======================================================添加注释==========================================================
    130 "将键盘上的F10功能键映射为添加作者信息,版权声明,文件信息,代码说明等
    131     map <F10> :call TitleDet()<cr>
    132
    133 "添加文件信息
    134   function AddTitle()
    135     call append(0,"/* *=+=+=+=+* *** *=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=")
    136     call append(1,"  * 作者代号: *** :guochaoxxl")
    137     call append(2,"  * 版权声明: *** :(魎魍魅魑)GPL3")
    138     call append(3,"  * 联络信箱: *** :guochaoxxl@gmail.com")
    139     call append(4,"  * 文档用途: *** :深入理解C指针")
    140     "call append(4,"  * 文档用途: *** :数据结构与算法--C语言描述")
    141     call append(5,"  * 文档信息: *** :".expand("%:p:~"))
    142     call append(6,"  * 修订时间: *** :".strftime("%Y年第%W周 %m月%d日 %A %p%I:%M (%j天)"))
    143     call append(7,"  * 代码说明: *** :自行添加")
    144     call append(8," * *+=+=+=+=* *** *+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+*/")
    145   endfunction
    146
    147 "更新最近修改时间和文件名
    148   function UpdateTitle()
    149     normal m'
    150     execute '/修订时间:/s@:.*$@=strftime(": *** *%Y年第%W周 %m月%d日 %A %p%I:%M (%j天)")@'
    151     normal ''
    152     normal mk
    153     execute '/文档信息:/s@:.*$@=": *** :".expand("%:p:~")@'
    154     execute "noh"
    155     normal 'k
    156   endfunction
    157
    158 "判断前10行代码里面,是否有Last modified这个单词;
    159 "如果没有,需要添加作者信息;
    160 "如果有,只需要更新必要的信息即可;
    161   function TitleDet()
    162     let n=1
    163     "默认为添加
    164     while n < 10
    165         let line = getline(n)
    166         if line =~ '^  **s*S*修订时间:S*.*$'
    167         "更新注释信息
    168         call UpdateTitle()
    169             return
    170         endif
    171         let n = n + 1
    172     endwhile
    173     "添加注释信息
    174     call AddTitle()
    175   endfunction
    176
    177 "======================================================添加注释==========================================================
    178
    179 "======================================================编译运行==========================================================
    180 "通过键盘F9映射快速实现编译与运行
    181   map <F9> :call CompileRun()<cr>
    182   function CompileRun()
    183     exec "w"
    184     if &filetype == 'c'
    185     exec "!gcc -g  % -o %<"
    186     exec "!%<"
    187     elseif &filetype == 'cpp'
    188     exec "!g++ -g % -o %<"
    189     exec "!%<"
    190     elseif &filetype == 'java'
    191     exec "!javac %"
    192     exec "!java %<"
    193     else
    194     exec "echo not support filetype!"
    195     endif
    196   endfunction
    197
    198 "======================================================编译运行==========================================================
    199
    200 "######################################################自动补全##########################################################
    201 :inoremap ( ()<ESC>i
    202 :inoremap ) <c-r>=ClosePair(')')<CR>
    203 :inoremap } {}
    204 :inoremap { {<CR>}<ESC>O
    205 :inoremap } <c-r>=ClosePair('}')<CR>
    206 :inoremap [ []<ESC>i
    207 :inoremap ] <c-r>=ClosePair(']')<CR>
    208 :inoremap " ""<ESC>i
    209 ":inoremap ' ''<ESC>i
    210 function ClosePair(char)
    211     "if getline('.')[col('.') - 1 ] == a:char
    212     if getline('.') == a:char
    213     return "<Right>"
    214     else
    215     return a:char
    216     endif
    217 endfunction
    218
    219 function CloseLPair(char)
    220     "if getline('.')[col('.') - 1 ] == a:char
    221     if getline('.') == a:char
    222     return "<Left>"
    223     else
    224     return a:char
    225     endif
    226 endfunction
    227 "######################################################自动补全##########################################################
    228
    229 "====================================================##按键映射==========================================================
    230 map e ea
    231 "map e ea                               "移动到单词结尾时就自动进入插入模式
    232 "map + <C-w>+                           "增减窗口尺寸
    233 "map _ <C-w>-
    234 map + <C-w><                            "增减窗口尺寸
    235 map _ <C-w>>
    236 map <silent> <F2> :NERDTreeToggle<cr>               "tarbar functon list
    237 map <silent> <F3> :TagbarToggle<cr>             "header and implement file switch
    238 map <F4> :A<cr>                         "update index
    239 map <F5> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q<cr><cr>:cs kill cscope.out<cr>:!cscope -Rb<cr><cr>:cs add cscope.out<cr>        "switch display invisable ch    ar or not
    240 map <F6> :set list!<cr>:set list?<cr>               "highlight
    241 map <F7> ms:%s /<<C-R>=expand("<cword>")<CR>>//gn<cr>`    "swapfile list
    242 map <silent> <F8> :BufExplorer<CR>              "comment visual line
    243 nmap <C-[>g :cs find g <C-R>=expand("<cword>")<CR><CR>      "list the funcion called by this function
    244 nmap <C-[>d :cs find d <C-R>=expand("<cword>")<CR><CR>      "list the position where to call this word
    245 nmap <C-[>c :cs find c <C-R>=expand("<cword>")<CR><CR>      "search word in the project
    246 nmap <C-[>s :cs find s <C-R>=expand("<cword>")<CR><CR>      "search word in the project and the word can be in text
    247 nmap <C-[>t :cs find t <C-R>=expand("<cword>")<CR><CR>      "search word in the project and the word can be in text, support regex
    248 nmap <C-[>e :cs find e <C-R>=expand("<cword>")<CR><CR>      "list the file which filename is this word
    249 nmap <C-[>f :cs find f <C-R>=expand("<cfile>")<CR><CR>      "list the file include the file which filename is this word
    250 nmap <C-[>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>    "list the file which include this file
    251 nmap <C-[>I :cs find i <C-R>=expand("%:t")<CR><CR>
    252 "nnoremap j gj                          "自动换行时可在行中移动
    253 "nnoremap k gk
    254 nnoremap <C-h> <C-w>h                       "在分割的窗口间移动
    255 nnoremap <C-j> <C-w>j
    256 nnoremap <C-k> <C-w>k
    257 nnoremap <C-l> <C-w>l
    258 noremap <S-h> :bp<cr>                       "在buffer间移动
    259 noremap <S-l> :bn<cr>
    260 "用空格键来开关折叠
    261 nnoremap <space> @=((foldclosed(line('.')) < 0) ? 'zc' : 'zo')<CR>
    262 vnoremap <silent> , :call NERDComment(1, "alignLeft")<cr>   "uncomment visual line
    263 vnoremap <silent> . :call NERDComment(1, "uncomment")<cr>   "show list if more tag
    264
    265 if has("cscope")
    266     set nocsverb
    267     if filereadable("cscope.out")
    268         cs add cscope.out
    269     endif
    270 endif
    271 "======================================================按键映射==========================================================

      可以参考思路,自己再次实现。

  • 相关阅读:
    (转)关于c#中的事件
    MySql数据库--持续记录ing
    在Eclipse中通过JDBC连接MySQL步骤,非常详细!
    mybatis传入参数类型parameterType和输出结果类型resultType详解
    关于JDBC访问存储过程的问题
    Mybatis(一)入门
    [Redis] 基于redis的分布式锁
    分布式锁----浅析redis实现
    MyBatis的增删改查操作
    C3P0连接池工具类实现步骤及方法
  • 原文地址:https://www.cnblogs.com/guochaoxxl/p/7648899.html
Copyright © 2011-2022 走看看