티스토리 뷰

os/Linux

vim (vi)

Jacob_baek 2012. 9. 10. 11:10

환경설정

- ubuntu 에서 vimrc 설정

ctags 를 활용한 vim 사용

 

/etc/vim/vimrc.local (debian 계열)

set tags += /root/workspace/tags

 

위와 같이 추가할 경우 생성해놓은 tags 파일을 어디서 열던지 link가 가능하다.

 

vimrc.local 

 

 set smartindent

 자동 구문 들여쓰기 

 set ts=4

 tab 크기를 4byte로 설정 

 set ruler

 줄자 기능 사용 (현재 커서 위치 아래에 표시된다.) 

 set number(nu)

 줄번호 표시 (미표시를 위해서는 no를 붙여서 입력) 

 set ignorecase(ic)

 검색시 대소문자 구분하지 않음 

 set incsearch

 점진 검색 사용(즉, 한글자 입력시마다 검색 수행) 

 set list

 tab과 같은 문자에 대한 화면 표시 

 set listchars=tab:[-

 tab에 대한 표시를 [- 와 같이 표시 (첫문자 [, 그외 -) 

 

사용법

단축키

 

 *

 커서에 존재하는 단어 검색(n 혹은 shift + n으로 다음 항목 이동가능)

 #

 *와 동일한 기능이나 n 혹은 shift + n 수행시 반대로 검색수행

 shift + k 

 man page 이동 (커서가 놓인 단어에 대한)

 ctrl + ] (opp : ctrl + t)

 (ctags와 함께 사용)

 ctrl + f (opp : ctrl + b)

 

 

 

vimscript (/etc/vim/vimrc.local) : 특정 tags(using ctags)를 상태에 따라 load하기

 

let fname=expand('%:t')        # vim으로 open 한 file name

let dname=expand('%:p')      # vim으로 open 한 file 이 존재하는 directory

 

" if fname[0:3] == "test"

if expand('%:t') =~ "test"

    set tags +=/root/workspace/test/tags

endif

 

if fname =~ "test2"

    set tags +=/root/workspace/test2/tags

endif

 

참고사이트

- http://vimdoc.sourceforge.net/htmldoc/cmdline.html#filename-modifiers : 파일이름 수정자

- vim.wikia.com/wiki/Insert_current_filename

 

Plugin

Plugin 설치시 아래 /usr/share/vim/vimfiles/plugin으로 vim 확장자를 가진 파일을 복사한다.

 

 

Project (http://www.vim.org/scripts/script.php?script_id=69)

Ctags ()

CScope ()

Taglist (http://www.vim.org/scripts/script.php?script_id=273)

bufexplorer (http://www.vim.org/scripts/script.php?script_id=42)

 

좀더 편리하게 사용하기 위해 vimrc에 아래와 같은 keymap 을 지정한다.

map <F3> :TlistToggle<CR>

 

ctrl + w(double) 을 사용하면 function list로 이동한다. 다시 돌아올수도 있음.

- http://vim.wikia.com/wiki/Mapping_keys_in_Vim_-_Tutorial_(Part_1)

 

copy & paste 수행시 indent가 깨지는 문제가 발생될수 있다.

F2키를 등록하여 이를 해결하는 방법이 아래에 기술되어 있다.

https://vim.fandom.com/wiki/Toggle_auto-indenting_for_code_paste

 

 

참고사이트

http://blog.naver.com/njybk?Redirect=Log&logNo=70032218102

http://www.vim.org/scripts/script_search_results.php?order_by=rating

http://learnvimscriptthehardway.stevelosh.com/acknowledgements.html : vimscript 관련 튜토리얼

http://vimdoc.sourceforge.net/htmldoc/

http://dougblack.io/words/a-good-vimrc.html

- http://amix.dk/vim/vimrc.html : 다양한 예제 파일 존재

'os > Linux' 카테고리의 다른 글

ssh certification  (0) 2014.09.01
desktop icon execution of root privilege in ubuntu  (0) 2013.05.13
standard streams  (0) 2013.04.12
ssh character encoding  (0) 2013.03.15
strace  (0) 2012.06.07
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/04   »
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
글 보관함