Vim (or MacVim) as a C/C++ IDE

This post is meant to be a little guide to setting up Vim (or MacVim) as your next favorite C/C++ IDE. Vim is probably the most powerful text editor that humans have ever created, so you should consider using it even if its learning curve is a bit steep.

MacVim


First, let’s install MacVim. MacVim adds a graphical interface to Vim that can help newcomers (only for OSX users, others should consider GVim). Skip the next steps if you want to use the regular Vim instead.
  • Get the latest snapshot of MacVim from here (make sure you have the correct OSX version).
  • Decompress it (double click) and drag MacVim.app to your Applications folder.
  • Open the Terminal (commonly located in /Applications/Utilities/Terminal.app, but I suggest you put it in your Dock) and go to the MacVim Snapshot folder you just downloaded. In my case, I had to type the following:
    cd ~/Downloads/MacVim-snapshot-73/
  • Copy the mvim binary to your PATH so that you can open MacVim from any directory in your computer. Like this (you will have to enter your machine password):
    sudo cp mvim /usr/bin
  • Now you should be able to start a new document with MacVim by typing:
    mvim hello.c
    (Type :w to quit).

.vimrc


Now that you have Vim (and/or MacVim) installed in your system, the next thing you should do is to set it up to adapt it to your needs. The rest of the instructions work for Vim and MacVim, so I will use Vim to refer to both (simply replace vim for mvim if you want to use MacVim). Vim is highly configurable, but here I will describe what I believe is the most useful setup for new users and C/C++ developers.
The Vim (or MacVim) configuration file is located in ~/.vimrc. Therefore, type vim ~/.vimrc to start editing your configuration. You might see a blank file if you have never edited Vim’s configuration before. You can copy and paste the following. There’s a comment for the most important commands, so that you can understand what these lines do if you are interested.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
" Enables highlight syntax
syntax enable
set nofoldenable
" Sweet colorscheme
" colorscheme codeschool
set background=dark
" Set utf8 as standard encoding and en_US as the standard language
set encoding=utf-8
"" Display line numbers on the left
set number
"" Use mouse (only for resizing!)
set mouse=a
" Set the focus to the correct screen (ok, no more mouse thingies)
set mousefocus
" No more annoying sounds
set visualbell
" Do not scroll sideways unless we reach the end of the screen
set sidescrolloff=0
" highlight the status bar when in insert mode
if version >= 700
    if has("gui_running")
        au InsertEnter * hi StatusLine guifg=black guibg=green
        au InsertLeave * hi StatusLine guibg=black guifg=grey
    else
        au InsertEnter * hi StatusLine ctermfg=235 ctermbg=2
        au InsertLeave * hi StatusLine ctermbg=240 ctermfg=12
    endif
endif
" Infere the case-sensitivity
set infercase
" Need to set this flag on in order to have many cool features on
set nocompatible
" Indent properly based on the current file
filetype indent plugin on
filetype plugin on
" Pathogen load
"filetype off " Makes syntax non-working on office box
call pathogen#infect()
call pathogen#helptags()
" Switch between files in buffer
nnoremap :bn
nnoremap :bp
" Change default fontsize to fit MacBook Pro 13'
set guifont=Monaco:h11
" Don't select first Omni-completion option
set completeopt=longest,menuone
"set completeopt=menuone,longest,preview
set tabstop=4     " a tab is four spaces
set backspace=indent,eol,start
                  " allow backspacing over everything in insert mode
