Showing posts with label vim. Show all posts
Showing posts with label vim. Show all posts

VIM IDE for C, Python and Go

VIM (Vi IMproved) ကို C, Python and Go IDE အျဖစ္အသံုးျပုခ်င္သူမ်ားအတြက္ config နဲ့ plugins ေတြကို ဒီ vim-config repo မွာ ရယူနိုင္ပါတယ္။

အသံုးျပုပံုနဲ့ screenshots အခ်ို့ကို ေအာက္ကလင့္မွာျကည့္နိုင္ပါတယ္။
C IDE Screenshots
Python IDE Screenshots
Project with VIM

NERD_tree demo -> click on Picture


NERD_tree.vim နဲ့ Project.vim plugins ေတြကိုနွစ္သက္ရာသံုးနိုင္ပါတယ္။

Enjoy! :-)

How to setup environment for Go

Go Programming Language ဟာ ဒီဆယ္စုနွစ္အတြင္းမွာ အသစ္ထြက္ေပာ္လာတဲ့ New Programming Language တစ္ခုပါ။ Developer ကေတာ့ Google ပါ။ Authors ေတြကေတာ့ Plan9 OS project က Rob Pike, Ken Thompson အပါအဝင္ Robert Griesemer နွင့္ အျခားပုဂဿဿဂုိလ္မ်ားျဖစ္ျကျပီး BSD-style License နဲ့ Open Source Distribution ျဖစ္ပါတယ္။
Go က C/C++ တို့လို Compiled Language ျဖစ္ျပီး gc (8g,6g) နဲ့ gccgo တို့က Go အတြက္ compilers ေတြျဖစ္ျကပါတယ္။ ေလာေလာဆယ္ေတာ့ Linux နဲ့ Mac OS မွာပဲ ဒီ compilers ေတြကိုအသံုးျပုနိုင္ပါေသးတယ္။
Go ကို ေလ့လာနိုင္ဖို့အတြက္ အဓိကေနနဲ့ Go compiler နဲ့ အျခားလိုအပ္တဲ့ programming environment programs ေတြပါ။ ဒါေတြကို go source ကေန့ Build လုပ္ဖို့အတြက္ ျပင္ဆင္ရေအာင္။ က်ေနာ္ကေတာ့ Debian GNU/Linux user ဆိုေတာ့ က်ေနာ့္ Linux x86 (386) မွာ ဘယ္လို setup လုပ္လဲဆိုတာ နမူနာအေနနဲ့ေရးမွာပါ။
ပထမဦးဆံုးအေနနဲ့ က်ေနာ္တို့ ~/.bashrc ဖိုင္မွာ Environment variables ေတြကို ေရးရေအာင္ ~/.bashrc ဖိုင္ကို gedit နဲ့ပဲျဖစ္ျဖစ္ ျကိုက္နွစ္သက္ရာ editor တစ္ခုခုနဲ့ပဲျဖစ္ျဖစ္ဖြင့္ျပီး ေအာက္က Environmnet variables ေတြကို ထည့္ျဖည့္ေရးေပးျပီး .bashrc ဖိုင္ကို သိမ္းျပီး ပိတ္လိုက္ပါ။

$ gedit ~/.bashrc

## Go Environment variables ##
export GOROOT=~/hg
export GOOS=linux
export GOARCH=386
export GOBIN=~/bin

ျပီးရင္ ~/.bashrc ဖိုင္ကို save ျပီး ပိတ္လိုက္ပါ။ ျပီးရင္ ေအာက္က command ကို Terminal ထဲမွာပဲ run ေပးပါ။

$ source ~/.bashrc

ျပီးရင္ Environment Variables ေတြက memory ထဲေရာက္ျပီးလား Test လုပ္ျကည့္ပါ။

$ env | grep '^GO'
GOBIN=/home/username/bin
GOARCH=386
GOROOT=/home/username/hg
GOOS=linux

အဲလိုအေပာ္က results ကိုေတြ့မွာပါ။ ဒါေပမယ့္က်ေနာ္တို့ ~/bin folder မရွိေသးရင္ mkdir နဲ့ folder လုပ္ေပးရပါမယ္။

## making 'bin' folder under your home directory ##
$ mkdir -p ~/bin

ျပီးရင္ mercurial ကိုသံုးျပီး go source files ေတြကို fetch မွာျဖစ္ပါတယ္။ က်ေနာ့္ Linux က Debian ျဖစ္သမို့ က်ေနာ္ apt ဒါမွမဟုတ္ aptitude ကိုသံုးျပီး mercurial ကို ေအာက္ကအတိုင္း install လုပ္ပါမယ္။ ခင္ဗ်ားမွာ mercurial ရွိျပီးသားဆိုရင္ေတာ့ install လုပ္စရာမလိုတဲ့အတြက္ ဒီအဆင့္ install လုပ္တဲ့အဆင့္ကိုေက်ာ္ျပီး go source files ကို fetch လုပ္နိုင္ပါျပီ။

