• Vim配置C++


    当前用户的Vim配置便存储在文件 ~/.vimrc 中,该文件的每一行便是一个配置项

    设置自动换行,在配置文件中加入如下代码:

    syntax on
    set tabstop=4
    set softtabstop=4
    set shiftwidth=4
    set expandtab
    set autoindent
    set cindent
    set cinoptions={0,1s,t0,n-2,p2s,(03s,=.5s,>1s,=1s,:1s
    set nu
    set ruler

     ps:    set nonu 就是不显示行号

    Vundle

    参考:http://zuyunfei.com/2013/04/12/killer-plugin-of-vim-vundle/

    下载vundle:

    git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle

    在.vimrc 中添加:

    set nocompatible                " be iMproved
    filetype off                    " required!
    set rtp+=~/.vim/bundle/vundle/
    call vundle#rc()
    
    " let Vundle manage Vundle
    Bundle 'gmarik/vundle'
    
    "my Bundle here:
    "
    " original repos on github
    Bundle 'kien/ctrlp.vim'
    Bundle 'sukima/xmledit'
    Bundle 'sjl/gundo.vim'
    Bundle 'jiangmiao/auto-pairs'
    Bundle 'klen/python-mode'
    Bundle 'Valloric/ListToggle'
    Bundle 'SirVer/ultisnips'
    Bundle 'Valloric/YouCompleteMe'
    Bundle 'scrooloose/syntastic'
    Bundle 't9md/vim-quickhl'
    " Bundle 'Lokaltog/vim-powerline'
    Bundle 'scrooloose/nerdcommenter'
    "..................................
    " vim-scripts repos
    Bundle 'YankRing.vim'
    Bundle 'vcscommand.vim'
    Bundle 'ShowPairs'
    Bundle 'SudoEdit.vim'
    Bundle 'EasyGrep'
    Bundle 'VOoM'
    Bundle 'VimIM'
    "..................................
    " non github repos
    " Bundle 'git://git.wincent.com/command-t.git'
    "......................................
    filetype plugin indent on

    安装:vim +BundleInstall +qall

    等把插件都安装完,我等了很久,有些要翻出去才能装完

    YouCompleteMe

    参考:http://valloric.github.io/YouCompleteMe/#ubuntu-linux-x64

    装完上面的插件后,打开一个cpp文件,vim提示YouCompleteMe unavailable:…… 什么的,这个时候

    cd ~/.vim/bundle/YouCompleteMe
    ./install.py

    这个时候可能会提示没有哪个module什么的,而且出现了下面这条语句,恩,执行之

     git submodule update --init --recursive 

    遇到了这个:

    fatal: Needed a single revision 无法在子模组路径 'third_party/ycmd/third_party/OmniSharpServer' 中找到当前版本

    这个时候删除掉那个文件夹即可

    等了很久,翻出去才全部下载完

    然后再执行

    ./install.py

    出现如下错误:

     pyconfig.h: 没有那个文件或目录

    找到了这个网址:https://github.com/okfn/piati/issues/65

    执行  sudo apt-get install python-dev libxml2-dev libxslt-dev 

    完成后再尝试

    ./install.py

    终于可以正常安装了,等它安装完,这个时候再打开一个cpp,会出现代码补全提示了,差不多算是搞定了?

    关闭预览,草稿

    安装完这一波插件,会自动补全了,但是会出现很恶心的预览,草稿啥的乱七八糟的占据屏幕上方一大截。

    这个时候就要用 :set completeopt=menu ,记得写在vimrc中

    注释

    如果上面的vundle中的插件都装成功了的话,nerdcommenter就是用来注释的

    <leader>cc   加注释
    <leader>cu   解开注释
    
    <leader>c<space>  加上/解开注释, 智能判断
    <leader>cy   先复制, 再注解(p可以进行黏贴)

    这里的<leader>默认是 ,不过有点远 ,可以自己设置,在配置文件中加入一条 let mapleader="," 将<leader>换成" , ”

    编译运行

    参考:http://www.cnblogs.com/ma6174/archive/2011/12/10/2283393.html

    在配置文件中加入代码

    map <F5> :call CompileRunGcc()<CR>
    func! CompileRunGcc()
        exec "w" 
        if &filetype == 'c' 
            exec "!g++ % -o %<"
            exec "! ./%<"
        elseif &filetype == 'cpp'
            exec "!g++ % -o %<"
            exec "! ./%<"
        endif
    endfunc

    即可按F5一键编译运行,写了个hello world 能用 ,不过应该还有一些问题,以后再折腾

    编译C++11

    g++ -std=c++11 test.cpp

    如果里面没有C++11的东西,直接g++ test.cpp 也是可以的,就会出来一个a.out的文件,然后 ./a.out 就能看到执行结果了

  • 相关阅读:
    Codeforces Round #344 (Div. 2) C. Report 其他
    Codeforces Round #344 (Div. 2) B. Print Check 水题
    Codeforces Round #344 (Div. 2) A. Interview 水题
    8VC Venture Cup 2016
    CDOJ 1280 772002画马尾 每周一题 div1 矩阵快速幂 中二版
    CDOJ 1280 772002画马尾 每周一题 div1 矩阵快速幂
    CDOJ 1279 班委选举 每周一题 div2 暴力
    每周算法讲堂 快速幂
    8VC Venture Cup 2016
    Educational Codeforces Round 9 F. Magic Matrix 最小生成树
  • 原文地址:https://www.cnblogs.com/i-love-kobe/p/6091197.html
Copyright © 2020-2023  润新知