Configuring your own vim

Posted 2009/06/09 11:44 by kdsoo

Description TBD

set tags=./tags,/usr/src/linux/tags,/usr/include/tags
set number

set csprg=/usr/bin/cscope
set csto=0
set cst
set mouse=a
set nocsverb
set encoding=utf-8
"set sw=4
"set tabstop=8
"set expandtab
set autoindent
set cindent
set smartindent
set ruler
set wmnu
set lpl
set ic
set scs
set sc
set sm
set sel=exclusive

abbr #b /*********************************************************
abbr #e *********************************************************/

"color advantage
color impact

if $LANG[0] == 'k' && $LANG[1] == 'o'
set fileencoding=korea
endif

if &t_Co > 2 || has("gui_running")
    syntax on
    set hlsearch
endif

if &term=="xterm"
    set t_Co=8
    set t_Sb=^[[4%dm
    set t_Sf=^[[3%dm
endif

if filereadable("./cscope.out")
        cs add cscope.out
else
        cs add /home/share/linux/cscope.out
endif
set csverb

if version >= 500
func! Sts()
        let st = expand("<cword>")
        exe "sts ".st
endfunc
nmap ,st :call Sts()<cr>

func! Tj()
        let st = expand("<cword>")
        exe "tj ".st
endfunc
nmap ,tj :call Tj()<cr>
endif

map ,1 :b!1<CR>
map ,2 :b!2<CR>
map ,3 :b!3<CR>
map ,4 :b!4<CR>
map ,5 :b!5<CR>
map ,6 :b!6<CR>
map ,7 :b!7<CR>
map ,8 :b!8<CR>
map ,9 :b!9<CR>
map ,0 :b!0<CR>
map ,w :b!bw<CR>

map <F1> v]}zf

nnoremap <silent> <F2> :copen<CR>
nnoremap <silent> <F3> :cclose<CR>
nnoremap <silent> <F4> :make uImage<CR> :cw 7<CR>
nnoremap <silent> <F5> :cs find f 
nnoremap <silent> <F6> :BufExplorer<CR>
nnoremap <silent> <F7> :Tlist<CR>
nnoremap <silent> <F8> :make cscope ARCH=arm<CR> :cs kill 0<CR> :cs add cscope.out<CR>

func! Man( )
    let sm = expand("<cword>")
    exe "!man -S 2:3:4:5:6:7:8:9:tcl:n:l:p:o ".sm
endfunc
nmap <F9> :call Man( )<cr><cr>

nmap <C-[>s :cs find s <C-R>=expand("<cword>")<CR><CR>
nmap <C-[>g :cs find g <C-R>=expand("<cword>")<CR><CR>
nmap <C-[>c :cs find c <C-R>=expand("<cword>")<CR><CR>
nmap <C-[>t :cs find t <C-R>=expand("<cword>")<CR><CR>
nmap <C-[>e :cs find e <C-R>=expand("<cword>")<CR><CR>
nmap <C-[>f :cs find f <C-R>=expand("<cfile>")<CR><CR>
nmap <C-[>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
nmap <C-[>d :cs find d <C-R>=expand("<cword>")<CR><CR>

" Show trailing whitespace and spaces before tabs
hi link localWhitespaceError Error
au Syntax * syn match localWhitespaceError /\(\zs\%#\|\s\)\+$/ display
au Syntax * syn match localWhitespaceError / \+\ze\t/ display
크리에이티브 커먼즈 라이선스
Creative Commons License

Tag : vi, vi shortcut keys, vim, vim shortcut keys, vimrc

Installing vim

Ubuntu is not serving vim full packages for default. So, if you need to use advanced features of vim, just type like following

sudo apt-get install vim

Man pages for development

Hey, M$ users. You can even use reference library like MSDN in vim as well. Just install man pages for development and press shift+k on symbol in vim. Then, you’ll see.

sudo apt-get install manpages-dev

 

Installing cscope

And even use symbol search feature in vim also.

sudo apt-get install cscope

 

Attaching cscope to vim

Just add following lines in your .vimrc which is stored in your home directory.

 

set csprg=/usr/bin/cscope

if filereadable("./cscope.out")

cs add cscope.out

else

cs add "your project cscope.out"

endif

set csverb

 

Script for building cscope db

If your project is not supporting cscope through Make, then you can make a script on your own and locate it in your /usr/local/bin directory with executable permission. And execute that script in your top directory of your project. BTW, kernel project just supports cscope through Makefile. You can just issue “make cscope ARCH=…”

#!/bin/sh

rm -rf cscope.*

find . \( -name '*.c' -o -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.s' -o -name '*.S' \) -print > cscope.files

cscope -i cscope.files

Enjoy your vim&cscope life.

Cheers,

크리에이티브 커먼즈 라이선스
Creative Commons License

Tag : vi, vi + cscope, vim + cscope, vim. cscope

vi 와 Linux programmer&rsquo;s manual 연동

Posted 2009/02/12 13:58 by kdsoo

vi 에서 코드 분석하거나 작성할때 C 함수들을 쉘에서 man page 를 통해 볼수 있지만

 

vi 에서 곧바로 확인하는 방법이 있습니다.

 

우선 개발자용 맨페이지를 받아야하는데요

 

1. ubuntu 기준으로

    sudo apt-get install manpages-dev

하시면 Linux programmer's manual 을 받을수 있습니다. (리눅스는 섹션 2네요...솔라리스나 HPUX 같은건 7 이었던 것 같은데..)

 

2. vi 에서 표준 C 함수에 커서를 놓고 shift + k 를 누르시면 해당 함수의 매뉴얼이 나옵니다.

 

즐개발~

크리에이티브 커먼즈 라이선스
Creative Commons License

'[3] My specialty' 카테고리의 다른 글

git pull & patch 간략 정리  (0) 2009/02/18
Hello San Francisco.  (0) 2009/02/13
vi 와 Linux programmer&rsquo;s manual 연동  (0) 2009/02/12
cscope with linux kernel source code  (0) 2009/02/10
Firefox url bar problem on Ubuntu 8.04  (0) 2009/02/02
V4L2 개발 관련 정리.  (0) 2009/01/21

Tag : Linux programmer's manual, man page, MSDN, vi, vim

cscope with linux kernel source code

Posted 2009/02/10 09:17 by kdsoo

cscope 를 사용하시면 커널소스안에서 파일 위치나 함수 위치 같은걸 기억하지 않아도 금방 찾을수 있습니다.

심볼 싱크하는 시간도 IDE 들에 비해 훨씬 빨라서 좋습니다.(아무리 늦어도 30초 이내에 전체 프로젝트가 싱크됨)

 

0. cscope 설치.

ubuntu 기준으로

sudo apt-get install cscope

 

1. vim에 cscope 인식

우선 자신의 계정에 .vimrc 를 열어서 편집합니다.

set csprg=/usr/bin/cscope

......

if filereadable("./cscope.out")

        cs add cscope.out

else

        cs add /home/share/linux/cscope.out

endif

set csverb

이걸 추가 해주시구요.

 

2. cscope 싱크

커널 소스의 최상위 디렉토리에서

kdsoo@chromatix:/home/share/GIT/OMAP3430/linux-2.6.29-rc3-omap$ make cscope

합니다.

그럼 cscope index 를 만들기 시작합니다.

 

3. 기본적인 사용법

kdsoo@chromatix:/home/share/GIT/OMAP3430/linux-2.6.29-rc3-omap$ vi .

위와 같이 커널소스 최상위 디렉토리에서 "vi ." 이라고 치시면 vim 이 cscope 가 생성한 db와 연동하여 open 됩니다.

 

4. cscope 기본 명령어

vi 의 command mode (: 를 누르면 들어감) 에서

    - 파일 찾기: cs find f 파일명

    - 심볼 찾기 : cs find s 심볼

    - 함수등의 원형 찾기 : cs find g 심볼

    - 해당함수를 호출하는 함수 찾기 : cs find c 심볼

    - 해당함수가 호출하는 함수 찾기 : cs find d 심볼

더 있는데 저는 대충 이거만 써서...

사용법은 vim의 command mode 에서

:cs

라고 치시면 나오니 참고하세요.

 

5. 단축키 만들기

단축키 만들어 두면 편합니다.

.vimrc에 다음을 구미에 맞게 추가하세요. (F 키는 키보드의 펑션키를 말함..취향에 맞게 변경해 쓰세요)

    - cscope db 빌드 단축키 (F8)

    nnoremap <silent> <F8> :make cscope ARCH=arm<CR> :cs kill 0<CR> :cs add cscope.out<CR>

    - 파일찾기 단축키

    nnoremap <silent> <F5> :cs find f

 

6. vim visual mode 에서 cscope 연동

vim 의 visual mode (마우스로 해당 심볼을 선택가능한 모드)에서

해당 심볼을 마우스로 선택하고(그냥 원클릭)

ctrl + [ 를 누른후 s g c t e 등의 cscope 커맨드 옵션을 입력하면

cs find "옵션" 심볼

과 같은 효과를 낼수 있습니다.

다음을 .vimrc에 추가하세요.

nmap <C-[>s :cs find s <C-R>=expand("<cword>")<CR><CR>

nmap <C-[>g :cs find g <C-R>=expand("<cword>")<CR><CR>

nmap <C-[>c :cs find c <C-R>=expand("<cword>")<CR><CR>

nmap <C-[>t :cs find t <C-R>=expand("<cword>")<CR><CR>

nmap <C-[>e :cs find e <C-R>=expand("<cword>")<CR><CR>

nmap <C-[>f :cs find f <C-R>=expand("<cfile>")<CR><CR>

nmap <C-[>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>

nmap <C-[>d :cs find d <C-R>=expand("<cword>")<CR><CR>

위 옵션들을 추가하면 vim 에서 원하는 심볼을 선택하고 해당 심볼을 call 하는 심볼을 찾는 작업등을 할수 있습니다.

그럼 즐거운 vi 생활 되세요.

추가로... 지금 열고있는 소스파일의 심볼 목록을 쉽게 보고 싶으신 경우를 위해 다음 단축키도 편하게 사용하실수 있습니다.

nnoremap <silent> <F7> :Tlist<CR>

크리에이티브 커먼즈 라이선스
Creative Commons License

'[3] My specialty' 카테고리의 다른 글

Hello San Francisco.  (0) 2009/02/13
vi 와 Linux programmer&rsquo;s manual 연동  (0) 2009/02/12
cscope with linux kernel source code  (0) 2009/02/10
Firefox url bar problem on Ubuntu 8.04  (0) 2009/02/02
V4L2 개발 관련 정리.  (0) 2009/01/21
Diff tools  (0) 2009/01/16

Tag : cscope, Linux Kernel, vi, vim

집에서도 열혈 코딩/코드분석을...

Posted 2007/08/28 23:30 by kdsoo
회사 와서 내 밥숫가락이나 다름없는 유닉스를 멀리하다...

지금은 OSX를 쓰고, 요즘 리눅스 커널을 다루는지라

과감하게 맥북에 ctags/cscope 콤보에 vim taglist 를 넣어주시니 재택근무 준비 완료 =ㅅ=

솔직히 소스인사이트 보다는 다소 못하지만 소스인사이트 처럼 버벅이는 일은 없으니...

vim 에 set mouse=a 를 해주니 vi 키보드 워크의 압박이 없고 마우스 휠 드르륵 드르륵도 먹고

심지어 심볼 클릭을 통한 레퍼런스로 점프까지 되니 더 못할건 솔직히 없다.

근데....이런거로 좋아하고 있는게 정상일까 아닐까...


크리에이티브 커먼즈 라이선스
Creative Commons License

Tag : cscope, ctags, kernel, Linux, taglist, vi