Home > c, linux, vim > vim dengan c code completion

vim dengan c code completion

1. Install vim dan ctags

root@constantine:~# apt-get install vim ctags
Reading package lists… Done
Building dependency tree
Reading state information… Done
vim is already the newest version.
Note, selecting exuberant-ctags instead of ctags
The following NEW packages will be installed:
exuberant-ctags
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 131kB of archives.
After this operation, 287kB of additional disk space will be used.
Get:1 http://mirror.its.ac.id sid/main exuberant-ctags 1:5.8-1 [131kB]
Fetched 131kB in 0s (2,362kB/s)
Selecting previously deselected package exuberant-ctags.
(Reading database … 142613 files and directories currently installed.)
Unpacking exuberant-ctags (from …/exuberant-ctags_1%3a5.8-1_i386.deb) …
Setting up exuberant-ctags (1:5.8-1) …

2. Edit file konfigurasi vim, dan tambahkan baris2 dibawah ini dengan editor kesukaan anda [sementara ini kesukaan saya adalah mc]

root@constantine:~# mcedit /etc/vim/vimrc
autocmd FileType python set omnifunc=pythoncomplete#Complete
autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS
autocmd FileType html set omnifunc=htmlcomplete#CompleteTags
autocmd FileType css set omnifunc=csscomplete#CompleteCSS
autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags
autocmd FileType php set omnifunc=phpcomplete#CompletePHP
autocmd FileType c set omnifunc=ccomplete#Complete

3. Buat ctags sesuai library yg anda inginkan.
Sebagai contoh, saya ingin membuat CTAGS dari header yang dimiliki SDK Nvidia CUDA.

root@constantine:~# ctags -R -f /home/lqman/.vim/cuda.ctags /usr/local/cuda/include/

4. Tambahkan ctags agar bisa diload vim secara otomatis. Pada contoh ini saya hanya ingin user lqman yg menggunakan ctags yg telah dibuat.

lqman@constantine:~/Desktop$ vim /home/lqman/.vimrc
set tags +=~/.vim/cuda.ctags

5. Cobalah membuat program baru, dan saat mengetik coba lakukan pencarian code completion dengan menekan tombol “Ctrl+n” lalu pilihlah fungsi yg anda inginkan.

lqman@thesisbox:~$ vim tes.c
#include
int main()
{
int a;
for (a=1; a<10; a++)
{
printf("Nilai A = %d\n",a);
}
do
{
a–;
printf("a=%d\n",a);
}while(a);
return 0;
}

Happy code-completing.
thx to :
Cak Kholis : http://blog.its.ac.id/kholis

referensi :
http://helmi-blebe.blogspot.com/2007/12/turn-vim-omni-completion-on.html

Advertisements
  1. umek1
    5 October 2011 at 4:51 am

    root@constantine:~# ctags -R -f /home/lqman/.vim/cuda.ctags /usr/local/cuda/include/

    i can’t found “.vim/” in my home directory…
    just find .viminfo
    what should i do?

    thx b4
    sorry 4 being noob ==a

  2. 6 October 2011 at 7:30 am

    @umek1 :
    you should create the directory manually.
    btw, thx 4 the comment.

  3. 21 October 2011 at 11:49 am

    owh… cr8 manual to.. woke.. thx gan.. @.@

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: