DarkMatter in Cyberspace
  • Home
  • Categories
  • Tags
  • Archives

C++ Develop Environment with vim on Linux


ctags

Install

$ sudo apt-get install exuberant-ctags

Usage

$ cd $PROJECT_HOME
$ ctags -R *
$ vi MyApp.cpp

Some frequently used shortcuts:

  • Go to definition: Ctrl-]

  • Jump back from definition: Ctrl-t

  • C-w C-]: Open the definition in a horizontal split

  • C-o/i: jump between items in jump list;

  • gf: "go to file", open the file under the cursor;

  • gd: "go to definition", go to the definition of a variable;

Ref: http://stackoverflow.com/questions/563616/vim-and-ctags-tips-and-tricks

Buffer explorer

Install

  1. Download bufexplorer-7.4.2.zip from it's website;

  2. unzip it to ~/.vim/bundle/ (you have to install pathogen before hand);

  3. restart vim;

Usage

:h buffer-explorer

be, bs, bv

I defined my key to comma(let mapleader=",") in .vimrc, so open buffer explorer window with ",be".

Tagbar

This plugin is for C/C++ code outline.

Installation: Downlaod majutsushi-tagbar-v2.6.1-0-ge872e67.zip from it's website, unzip to ~/.vim/bundle/ and restart vim.

:h tagbar

:TagbarToogle to open outline window; try , p, in outline window.

c.vim

Download cvim.zip v6.1.1 from its website. Unzip it to ~/.vim/bundle.

Add the following line to ~/.vimrc to override the default key:

let g:C_MapLeader  = ','

Use ",rc" to save and compile. Use :cn, :cp, :cfirst, :clast, :cc, :cclose, :copen to traverse in quickfix list (see :h quickfix for full list of hotkeys).

Use F9 or ",rr" to run source file.

Use "2. Usage without GUI" and " 3. Hotkeys" in :h csupport for full list of hotkeys.

Configuration for REPL

  1. Add ":nnoremap :make %:r && ./%:r" to ~/.vimrc;

  2. Open vim, copy the following c++ codes into it:

    using namespace std;

    int main() { cout << "hello C++.\n"; }

  3. Save the file, syntastic(search tag syntastic for installation and usage details) will report an error: ‘cout’ was not declared in this scope

  4. Add "#include " at the beginning of the file, save it, and press , you can see the result;



Published

Apr 29, 2014

Last Updated

Apr 29, 2014

Category

Tech

Tags

  • C++ 12
  • ctags 1
  • Linux 158
  • vim 92

Contact

  • Powered by Pelican. Theme: Elegant by Talha Mansoor