## installing mercurial ##
$ sudo apt-get install mercurial

mercurial ကို install လုပ္ျပီးတဲ့အခါ က်ေနာ္တို့ go source files ေတြကိုရယူဖို့အတြက္ ေအာက္က command line ကို run ေပးပါမယ္။

## fetching go source files ##
$ hg clone -r release https://go.googlecode.com/hg/ $GOROOT

source files ေတြရျပီးရင္ အဲဒါေတြကို build လုပ္ဖို့အတြက္ လိုအပ္တာေလးေတြကို install လုပ္ေပးပါမယ္။

## installing gcc and others to build go source ##
$ sudo apt-get install bison gcc libc6-dev ed make

ျပီးရင္ Go Distributions ကို က်ေနာ္တို့ build ရေအာင္ ..

## building go distribution ##
$ cd $GOROOT/src
$ ./all.bash

တေအာက္ေလာက္ေစာင့္ေပးျပီးရင္ ေအာက္က results ကိုေတြ့မွာပါ။ အဲဒါဆိုရင္ building process က အဆင္ေျပျပီး go compiler ကိုသံုးလို့ရပါျပီး ..

--- cd ../test
0 known bugs; 0 unexpected bugs

အေသးစိတ္သိခ်င္ရင္ေတာ့ ဒီလင့္ခ္ ေလးကို သြားျပီးဖတ္ပါ။

vim မွာ go syntax highlight အတြက္ ကိုစိုးမင္းရဲ့ post ကိုသြားဖတ္နိုင္ပါတယ္။
ဒီမွာပဲတဆက္တည္းျကည့္လိုက္ရေအာင္ က်ေနာ္ေရးေပးလိုက္ပါတယ္။

## adding go syntax for vim editor ##
$ mkdir ~/.vim/
$ mkdir ~/.vim/syntax/
$ cp $GOROOT/misc/vim/go.vim ~/.vim/syntax/

## making and opening ~/.vimrc file ##
$ gedit ~/.vimrc

gedit နဲ့ ~/.vimrc ဖိုင္ပြင့္လာျပီးဆိုရင္ ေအာက္ကဟာေတြကို ကူးျပီးေရးျဖည့္ေပးလိုက္ျပီး သိမ္းျပီး ပိတ္ေပးလိုက္ပါ။

autocmd BufNewFile,BufRead *.go set filetype=go
:syntax on

ခုဆိုရင္ vim editor နဲ့ go programming language ကို syntax highlight ေတြနဲ့ေလ့လာနိုင္ပါျပီ။

Enjoy learning Go!

vim syntax on

Ubuntu မွာတုန္းက vim-full ကို install လုပ္ၿပီးလ်င္ vim syntax highlight က အလိုအေလွ်ာက္ on ၿပီးသားပါ။ ဒါေပမယ္႔ က်ေနာ္႔ debian lenny မွာ အလိုအေလွ်ာက္ on ျဖစ္မေနအတြက္ က်ေနာ္ .vimrc ဖိုင္ကို အသစ္လုပ္ေပးၿပီး on ရပါတယ္။ လုပ္ပံုကေတာ႔ Terminal ထဲမွာ ေအာက္ကအတုိင္း vim နဲ႔ပဲ အဲဒီဖိုင္အသစ္ကိုေဆာက္ေပး လိုက္ပါတယ္။ ၿပီရင္ အဲဒီဖိုင္ထဲမွာ ':syntax on' ဆိုၿပီးရိုက္ထည့္ေပးလိုက္ပါတယ္။ ေအာက္မွာ Terminal ထဲမွာ ရိုက္တဲ႔ command line နဲ႔ ဖိုင္ထဲမွာ ရိုက္ထည့္ထားတာကို ေတြ႕ရမွာပါ။

$ vim ~/.vimrc

[caption id="attachment_118" align="alignnone" width="480" caption=".vimrc file"].vimrc file[/caption]

ၿပီးရင္ ဖိုင္ကို သိမ္းဆည္းၿပီးပိတ္ပါ။ အဲဒီဖိုင္ေလး effect ျဖစ္ဖို႔အတြက္ Logout လုပ္ေပးလိုက္ပါ။ Login ျပန္ၿပီး vim နဲ႔ source file ေတြျပန္ဖြင္႔တဲ႔အခါ syntax highlighting on ေနတာ ေတြ႕ရပါလိမ္႔မယ္။

[caption id="attachment_119" align="alignnone" width="480" caption="syntax on"]syntax on[/caption]

အကယ္၍ run time မွာပဲ syntax off ခ်င္တယ္ဆိုရင္ vim ကို ':syntax off' command ေပးလိုက္လ်င္ syntax highlight off ျဖစ္သြားမွာပါ။

[caption id="attachment_120" align="alignnone" width="480" caption="syntax off"]syntax off[/caption]

vim ရဲ႕ မ်က္စိေအးတဲ႔ syntax highlight color နဲ႔ code ေတြကို ေပ်ာ္ရႊင္စြာေရးႏိုင္ပါေစ .. :-)

compile && execute in gedit

Source code ေတြကို vim မွာေရးၿပီး Terminal မွာပဲ တခါတည္း compile & execute လုပ္တာက GUI အားသန္သူမ်ားအတြက္ မကိုက္လွပါဘူး။ စတင္သူမ်ားက gedit နဲ႔လုပ္ခ်င္မွာပဲေလ၊ လြယ္လဲ လြယ္ကူပါတယ္။ gedit ဟာ တကယ္႔ကို powerful text editor ျဖစ္တဲ႔အျပင္ သူ႔ရဲ႕ plugin ေတြသံုးၿပီး simple program ေလးေတြကိုပါ ေလ႔လာလို႔ရတဲ႔ powerful tool တစ္ခုျဖစ္ပါတယ္။ ဥပမာ C++ ကိုစတင္ေလ႔လာလိုသူမ်ားအတြက္ gedit ကိုသံုးၿပီး C++ source file ကို ဘယ္လို compile လုပ္ၿပီး execute လုပ္တယ္ဆိုတာ တင္ျပေပးမွာပါ။
အရင္ဦးဆံုး gedit plugin ျဖစ္တဲ႔ External Tools ကို Activate လုပ္ရေအာင္ ..
gedit ကိုဖြင္႔ပါ .. Edit > Preferences ကို သြားပါ .. gedit Preferences Window ေလးေပၚလာ မယ္ .. Plugins Tab ကို ဆက္သြားမယ္ .. အဲဒီမွာ External Tools plugin ကို check box မွာ mark လုပ္ေပးၿပီး Activate လုပ္ေပးပါ [see:fig-1] ..

[caption id="attachment_122" align="alignnone" width="480" caption="Figure 1"]Figure 1[/caption]

ၿပီးရင္ gedit > Tools > External Tools ကိုဖြင္႔ပါ .. External Tools Manager Window [see:fig.3] ေလးေပၚလာမယ္ .. အဲဒီမွာ Tools အသစ္ႏွစ္ခုကို New buttom ေလးသံုးၿပီးေတာ႔ ထည့္ေပးရေအာင္ .. ပထမတစ္ခုကို "Compile C++" ႏွင္႔ ေနာက္တစ္ခုကိုက်ေတာ႔ "Run C++" လို႔နာမည္ေပးရေအာင္ .. ဒါေပမယ္႔ အဆင္ေျပသလို နာမည္ေပးႏိုင္ပါတယ္ .. အဓိကကေတာ႔ ကိုယ္သိဖို႔ပါပဲ [see:fig-2] ..

[caption id="attachment_123" align="alignnone" width="480" caption="Figure 2"]Figure 2[/caption]

Compile C++ အတြက္ျဖည့္ရမယ္႔ ဟာေတြကေတာ႔ ..
Description: Compile C++ by using g++
Accelerator: F5
Command(s): g++ $GEDIT_CURRENT_DOCUMENT_NAME -o ${GEDIT_CURRENT_DOCUMENT_NAME%.*}
Input: Nothing
Output: Insert in output panel
Applicability: All documents

Run C++ အတြက္ျဖည့္ရမွာကေတာ႔ ..
Description: Run C++
Accelerator: F6
Command(s): ./${GEDIT_CURRENT_DOCUMENT_NAME%.*}
Input: Nothing
Output: Insert in output panel
Applicability: All documents

အဲလိုျဖည့္ေပးလိုက္တဲ႔အတြက္ gedit မွာ C++ source code ကို view ၾကည့္ရာကေန F5 ႏွိပ္ေပးလိုက္ရင္ g++ က အဲဒီ source file ကို compile လုပ္ေပးၿပီး F6 ကို ႏွိပ္လိုက္ရင္ shell က execute လုပ္ေပးပါလိမ္႔မယ္။ ဒါမွမဟုတ္လဲ gedit > Tools ကိုသြားၿပီး dropdown menu ကေန Compile C++ နဲ႔ Run C++ တို႔ကို သံုးႏိုင္ပါတယ္။

Compiling C++ souce file
[caption id="attachment_124" align="alignnone" width="480" caption="Figure 3"]Figure 3[/caption]

Executing C++ program
[caption id="attachment_125" align="alignnone" width="480" caption="Figure 4"]Figure 4[/caption]

အကယ္၍ Terminal ထဲမွာပဲ compile && execute လုပ္ခ်င္လ်င္ေတာ႔ ..

$ g++ -o Sample Sample.cpp

$ ./Sample

Sample ဆိုတာက compile လုပ္ၿပီးရလာမယ္႔ output file (program) ပါ၊ Sample.cpp ကေတာ႔ input file (c++ source file) ပါ။ စတင္မယ္႔သူမ်ား အစျပဳႏိုင္ၿပီလို႔ ေမွ်ာ္လင္႔ပါတယ္ .. :-)