set autoindent    " always set autoindenting on
set copyindent    " copy the previous indentation on autoindenting
set shiftwidth=4  " number of spaces to use for autoindenting
set shiftround    " use multiple of shiftwidth when indenting with '<' and '>'
set incsearch     " show search matches as you type
set expandtab
set shiftwidth=4
set softtabstop=4
" Always set the current file directory as the local current directory
autocmd BufEnter * silent! lcd %:p:h
" Enable folding
nnoremap @=(foldlevel('.')?'za':"\")
vnoremap zf
set history=1000         " remember more commands and search history
set undolevels=1000      " use many levels of undo
" Tabs in command line mode behave like bash
set wildmode=longest,list,full
set wildmenu
" Highlight the entire word when searching for it
set hlsearch
"====[ Make tabs, trailing whitespace, and non-breaking spaces visible ]======
exec "set listchars=tab:\uBB\uBB,trail:\uB7,nbsp:~"
set list
" Move line by line even when the line is wrapped
map j gj
map k gk
" Persistent undo
set undofile                " Save undo's after file closes
set undodir=$HOME/.vim/undo " where to save undo histories
set undolevels=1000         " How many undos
set undoreload=10000        " number of lines to save for undo
" YouCompleteMe
let g:ycm_global_ycm_extra_conf = "~/.vim/bundle/YouCompleteMe/.ycm_extra_conf.py"
nnoremap g :YcmCompleter GoToDefinitionElseDeclaration

Plugins


Now it’s time to install some plugins. We will start with Pathogen, a script to make the installation of other scripts extremely easy. To install Pathogen, just type:
mkdir -p ~/.vim/autoload ~/.vim/bundle
curl https://raw.githubusercontent.com/tpope/vim-pathogen/master/autoload/pathogen.vim > ~/.vim/autoload/pathogen.vim
Using Pathogen, we will install Syntastic, a wonderful plugin to identify errors in your code (linting) in the most popular programming languages. To install it, just type:
cd ~/.vim/bundle && \
git clone https://github.com/scrooloose/syntastic.git
Now restart Vim and type :Helptags. Linting should be working now for C/C++.
The next plugin to install is MiniBufExplorer, which will make our life easier when dealing with multiple files in Vim. To install it, simply type:
cd ~/.vim/bundle && \
git clone https://github.com/fholgado/minibufexpl.vim.git
We also want to have some auto complete options when developing our C/C++ programs. The best plugin I’ve found is called YouCompleteMe, which is compatible with basically all the most popular programming languages to date. Type the following to install it:
cd ~/.vim/bundle && \
git clone https://github.com/Valloric/YouCompleteMe.git
cd YouCompleteMe
git submodule update --init --recursive
./install.sh --clang-completer
Note: You might need to install Homebrew to install YouCompleteMe. To install it, type:

ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
You will need to do some additional setup in order to get the plugin working. As you may see in the second to last line of the .vimrc above, we set up the default configuration file in ~/.vim/bundle/YouCompleteMe/.ycm_extra_conf.py. You can simply copy my .ymc_extra_conf.py in this folder. To do so, simply type:
curl http://urinieto.com/drop/.ycm_extra_conf.py > ~/.vim/bundle/YouCompleteMe/.ycm_extra_conf.py
Finally, the last plugin to install is the C Plugin, which will help us when navigating through C/C++ files, debugging, etc. This plugin does not support Pathogen installation, so we will have to do it manually. Go to the official plugin page: http://www.vim.org/scripts/script.php?script_id=213 and download the latest cvim.zip. Copy the zip file to your ~/.vim/folder and type:
unzip cvim.zip
Before we are done, you should configure the template file with your name and affiliation. To do so, edit the template file and edit the user macros, like this:
vim ~/.vim/c-support/templates/Templates
My User Macros look like this:

§ ==========================================================
§ User Macros
§ ==========================================================
SetMacro( 'AUTHOR', 'Oriol Nieto' )
SetMacro( 'AUTHORREF', '' )
SetMacro( 'COMPANY', 'New York University' )
SetMacro( 'COPYRIGHT', '' )
SetMacro( 'EMAIL', 'oriol@nyu.edu' )
SetMacro( 'LICENSE', '' )
SetMacro( 'ORGANIZATION','New York University' )
If you’ve done everything correctly, you will be able to create a new .c file (e.g. vim hello.c and a nice template will be included in the top of the file. Moreover, you should be able to open multiple files (e.g. :e otherfile.c) and they will appear in the MiniBufferExplorer. And finally, if you make some errors while coding, Syntastic will tell you. As an example, see the following screenshot:
MacVim with the following plugins: Syntastic, YouCompleteMe, C.vim, and MiniBufExplorer
MacVim with the following plugins: Syntastic, YouCompleteMe, C.vim, and MiniBufExplorer

Please, let me know if you have any questions. I hope you enjoy your new IDE!

把自己的.bash_profile和.vimrc丟進去 on MAC

把自己的.bash_profile和.vimrc丟進去
LANG=zh_TW.UTF-8
export LANG
export CLICOLOR=1
export LSCOLORS=dxfxcxdxbxegedabagacad
PS1='\[\033[1;33m\]\u\[\033[1;37m\]@\[\033[1;32m\]\h\[\033[1;37m\]:\[\033[1;31m\]\w \[\033[1;36m\]\$ \[\033[0m\]'
export PS1

Compiling PJSIP

Compiling PJSIP


Steps to Compile PJSIP latest version 1.10

STEP 1. Download source code from one of the following link :



STEP 2. Set your config_site.h to the following:

#define PJ_CONFIG_IPHONE 1 
#include  

The pjlib/include/pj/config_site.h contains local customizations to the libraries. The simplest way is just to create an empty file, to use whatever default values set by the libraries. Or copy and paste the config_site_sample.h file and delete all its content and copy above two lines.

This will activate iPhone specific settings in the config_site_sample.h.

Note: When the Makefile based build system is used, this process is taken care by the Makefiles. But when non-Makefile based build system (such as Visual Studio) is used, the config_site.h file must be created manually.
STEP 3. To Build PJSIP
Just run:
$ cd /path/to/your/pjsip/dir
$ ./configure-iphone 

Their may be following problems: 

  • Permission denied 
       Solution: login as super user using su command and the type following command
       $ su
       Password:
       # chmod 777 configure-iphone
       # exit

The permission to the file configure-iphone will be set as rwx (read-write-execute) for all.

  • Again running the ./configure-iphone may give following error 
        -bash: ./configure-iphone: /bin/bash^M: bad interpreter: No such file or directory

(This error may come because in the configure-iphone file every line may have been appended by a character $ or may be a carriage return symbol)
        To check this do as:
        - Run command
          $ vim configure-iphone
          (It wil open the vim editor)
          To see the last character press escape(ESC:)set list
          To quit vim press Esc:q

        - To Eliminate 
           $ tr -d '\r' FILE.new
(It will create new file with name FILE. Now after that delete the configure-iphone file and rename FILE to configure-iphone using the following commands:)

         $ rm configure-iphone
         $ mv FILE.new configure-iphone
(Again confirm that new created file has 777 permission if no then assign from su- super user)

        - Again run
        $ ./configure-iphone

  • Again there may be error in ./aconfigure: Permission denied 
        Solution : Assign 777 permission to the whole folder. 
       - $ cd .. (Go to the parent folder in which the PJSIP folder lies)
       - $ su (login as super user)
       - # chmod 777 * (It will assign 777 permission to the whole folder and its content)

Again run $ ./configure-iphone command. This time every thing should work fine. 


STEP 4. After getting message "Done configuring for iPhoneOS4.1.sdk" run following command
     - $ make dep


STEP 5. If every thing is successfull then run following command

     - $ make


(After executing above 5 steps successfully the C files will produce the object .o files for pjlib,pjmedia,pjnath etc. and there .a liabraries that are included into the project and used.)

什麼都不是

感恩師佛的加持與教導

感恩所有的佛菩薩護法金剛的加持與教導
--------------------------------------------------------
自己什麼都不是,也不是什麼。

來首『什麼都不是的什麼』

夢來夢去,何處停留?
追來追去,何物長久?

怨天怨地,誰是阿我?
讚天讚地,誰是阿我?
歡天喜地,誰是阿我?

何物能長久?何事能停留?

我是什麼!什麼是我!

光明心中流,流入大性海。


心內求法

感恩師佛的加持與教導

感恩蓮極上師的教導
------------------------------------
我想從今以後不會在去跑道場了。也沒甚們道場好去跑的。

除了,師尊在台灣每周六的法會外,我不會在去其他的道場了。

好好專心在家實修吧!

很感謝蓮極上師給柏雄的當頭棒喝,

此話怎解,11/29參加完師尊的法會後,帶著三位師姐一起去卦山雷藏寺。

見到了蓮極上師,上師開口就說,11/22帶女兒來示威?

我哈哈哈大笑,我說:帶來皈依師尊的。

蓮極說:你女兒的面相不錯。我笑笑沒回應。

沒想到提到上師做麵包的事情,

蓮極:問我妳吃過我做的麵包嗎?

我說:吃過一次。

蓮極:感覺怎樣?

我說:有古老的味道。

蓮極一直笑的說:你知道甚麼是古老的味道?
你這年紀會知道甚麼是古老的味道。

蓮極:那你說古老是甚麼味道?

我:啞口無言。

蓮極:這不就是呼巄我。

我就一直傻笑。

同修完後,回到家裡。

我在壇城前痛哭,原來到現在,我還是無法真誠的面對自己的心。

我很難過,很悲傷,師尊的真佛宗,最重要的""字,

也是最簡單的事情,我都做不好。

不好吃就不好吃,沒味道就說沒味道,何必敷衍ㄋ!!!!!!!!!!!!!!!!!!!!!

所以我很感謝蓮極上師提點我一下,

此後,我應該要好好聽聽內在的聲音。這就是心內求法的重點。

感恩

阿彌陀佛















夢裡如現實~

感恩師佛的加持與教導

感恩三根本的加持攝受護持
---------------------------------------
如夢似幻的人生,

就像泡影般漸漸消散,

心目中的自己,

現實中的自己,

睡夢中的自己,

何時認得清?

緣分該是好好珍惜的,

一個念頭的上下,千千萬萬的世界在於你自己的變化!

左右一個念頭,刻不刻意,難說的清,

柏雄不想成就,但是也不斷在精進修~

柏雄不想成佛,但是也不斷念念清靜~

哈!感念師尊的加持與教導!


蓮花一妍的皈依

感恩師佛的加持與教導

感恩諸如來護法的加持與教導
-----------------------------------------
2014年11月22日是王妍的皈依聖尊蓮生活佛的日子,

也是蓮花柏雄的國曆生日~

一樣還是感恩~

如果有人問我,你到底會甚麼?

我說真的,我甚麼都不會!

真的要講出一樣的話!

我只能說,我只會祈禱!

如此而已~感恩在感恩!


大白蓮花童子的咒輪

感恩師佛的加持與教導

感恩諸佛菩薩的加持與教導
----------------------------------------
2014年11月16日

這天是偉大的聖尊蓮生活佛歸國弘法的日子,

想不到,

在前一天的夢中,虛空界已經有歡迎的車隊,列隊歡迎,

抬頭一看虛空,好大好大的大白蓮花童子的咒輪唷!

殊勝殊勝~

感恩師尊的不持辛勞的一日復一日的弘法,

眾生才有一盞明燈可以照亮千年之暗室!

師尊~蓮花柏雄~不敢忘去誓言~也不知道該如何忘記誓言!

生生世世的皈依,無不是尋求一盞明燈,原來明燈早已經在心中!

望著心中的明燈,心心相印!

輪迴是苦,而且苦不堪言!

輪迴是樂,總是樂此不疲!

師尊您說是吧!

感念一切的眾生!感念自己的貪嗔癡疑慢!

阿彌陀佛


感恩

感恩聖尊蓮生活佛

感恩多聞天王黃財神及其所有眷屬
-----------------
連續修了兩三天的黃財神法,

感恩師佛的加持,黃財神的加持,及黃財神眷屬的加持!

今天,連宇公司寄了聘用任職的書給我,看來柏雄還真會唬爛唷!

總之,即來之則安之,願意用我的人,我當盡心盡力!

不管出世間入世間都一樣!

感恩~師佛的真佛密法的殊勝!感恩諸佛菩薩護法的感應!

阿彌陀佛!

虹光大成就-密教灌頂(一)