神级编辑器VIM配置文件给.vimrc

Posted weimin1314

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了神级编辑器VIM配置文件给.vimrc相关的知识,希望对你有一定的参考价值。

"TNERDTree settings 
" " 打开vim自动打开目录树
"autocmd vimenter * NERDTree
" " 关闭文件后,如果只剩目录树窗口,则直接关闭
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree")) | q | endif
" " F2键开启/关闭目录树
map <F2> :NERDTreeToggle<cr>
" " 将目录树窗口设置在左边
let g:NERDTreeWinPos="left"
" " 设置目录树窗口宽度为30
let g:NERDTreeWinSize=30
" " 显示目录树窗口行号
let g:NERDTreeShowLineNumbers=1



"--------------------------------------------------
"                     YCM
"--------------------------------------------------

" 菜单
highlight Pmenu ctermfg=2 ctermbg=3 guifg=#005f87 guibg=#EEE8D5
" 选中项
highlight PmenuSel ctermfg=2 ctermbg=3 guifg=#AFD700 guibg=#106900
let g:ycm_server_python_interpreter=‘/usr/bin/python‘
let g:ycm_global_ycm_extra_conf=‘~/.vim/.ycm_extra_conf.py‘

  " YCM 查找定义
let mapleader=‘,‘
nnoremap <leader>gl :YcmCompleter GoToDeclaration<CR>
nnoremap <leader>gf :YcmCompleter GoToDefinition<CR>
nnoremap <leader>gg :YcmCompleter GoToDefinitionElseDeclaration<CR>
let g:ycm_collect_identifiers_from_tags_files = 1

set completeopt=menu,menuone
let g:ycm_add_preview_to_completeopt = 0  " 关闭函数原型提示

let g:ycm_show_diagnostics_ui = 0 " 关闭诊断信息
let g:ycm_server_log_level = ‘info‘
let g:ycm_min_num_identifier_candidate_chars = 2  " 两个字符触发 补全
let g:ycm_collect_identifiers_from_comments_and_strings = 1 " 收集
let g:ycm_complete_in_strings=1

noremap <c-z> <NOP>
let g:ycm_key_invoke_completion = ‘<c-z>‘   " YCM 里触发语义补全有一个快捷键
let g:ycm_max_num_candidates = 15  " 候选数量

let g:ycm_semantic_triggers =  {
                         ‘c,cpp,python,java,go,erlang,perl‘: [‘re!w{2}‘],
                         ‘cs,lua,javascript‘: [‘re!w{2}‘],
                         }

"----------------------------------------
"              ctags: ctags -R
"----------------------------------------
if filereadable("tags")
        set tags=tags
endif


"------------------------------------------------------
"                       实用设置
"------------------------------------------------------
set nu

" 为C程序提供自动缩进
set smartindent

"自动补全
: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
                return "<Right>"
        else
                return a:char
        endif
endfunction

"--------------------------------------------------------
          "新建.c,.h,.sh,.java文件,自动插入文件头
"--------------------------------------------------------
autocmd BufNewFile *.cpp,*.[ch],*.sh,*.java exec ":call SetTitle()"
""定义函数SetTitle,自动插入文件头
func SetTitle()
        "如果文件类型为.sh文件
        if &filetype == ‘sh‘
                call setline(1,"#########################################################################")
                call append(line("."), "# File Name: ".expand("%"))
                call append(line(".")+1, "# Author: velma")
                call append(line(".")+2, "# mail: velmajia@163.com")
                call append(line(".")+3, "# Created Time: ".strftime("%c"))
                call append(line(".")+4, "#########################################################################")
                call append(line(".")+5, "#!/bin/bash")
                call append(line(".")+6, "")
        else
                call setline(1, "/*************************************************************************")
                call append(line("."), "      > File Name: ".expand("%"))
                call append(line(".")+1, "      > Author:velma")
                call append(line(".")+2, "      > Mail: velmajia@163.com ")
                call append(line(".")+3, "      > Created Time: ".strftime("%c"))
                call append(line(".")+4, " ************************************************************************/")
                call append(line(".")+5, "")
         endif
         if &filetype == ‘cpp‘
                 call append(line(".")+6, "#include <iostream>")
                 call append(line(".")+7, "using namespace std;")
                 call append(line(".")+8, "")
         endif
         if &filetype == ‘c‘
                 call append(line(".")+6, "#include <stdio.h>")
                 call append(line(".")+7, "")
         endif
         "       if &filetype == ‘java‘
         "               call append(line(".")+6,"public class ".expand("%"))
         "               call append(line(".")+7,"")
         "       endif
         "新建文件后,自动定位到文件末尾
 "       autocmd BufNewFile * normal G
 endfunc
 "新建文件后,自动定位到文件末尾
 autocmd BufNewFile * normal G




