zoukankan      html  css  js  c++  java
  • vim的语法高亮及配置文件说明

    本文主要针对那些刚刚入门的菜鸟,老手请自动忽略,谢谢。
    一、安装vim:
    sudo pacman -S vim 随后根据提示输入超级用户密码即可完成安装
    二、配置自己的语法高亮文件,主要是修改~/.vimrc,也就是自己所在用户目录的根目录下,该文件是vim的配置文件,是个隐藏文件,需要使用按下f8才能看到这个文件。

    一些说明:(1)配置文件中以"开始的行都是被注释掉的,实际是没有什么用的,以备下次的启用所以保留,如果你有代码洁癖,可以尽管删除;2)我的vim配置文件非常丰富,如果你不需要这么多功能,请根据说明,几乎很快就可以快速实现自己的配置文件,
            (3)都是模块化,添加就能使用的,
            (4)请务必按照自己的实际情况修改,否则可能有版权纠纷,而且对使用的人非常不利,哈哈
    1、不同时段启动不同的颜色主题,根据自己的需要即可,下面的配置是从早上8点到19点使用github主题,主要是背景是亮色的,适合白天,其他时段是暗色主题
    "***********************************************不同时段启动不同的颜色主题**************************************************
    if strftime("%H") < 8                           "时间在8:00前
        colorscheme guodesert
    elseif strftime("%H") > 19                      "时间在19:00后
        colorscheme guodesert
                    else                            "时间在7:00~19:00之间
        colorscheme github
    endif
    "***********************************************不同时段启动不同的颜色主题**************************************************
    2、在不同模式下让提示符和高亮行和列的不同,便于浏览或编辑文件,具体看注释,根据自己的需求定制即可
    "******************************************************特殊设置**********************************************************
    "autocmd InsertLeave * set nocul                "浅色显示高亮行,离开时关闭
    autocmd InsertLeave * set nocuc                 "浅色显示高亮行,离开时关闭
    autocmd InsertEnter * set cul                   "浅色显示高亮行,进入时浅色显示打开
    autocmd InsertEnter * set cuc                   "浅色显示高亮行,进入时浅色显示打开
    
    let &t_SI = "<Esc>]50;CursorShape=0x7"
    let &t_EI = "<Esc>]50;CursorShape=1x7"
    "******************************************************特殊设置**********************************************************
    3、使用bundle管理vim插件,先占着位置,回头补上
    "*******************************************************插件管理*********************************************************
    "set rtp+=~/.vim/bundle/Vundle
    "call vundle#rc()
    "Bundle 'gmarik/vundle
    "*******************************************************插件管理*********************************************************
    4、vim的基础设置几乎都在这里了,假如你需要语法高亮,就将语法高亮行加进来即可,具体看注释,根据自己的需求定制即可
    "******************************************************选项设置**********************************************************
    syntax on                               "语法高亮
    filetype indent on                      "文件脚本自动缩进 
    filetype plugin on                      "文件类型特定脚本缩进 
    highlight OverLength ctermbg=red ctermfg=white guibg=#592929
    "highlight OverLength ctermbg=red ctermfg=white 
    match OverLength /\%109v.+/        
    set completeopt=longest,menu
    "set list                               "tab显示成>-------->--------
    "set listchars=tab:>-,trail:-,extends:>,precedes:<      "配合上边的语句完成
    set nocompatible                        "关闭vi兼容模式
    set t_Co=256                            "开启vim的256颜色支持
    set nobackup                            "覆盖文件时不备份
    set autoindent                          "插入模式下输入<cr>或使用"o""O"命令开新行,从当前行复制缩进距离
    set shiftwidth=4                        "(自动)缩进每一步使用的空白数目
    set softtabstop=4                       "执行插入时,<Tab>算作空格的数目,可以改为4
    set noexpandtab                         "不用空格展开<Tab>
    set scrolloff=1                         "光标上下两侧最少保留的屏幕行数
    set sidescrolloff=5                     "如果设置'nowrap',光标左右两侧保留的最少屏幕列数
    set sidescroll=1                        "水平滚动时滚动的最少列数
    set showcmd                             "在屏幕最后一行显示 (部分的) 命令
    set showmode                            "在插入、替换和可视模式里,在最后一行提供消息
    set hidden                              "放弃时隐藏缓冲区
    set wildmenu                            "'wildmenu'打开时,命令行补全以增强模式运行
    set wildmode=list:full                  "用'widechar'指定的字符所用的补全模式
    set novisualbell                        "不使用可视响铃
    set number                              "在每行前面显示行号
    set numberwidth=3                       "行号使用的最小列数
    set ignorecase                          "搜索模式里忽略大小写
    set smartcase                           "搜索模式里包含大写字符,不使用ignorecase选项
    set incsearch                           "输入搜索命令时,显示目前输入的模式的匹配位置。匹配的字符串被高亮
    set hlsearch                            "搜索时高亮显示被找到的文本
    set showmatch                           "插入括号时,短暂地跳转到匹配的对应括号 
    set matchtime=5                         "短暂跳转到匹配括号的时间
    set textwidth=122                       "设定文本的宽度为122个字符时自动断行
    "set columns=75                         "设置文本达到columns宽度时自动换行
    set wrap                                "设置文本达到textwidth宽度时自动换行,但实际文件还是一行
    "set nowrap                             "设置文本达到textwidth宽度时不自动换行
    set complete+=k                         "关键字补全,扫描 'dictionary' 选项给出的文件
    set history=255                         "命令的历史和最近搜索模式的历史被记住。本项决定分别记多少项历史 
    set wildignore+=*.svn                   "文件名补全时忽略.svn 
    set nosplitbelow                        "窗口的分割会把新窗口放到当前窗口之下
    set nosplitright                        "窗口的分割会把新窗口放到当前窗口之右
    "set background=dark                    "设置背景为暗色
    set virtualedit+=block                  "在可视模式下可以选择一个方块
    set autoread                            "当文件在外部被修改时,自动重新读取
    set autowrite                           "自动保存文件
    "set cmdheight=2                        "设定命令行的行数为1
    "set cursorcolumn                       "突出显示当前列
    set autochdir                           "自动切换当前目录为当前文件所在的目录
    set helplang=cn                         "设置帮助语言
    set iskeyword+=_,$,@,%,#,-             "带有这些字符的单词不要被换行分割
    set backspace=2                         "使用回格键
    set backspace=indent,eol,start          "影响 <BS>、<Del>、CTRL-W和CTRL-U在插入模式下的工作方式
    set noswapfile                          "没有交换文件
    "set undofile                           "持久撤销功能
    set foldlevel=99                        "设置折叠级别: 高于此级别的折叠会被关闭
    set foldclose=all                       "设置为自动关闭折叠 
    set foldenable                          "开始折叠
    set foldmethod=syntax                   "语法高亮项目指定折叠
    set foldcolumn=0                        "设置折叠区域的宽度,显示折叠列
    set cursorline                          "突出显示当前行
    set ruler                               "显示状态栏标尺
    set rulerformat =%33(%2*%<%=修改:\%{strftime("%H:%M",getftime(expand("%")))} 光标:\%l行 %c%V列 %p%%%)
    set fencs=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936          "设置编码
    set formatoptions+=q                    "描述自动排版如何进行的字母序列
    set formatoptions+=r
    set formatoptions+=n
    "set formatoptions+=1
    "set colorcolumn=+1 
    set smartindent                         "开启新行时使用智能自动缩进
    
    
    "******************************************************选项设置**********************************************************
    
    "======================================================添加注释==========================================================
    "将键盘上的F10功能键映射为添加作者信息的快捷键 进行版权声明的设置
        map <F10> :call TitleDet()<cr>  
    "添加文件信息
      function AddTitle()
        call append(0,"/* *=+=+=+=+* *** *=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=")
        call append(1,"  * 作者代号: *** :guochaoxxl")
        call append(2,"  * 版权声明: *** :(魎魍魅魑)GPL3")
        call append(3,"  * 联络信箱: *** :guochaoxxl@gmail.com")
        "call append(4,"  * 文档用途: *** :C++探秘——68讲贯通C++练习代码")  
        "call append(4,"  * 文档用途: *** :设计模式其实很简单Java")  
        call append(4,"  * 文档用途: *** :深入理解C指针")  
        call append(5,"  * 文档信息: *** :".expand("%:p:~"))
        call append(6,"  * 修订时间: *** :".strftime("%Y年第%W周 %m月%d日 %A %p%I:%M (%j天)"))
        call append(7,"  * 代码说明: *** :自行添加")
        call append(8," * *+=+=+=+=* *** *+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+*/")
        "echohl WarningMsg | echo "Successful in adding the copyright." | echohl None
      endf
    "更新最近修改时间和文件名
      function UpdateTitle()
        normal m'
        execute '/修订时间:/s@:.*$@=strftime(": *** *%Y年第%W周 %m月%d日 %A %p%I:%M (%j天)")@'
        normal ''
        normal mk
        execute '/文档信息:/s@:.*$@=": *** :".expand("%:p:~")@'
        execute "noh"
        normal 'k
        "echohl WarningMsg | echo "Successful in updating the copy right." | echohl None
      endfunction
    "判断前10行代码里面,是否有Last modified这个单词,如果没有,需要添加作者信息;如果有,只需要更新即可
      function TitleDet()
        let n=1
    "更新注释信息
        while n < 10
            let line = getline(n)
            if line =~ '^  **s*S*修订时间:S*.:$'
            call UpdateTitle()
                return
            endif
            let n = n + 1
        endwhile
    "添加注释信息
        call AddTitle()
      endfunction  
    
    "======================================================添加注释==========================================================
    
    "======================================================编译运行==========================================================
    "通过键盘F9映射快速实现编译与运行 
      map <F9> :call CompileRun()<cr>
      function CompileRun()
        exec "w"
        if &filetype == 'c'
        exec "!gcc -g % -o %<"
        exec "!%<"
        elseif &filetype == 'cpp'
        exec "!g++ -g % -o %<"
        exec "!%<"
        elseif &filetype == 'java'
        exec "!javac %"
        exec "!java %<"
        else
        exec "echo not support filetype!"
        endif
      endfunction
    
    "======================================================编译运行==========================================================
    
    "******************************************************杂项设置**********************************************************
    "set tags=~/WORKM/ANDROID_SRC/
    
    ab psvm public static void main                 "试试缩写好用吗 
    let NERDTreeQuitOnOpen=1
    let NERDTreeDirArrows=0
    let NERDTreeWinSize=40
    let NERDRemoveExtraSpaces=0
    let g:bufExplorerDisableDefaultKeyMapping = 1
    let g:acp_behaviorKeywordCommand = "<C-o>"
    let g:acp_behaviorKeywordLength = -1
    let g:acp_behaviorFileLength = -1
    let g:SuperTabDefaultCompletionType = "<c-n>"
    let g:SuperTabLongestHighlight = 1
    let g:tagbar_sort=0
    let g:tagbar_compact=1
    let g:tagbar_foldlevel=1
    let g:tagbar_iconchars=['+', '-']
    let OmniCpp_SelectFirstItem = 2
    let OmniCpp_ShowPrototypeInAbbr = 1 
    let OmniCpp_MayCompleteScope = 1
    
    "******************************************************杂项设置**********************************************************
    
    "######################################################自动补全##########################################################
    :inoremap ( ()<ESC>i
    :inoremap ) <c-r>=ClosePair(')')<CR> 
    :inoremap { {<CR>}<ESC>O
    :inoremap } <c-r>=ClosePair('}')<CR> 
    :inoremap [ []<ESC>i
    :inoremap ] <c-r>=ClosePair(']')<CR> 
    :inoremap " ""<ESC>i
    ":inoremap ' ''<ESC>i
    function ClosePair(char) 
        "if getline('.')[col('.') - 1 ] == a:char
        if getline('.') == a:char 
        return "<Right>" 
        else 
        return a:char 
        endif 
    endfunction 
    
    "######################################################自动补全##########################################################
    
    "====================================================##按键映射==========================================================
    map e ea
    "map e ea                                   "移动到单词结尾时就自动进入插入模式
    map + <C-w>+                                "增减窗口尺寸
    map _ <C-w>-
    map <silent> <F2> :NERDTreeToggle<cr>               "tarbar functon list
    map <silent> <F3> :TagbarToggle<cr>             "header and implement file switch
    map <F4> :A<cr>                         "update index
    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 char or not
    map <F6> :set list!<cr>:set list?<cr>               "highlight
    map <F7> ms:%s /<<C-R>=expand("<cword>")<CR>>//gn<cr>`    "swapfile list
    map <silent> <F8> :BufExplorer<CR>              "comment visual line
    nmap <C-[>g :cs find g <C-R>=expand("<cword>")<CR><CR>      "list the funcion called by this function
    nmap <C-[>d :cs find d <C-R>=expand("<cword>")<CR><CR>      "list the position where to call this word
    nmap <C-[>c :cs find c <C-R>=expand("<cword>")<CR><CR>      "search word in the project
    nmap <C-[>s :cs find s <C-R>=expand("<cword>")<CR><CR>      "search word in the project and the word can be in text
    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
    nmap <C-[>e :cs find e <C-R>=expand("<cword>")<CR><CR>      "list the file which filename is this word
    nmap <C-[>f :cs find f <C-R>=expand("<cfile>")<CR><CR>      "list the file include the file which filename is this word
    nmap <C-[>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>    "list the file which include this file
    nmap <C-[>I :cs find i <C-R>=expand("%:t")<CR><CR>
    "nnoremap j gj                              "自动换行时可在行中移动
    "nnoremap k gk
    nnoremap <C-h> <C-w>h                       "在分割的窗口间移动
    nnoremap <C-j> <C-w>j
    nnoremap <C-k> <C-w>k
    nnoremap <C-l> <C-w>l
    noremap <S-h> :bp<cr>                       "在buffer间移动
    noremap <S-l> :bn<cr>
    "用空格键来开关折叠
    nnoremap <space> @=((foldclosed(line('.')) < 0) ? 'zc' : 'zo')<CR> 
    vnoremap <silent> , :call NERDComment(1, "alignLeft")<cr>   "uncomment visual line
    vnoremap <silent> . :call NERDComment(1, "uncomment")<cr>   "show list if more tag 
    
    if has("cscope") 
        set nocsverb
        if filereadable("cscope.out")
            cs add cscope.out
        endif
    endif
    
    "======================================================按键映射==========================================================
    
    "======================================================跳转位置==========================================================
    if has("autocmd")                               "打开文件时,自动跳转到光标最后所在的位置
       au BufReadPost * if line("'"") > 0 && line("'"") <= line("$")
         | exe "normal! g'"" | endif
    endif
    
    "######################################################跳转位置##########################################################
    其他的同上

    链接: https://pan.baidu.com/s/1o896P0e 密码: 4qev
    有童鞋反映不会使用,那就补充下,以下假如你将下载的vim.zip文件下载到了/home/zhangsan/ 目录中,解压后的的目录为/home/zhangsan/vim/,
    打开终端或yakuake,使用命令:
    1、cd vim
    2、cp -R .vim/ ..
    3、cp .vimrc ..
    4、vim testy.c此时应该就有语法高亮和行号了,此处应该加上热泪和掌声。

  • 相关阅读:
    javascript基础之两种函数的定义方法
    与input有关的一些操作
    SpringMVC(八) RequestMapping HiddenHttpMethodFilter
    SpringMVC(七) RequestMapping 路径中带占位符的URL
    SpringMVC(六) RequestMapping 路径中ant风格的通配符
    SpringMVC(五) RequestMapping 请求参数和请求头
    SpringMVC(四) RequestMapping请求方式
    SpringMVC(三) RequestMapping修饰类
    SpringMVC(二) SpringMVC Hello World
    SpringMVC(一) SpringMVC概述
  • 原文地址:https://www.cnblogs.com/guochaoxxl/p/6823110.html
Copyright © 2011-2022 走看看