운영체제/Linux

[Linux] Vim 언어별 Highlight 설정 (Vi/Syntax/에디터/하이라이트)

쌍쌍바나나 2016. 3. 19. 17:57
반응형

들어가며

Vi/Vim Editor는 개발자라면 한번은 사용해본 에디터이다.  
우리는 Linux terminal에서 구현을 할때, 소스코드 syntax 하이라이트는 정말 중요하다.
또한 터미널에서 Vi키고 화려한 하이라이트의 색이 입혀진 코드를 보면, print문만 찍어도 뭔가 있어보이니까... 

설치하기


이미 친절하게 코드 vi syntax 코드 하이라이트를 만들어놓고 배포하는 착한 사람이 있다. 
https://github.com/sentientmachine/erics_vim_syntax_and_color_highlighting 
지원하는 코드 하이라이트는 java, python, html, javascript, php, css, bash, haml, viml 이다. 


  • 사전 설치 항목 (뭐.. 거의 있겠지만 혹시나 해서 )

$ sudo apt-get install vim 
$ sudo apt-get install git


설치가 완료 되면 git을 통해서 코드를 다운받으는다. 

$ mkdir /home/username/.vim
$ cd /home/username/.vim
$ git clone https://github.com/sentientmachine/erics_vim_syntax_and_color_highlighting.git


다운 받은 폴더에 있는 내용을 .vim으로 옮기고, 폴더를 제거하자.

$ mv erics_vim_syntax_and_color_highlighting/* .
$ rm -r erics_vim_syntax_and_color_highlighting 


이제 vim의 설정 파일을 변경하자. ./vimrc 파일에 아래 내용을 붙여넣자.

$ vi /home/username/.vimrc


"The following three lines map Ctrl+s to save in vi.  You can comment 
"these out, it has nothing to do with syntax highlighting or colors.

" optional lines to turn on pressing F2 to toggle paste mode
noremap <F2> :set invpaste paste?<CR>i
set pastetoggle=<F2>


:nmap <c-s> :w<CR>
:imap <c-s> <Esc>:w<CR>a
:imap <c-s> <Esc><c-s>

syntax on
set background=dark
set hlsearch
set nu
set smartindent
set tabstop=4
set shiftwidth=4
set expandtab
set cursorline
filetype on
filetype plugin indent on

au BufReadPost,BufNewFile *.twig colorscheme koehler 
au BufReadPost,BufNewFile *.css colorscheme slate
au BufReadPost,BufNewFile *.js colorscheme slate2
au BufReadPost,BufNewFile *.py colorscheme molokaiyo
au BufReadPost,BufNewFile *.html colorscheme monokai
au BufReadPost,BufNewFile *.java colorscheme monokai
" au BufReadPost,BufNewFile *.php colorscheme monokai

" Default line highlighting for unknown filetypes
hi String ctermfg=140
hi CursorLine ctermbg=235
hi CursorLine guibg=#D3D3D3 cterm=none

"What follows are optional things, I like them

"au BufNewFile,BufRead *.py 
"        \ set tabstop=4 
"        \ set shiftwidth=4     "aand fedora doesn't like this parameter, remove this line.
"        \ set textwidth=79 
"        \ set expandtab 
"        \ set autoindent 
"        \ set fileformat=unix

" Commenting blocks of code.
" This specifies the comment character when specifying block comments.
"autocmd FileType c,cpp,java,scala let b:comment_leader = '//'
"autocmd FileType sh,ruby,python   let b:comment_leader = '#'
"autocmd FileType conf,fstab       let b:comment_leader = '#'
"autocmd FileType tex              let b:comment_leader = '%'
"autocmd FileType mail             let b:comment_leader = '>'
"autocmd FileType vim              let b:comment_leader = '"'

"this makes it so you can Shift-V highlight lots of text then press ,cc to
"comment it or ,cu to uncomment.  
"noremap <silent> ,cc :<C-B>silent <C-E>s/^/<C-R>=escape(b:comment_leader,'\/')<CR>/<CR>:nohlsearch<CR>
"noremap <silent> ,cu :<C-B>silent <C-E>s/^\V<C-R>=escape(b:comment_leader,'\/')<CR>//e<CR>:nohlsearch<CR>

"This mission critical workaround hack tells vim to restore cursor to the last line.
"Be sure to set: "Thip, crinkle, sploit" to "stopit, just be right".  lolz
"Also it could be the functionality is disabled in your /etc/vim/vimrc or 
"your ~/.viminfo is owned by root.  
"http://askubuntu.com/questions/223018/vim-is-not-remembering-last-position
autocmd BufReadPost *
  \ if line("'\"") > 1 && line("'\"") <= line("$") |
  \   exe "normal! g`\"" |
  \ endif

"These extra commands tell syntastic to ignore the following kinds of warnings                                                               
"let g:syntastic_quiet_messages = { "regex": 'superfluous' }
"let g:syntastic_quiet_messages = { "regex": 'superfluous-parens\|too-many-instance-attributes\|too-few-public-methods' }

"I like the vertical bar on insert mode, others do not like.  You decide.
"let &t_SI = "\<Esc>]50;CursorShape=1\x7" " Vertical bar in insert mode
"let &t_EI = "\<Esc>]50;CursorShape=0\x7" " Block in normal mode


파일의 가장 아래 부분에 아래 줄을 입력하자. (.profile은의 파일이 만약 없다면 생성하면 된다.)


$ /home/username/.profile 

또는

$ /home/username/.bashrc


TERM=xterm-256color

 


현재 터미널 창을 재시작 하면 스타일이 적용된다.


적용 화면






[참고사이트]

https://github.com/sentientmachine/erics_vim_syntax_and_color_highlighting


반응형