set nocompatible              " 这是必需的 
filetype off                  " 这是必需的 
set rtp+=~/.vim/bundle/Vundle.vim
" vundle初始化 
call vundle#begin()
" 让 Vundle 管理 Vundle, 必须
Plugin ‘VundleVim/Vundle.vim‘
Plugin ‘tpope/vim-fugitive‘
Plugin ‘rstacruz/sparkup‘, {‘rtp‘: ‘vim/‘}
Plugin ‘ascenator/L9‘, {‘name‘: ‘newL9‘}
Plugin ‘scrooloose/nerdtree‘
Plugin ‘Valloric/YouCompleteMe‘

call vundle#end()            " 这是必需的 
filetype plugin indent on    " 这是必需的 



let g:ycm_server_python_interpreter=‘/usr/bin/python‘
let g:ycm_global_ycm_extra_conf=‘~/.vim/.ycm_extra_conf.py‘







" ***************** 全局设置 ************** "
"保持文件上次打开的位置
if has("autocmd")                                                          
    au BufReadPost * if line("‘"") > 1 && line("‘"") <= line("$") | exe "normal! g‘"" | endif 
endif 
" 开启文件类型侦测
filetype on
" 根据侦测到的不同类型加载对应的插件
filetype plugin on

" 自动缩进
filetype indent on

" 开启语法高亮功能
syntax enable
" 允许用指定语法高亮配色方案替换默认方案
syntax on

"----------配置----------------
set history=1000 "设置历史记录
set nobackup    "取消自动备份,禁止生成临时文件
set noswapfile 
set nocompatible "关闭兼容模式
set incsearch "开启实时搜索功能
set ignorecase "搜索忽略大小写
set wildmenu "vim命令自动补全
set autoread "文件自动更新
set gcr=a:block-blinkon0 "禁止关闭闪烁
set laststatus=2 "总是显示状态栏
set ruler "显示光标位置
set number "显示行号
set relativenumber "显示相对行号
set cuc "浅色显示当前行
set cul "浅色显示当前行
set showcmd "输入的命令显示出来
set cmdheight=2 "命令行高度
set nofoldenable
set foldmethod=manual "允许手动折叠
set backspace=2 "回退键生效
"set backspace=indent,eol,start
set novisualbell

" 禁止显示滚动条
set guioptions-=l
set guioptions-=L
set guioptions-=r
set guioptions-=R

" 禁止显示菜单和工具条
set guioptions-=m
set guioptions-=T

" 将制表符扩展为空格
set expandtab
" 设置编辑时制表符占用空格数
set tabstop=4
" 设置格式化时制表符占用空格数
set shiftwidth=4
" 让 vim 把连续数量的空格视为一个制表符
set softtabstop=4
" 基于缩进或语法进行代码折叠
set foldmethod=syntax
" 启动 vim 时关闭折叠代码
set nofoldenable
" 交互式打开shell
set shell=bash -i


" *************** 设置全局快捷键 *****************

" 定义快捷键的前缀,即<Leader>
"let mapleader="<space>"
let mapleader="‘"

" 设置快捷键将选中文本块复制至系统剪贴板
vnoremap <Leader>y "+y

" 设置快捷键将系统剪贴板内容粘贴至 vim
nmap <Leader>p "+p

" 定义快捷键关闭当前分割窗口
nmap <Leader>q :q<CR>

" 定义快捷键保存当前窗口内容
nmap <Leader>w :w<CR>

" 定义快捷键保存所有窗口内容并退出 vim
"nmap <Leader>WQ :wa<CR>:q<CR>

" 不做任何保存,直接退出 vim

 

以上是关于神级编辑器VIM配置文件给.vimrc的主要内容,如果未能解决你的问题,请参考以下文章

vimrc文件配置的全文收录(史上最全,附带中文解释)

Vim:Vim入门级配置

linux下.vimrc的配置

04 .vimrc文件配置

Vim入门级配置介绍

Vim(Linux编辑器)简单配置和常用命令