美文网首页
配置我的Vim

配置我的Vim

作者: 臻甄 | 来源:发表于2022-01-27 16:02 被阅读0次

    Step1:配置.vimrc文件

    vi ~/.vimrc
    

    Step2:将本文最后附加的内容拷贝进去,:wq保存退出

    Step3:安装插件管理器Vundle

    mkdir -p ~/.vim/bundle/
    git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
    vim
    # 以下操作在vim界面中执行
    :PluginList  # 遍历vimrc中的插件
    :PluginInstall  #安装插件,将逐个自动安装,请确保git clone可用
    :bdelete # 清除缓冲区缓存
    :PluginClean  #删除插件
    :PluginInstall!  #重新安装所有插件
    :h vundle 查看更多说明
    #我们也可以在不打开vim的情况下安装插件
    vim +PluginInstall +qall
    

    遇到过的问题

    (1)YouCompleteMe unavailable: requires Vim compiled with Python (3.6.0+) support.

    • 因为vim无法使用Python,mac可以通过brew重装vim,ubuntu可以通过Conda重装vim
    vim --version | grep python # 如果得到的结果 python 2/3前面是个-号,说明vim没法用Python
    brew install vim
    echo "alias vim=/opt/homebrew/bin/vim" >> ~/.bash_profile
    

    (2)The ycmd server SHUT DOWN (restart with ':YcmRestartServer'). YCM core library not detected; you need to compile YCM before using it. Follow the instructions in the documentation.

    • 因为YouCompleteMe这个插件需要到源仓库底下去编译,详见安装说明
    cd ~/.vim/bundle/YouCompleteMe
    /usr/bin/python3 install.py
    

    .vimrc

    set et
    set smarttab
    set smartindent
    set lbr
    set fo+=mB
    set sm
    set selection=inclusive
    set wildmenu
    set mousemodel=popup
    set t_Co=256
    set nocompatible
    filetype on
    
    
    "
    """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    " 显示相关
    """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    syntax on
    set shortmess=atI   " 启动的时候不显示那个援助乌干达儿童的提示
    set go=             " 不要图形按钮
    set guifont=Courier_New:h20:cANSI   " 设置字体
    set showcmd         " 输入的命令显示出来,看的清楚些
    set scrolloff=10     " 光标移动到buffer的顶部和底部时保持3行距离
    set foldenable      " 允许折叠
    set nocompatible  "去掉讨厌的有关vi一致性模式,避免以前版本的一些bug和局限
    set autoindent
    set cindent
    " Tab键的宽度
    set tabstop=4
    " 统一缩进为4
    set shiftwidth=4
    au FileType python setl sw=4 sts=4 et
    " 不要用空格代替制表符
    set expandtab
    " 在行和段开始处使用制表符
    set smarttab
    " 显示行号
    set number
    " 历史记录数
    set history=1000
    "搜索逐字符高亮
    set hlsearch
    set incsearch
    "语言设置
    set langmenu=zh_CN.UTF-8
    set helplang=cn
    " 总是显示状态行
    set cmdheight=2
    " 侦测文件类型
    filetype on
    " 载入文件类型插件
    filetype plugin on
    " 为特定文件类型载入相关缩进文件
    filetype indent on
    " 保存全局变量
    set viminfo+=!
    "将tab替换为空格
    nmap tt :%s/\t/    /g<CR>
    
    
    
    """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    """""新文件标题
    """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    "新建.c,.h,.sh,.java文件,自动插入文件头
    autocmd BufNewFile *.cpp,*.[ch],*.sh,*.rb,*.java,*.py exec ":call SetTitle()"
    ""定义函数SetTitle,自动插入文件头
    func SetTitle()
        "如果文件类型为.sh文件
        if &filetype == 'sh'
            call setline(1,"\#!/bin/bash")
            call append(line("."), "cd \"$(dirname \"$0\")\"")
        elseif &filetype == 'python'
            call setline(1,"#!/usr/bin/env python")
            call append(line("."),"# coding=utf8")
            call append(line(".")+1, "# File: ".expand("%"))
            "call append(line(".")+2, "# Author: likejiao(likejiao@baidu.com) ")
    
        else
            call setline(1, "/*************************************************************************")
            call append(line("."), "    > File Name: ".expand("%"))
            call append(line(".")+1, "    > Author:likejiao ")
            call append(line(".")+2, "    > Mail: likejiao@baidu.com")
            call append(line(".")+3, "    > Created Time: ".strftime("%c"))
            call append(line(".")+4, "    > Usage: ")
            call append(line(".")+5, " ************************************************************************/")
            call append(line(".")+6, "")
        endif
        if expand("%:e") == 'cpp'
            call append(line(".")+7, "#include<iostream>")
            call append(line(".")+8, "")
        endif
        if &filetype == 'c'
            call append(line(".")+7, "#include<stdio.h>")
            call append(line(".")+8, "")
        endif
        if expand("%:e") == 'h'
            call append(line(".")+7, "#ifndef _".toupper(expand("%:r"))."_H")
            call append(line(".")+8, "#define _".toupper(expand("%:r"))."_H")
            call append(line(".")+9, "#endif")
        endif
        "新建文件后,自动定位到文件末尾
    endfunc
    autocmd BufNewFile * normal G
    
    
    """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    "键盘命令
    """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    set mouse=
    
    "自动保存
    set autowrite
    set magic                   " 设置魔术
    set guioptions-=T           " 隐藏工具栏
    set guioptions-=m           " 隐藏菜单栏
    " 不要使用vi的键盘模式,而是vim自己的
    set nocompatible
    " 去掉输入错误的提示声音
    set noeb
    " 在处理未保存或只读文件的时候,弹出确认
    set confirm
    "禁止生成临时文件
    set nobackup
    set noswapfile
    "搜索忽略大小写
    set ignorecase
    
    
    
    
    set linespace=0
    " 增强模式中的命令行自动完成操作
    set wildmenu
    " 使回格键(backspace)正常处理indent, eol, start等
    set backspace=2
    " 允许backspace和光标键跨越行边界
    set whichwrap+=<,>,h,l
    set selection=exclusive
    " 在被分割的窗口间显示空白,便于阅读
    set fillchars=vert:\ ,stl:\ ,stlnc:\
    " 高亮显示匹配的括号
    set showmatch
    " 匹配括号高亮的时间(单位是十分之一秒)
    set matchtime=1
    " 光标移动到buffer的顶部和底部时保持3行距离
    set scrolloff=3
    " 为C程序提供自动缩进
    filetype plugin indent on
    
    set iskeyword+=.
    set termencoding=utf8
    set encoding=utf8
    set fileencodings=utf8,ucs-bom,utf8,cp936,gb2312,gb18030
    
    
    set rtp+=~/.vim/bundle/vundle/
    call vundle#rc()
    
    " My Plugins here:
    Plugin 'altercation/vim-colors-solarized'
    Plugin 'Auto-Pairs'
    Plugin 'ctrlp.vim'
    Plugin 'Yggdroot/indentLine'
    Plugin 'vim-airline/vim-airline'
    Plugin 'vim-airline/vim-airline-themes'
    Plugin 'Valloric/YouCompleteMe'
    "Plugin 'ycm-core/YouCompleteMe'
    Plugin 'Konfekt/FastFold'
    Plugin 'gmarik/vundle'
    Plugin 'cespare/vim-toml'
    
    filetype plugin indent on     " required!
    let NERDTreeIgnore=['\.pyc']
    "配色
    "set background=dark
    let g:solarized_termcolors=256
    set background=light
    "colorscheme solarized
    "colorscheme Tomorrow
    "colorscheme molokai
    "colorscheme gruvbox
    
    if &bg == "dark" "根据你的背景色风格来设置不同的书签颜色
      highlight SignColor ctermfg=white ctermbg=blue guifg=wheat guibg=peru
     else             "主要就是修改guibg的值来设置书签的颜色
       highlight SignColor ctermbg=white ctermfg=blue guibg=grey guifg=RoyalBlue3
      endif
    "vim-airline 配置
    set laststatus=2
    
    "let g:airline_section_c = airline#section#create(["%{expand('%:p')}", ''])
    let g:airline_section_b = '%{strftime("%d/%m %H:%M")}'
    let g:airline_section_x = 'Anita'
    let g:airline_section_y = 'Action speaks louder than Words'
    "let g:airline_section_y = 'it is time to say goodbye,my old friend.'
    let g:jedi#use_tabs_not_buffers = 1
    let g:airline#extensions#whitespace#enabled = 0
    
    "pycheck
    "let g:pyflakes_use_quickfix = 0
    set guifont=Source\ Code\ Pro\ for\ Powerline:h14
    let g:airline_powerline_fonts = 1
    let g:Powerline_symbols = 'luna'
    "let g:airline_theme="wombat"
    let g:airline_theme="light"
    let g:airline_left_sep = '▶'
    let g:airline_left_alt_sep = '❯'
    let g:airline_right_sep = '◀'
    let g:airline_right_alt_sep = '❮'
    
    " airline的所有符号设置
    if !exists('g:airline_symbols')
        let g:airline_symbols={}
    endif
    
    let g:airline_symbols.linenr = '¶'
    let g:airline_symbols.branch = '⎇'
    let g:airline_symbols.paste = 'ρ'
    let g:airline_symbols.whitespace = 'Ξ'
    
    "let g:airline_left_sep = '»'
    "let g:airline_right_sep = '«'
    "let g:airline_symbols.linenr = '␊'
    "let g:airline_symbols.linenr = '
    '
    "let g:airline_symbols.linenr = '¶'
    "let g:airline_symbols.branch = '⎇'
    "let g:airline_symbols.paste = 'Þ'
    "let g:airline_symbols.paste = '∥'
    set undofile
    
    
    """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    " => YouCompleteMe  代码自动补全
    """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    " disable preview window when autocomplete
    set completeopt-=preview
    "YouCompleteMe
    let g:ycm_path_to_python_interpreter = '/usr/bin/python3'
    
    "补全
    autocmd FileType python setlocal completeopt-=preview
    
    let g:acp_enableAtStartup = 0
    
    " Define keyword.
    inoremap <silent> <CR> <C-r>=<SID>my_cr_function()<CR>
    function! s:my_cr_function()
      return pumvisible() ? "\<C-y>" : "\<CR>"
    endfunction
    inoremap <expr><TAB>  pumvisible() ? "\<C-n>" : "\<TAB>"
    "let g:pymode_lint_checkers = ['pyflakes']
    
    
    
    set shiftwidth=4
    set tabstop=4
    au FileType python setl sw=2 sts=2 et
    " 不要用空格代替制表符
    set expandtab
    " 在行和段开始处使用制表符
    set smarttab
    " 显示行号
    set number
    " 历史记录数
    if has("autocmd")
      au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
    endif
    

    参考: https://blog.csdn.net/amoscykl/article/details/80616688

    相关文章

      网友评论

          本文标题:配置我的Vim

          本文链接:https://www.haomeiwen.com/subject/nzxkzktx.html