본문 바로가기

Build/Infra

Vim 사용기 (ColorScheme & Terraform)

0. 개요

테라폼을 사용하기위해 vim에 .tf파일을 제작려고 하는데 가독성이 떨어져 color scheme을 적용하고 vim을 배워본다. vi, vim은 유닉스 기본 편집기라 맥OS에서는 설치가 되어 있지만 윈도우의 경우 따로 설치해 주어야 한다.

vim 명령어: https://stricky.tistory.com/135

 

1. Vundle 설치

:PluginInstall을 하기위한 플러그인 매니저 입니다.

git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim

 

 

2. ./vimrc 파일 만들기

-1. Home 디렉토리에 .vimrc 파일을 만들어 준다.

vim ~/.vimrc

 

-2. .vimrc에 플러그인 설치와 설정 코드를 작성한다.

set nocompatible
filetype off

" for Vundle -----------------------------------------
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
" The following are examples of different formats supported.
" Keep Plugin commands between vundle#begin/end.
" plugin on GitHub repo
Plugin 'tpope/vim-fugitive'
" plugin from http://vim-scripts.org/vim/scripts.html
" Plugin 'L9'
" Git plugin not hosted on GitHub
Plugin 'git://git.wincent.com/command-t.git'
" git repos on your local machine (i.e. when working on your own plugin),
"Plugin 'file:///home/jjeaby/Dev/tools/vim-plugin'
" The sparkup vim script is in a subdirectory of this repo called vim.
" Pass the path to set the runtimepath properly.
Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
" Install L9 and avoid a Naming conflict if you've already installed a
" different version somewhere else.
" Plugin 'ascenator/L9', {'name': 'newL9'}
" All of your Plugins must be added before the following line
Plugin 'matchparenpp' " 괄호 확인
Plugin 'townk/vim-autoclose' " 자동 괄호 닫힘
Plugin 'vim-airline/vim-airline'
Plugin 'vim-airline/vim-airline-themes'
Plugin 'http://github.com/tomasr/molokai'  " colorscheme
Plugin 'scrooloose/nerdtree'
Plugin 'airblade/vim-gitgutter'
Plugin 'scrooloose/syntastic' " 문법검사 ******** 이게 검사 플러그인 입니다.
Plugin 'ctrlpvim/ctrlp.vim'

Plugin 'hashivim/vim-terraform' " 테라폼 관련 플러그인 #1 
Plugin 'juliosueiras/vim-terraform-completion' " 테라폼 관련 플러그인 #2

call vundle#end() " required
" end of Vundle -------------------------------------

" vim 기본 설정 영역
filetype plugin indent on

"NERDTree ON 단축키를 "\nt"로 설정
map nt :NERDTree
let NERDTreeShowHidden=1
" let NERDTreeQuitOnOpen=1
let g:ctrlp_custom_ignore = {
\ 'dir': '\.git$\|vendor$',
\ 'file': '\v\.(exe|so|dll)$'
\ }

" colorscheme jellybeans " 컬러 스킴 설정.(plugin 설치 필요)
colorscheme molokai
filetype on "vim filetype on

" Syntax 지원
if has("syntax")
syntax on
endif

set backspace=indent,eol,start " 맥 vi 백스페이스

set encoding=utf-8 " encoding 설정
set fileencodings=utf-8,cp949,default,latin1
set termencoding=utf-8

" set printencoding=utf-8 " 인쇄 encoding 옵션
" set printmbcharset=ISO10646
" set printmbfont=r:NanumGothiccoding,c:yes,a:yes
set number " 좌측 라인 넘버 표시
set numberwidth=6 " 넘버 표시 공간의 너비

set title " 하단 편집 문서의 이름 표시
set ruler " 하단부에 현재 커서의 위치를 표시

set shiftwidth=4 " 들여쓰기 간격
set tabstop=4 " tab 간격

set cindent
set autoindent " 자동 들여쓰기
set smartindent

set hlsearch " 검색 결과 강조
set incsearch " 증가 방향으로 검색
set nowrapscan " 검색 시 파일 끝에서 되돌려 검색하지 않게
set ignorecase " 검색 시 대소문자 구분하지 않음

set nowrap " 자동 줄 바꿈 사용하지 않음

set autowrite " 자동 저장
set autoread

" set paste " 붙여 넣기 시 계단현상 방지
set showmatch " 커서 위치 시 괄호의 끝 혹은 시작을 반전으로 표시

" for vim-airline
let g:airline#extensions#tabline#enabled = 1 " turn on buffer list
let g:airline_theme='hybrid'
set laststatus=2 " turn on bottom bar

set tagbsearch " 태그 데이터 베이스를 이진으로 검사

이후 :wq을 통해 저장후 다시 들어와서 :PluginInstall로 설치하면 설정이 되어 있다. 

 

3. Color Scheme 파일을 가져와 저장한다. 

-1. color 파일을 선택하여 가져온다. color라고 되어 있는 폴더의 파일을 가져오면 된다. Color Scheme을 바꾸려면 위의 설정파일의 colorscheme 후의 이름을 변경하면 된다. 현재는 "molokai". 

링크: https://www.slant.co/topics/480/~best-vim-color-schemes#16

 

-1. ~.vim 디렉토리에 colors폴더를 만든다.

mkdir ~/.vim/colors

 

-2. 다운로드한 파일을 color파일로 옮긴다

**위의 테라폼 관련 플러그인을 설치하여야 .tf파일에도 컬러가 적용된다.

mv molokai.vim ~/.vim/colors

 

 

출처: 

GLAB: https://duty-c.tistory.com/24

jyha81: https://velog.io/@jyha81/MacBook-%EA%B0%9C%EB%B0%9C%ED%99%98%EA%B2%BD-%EC%84%A4%EC%A0%95-%EA%B0%80%EC%9D%B4%EB%93%9C

Brodie Robertson: https://www.youtube.com/watch?v=2prsFrKwbOo

sTricky: https://stricky.tistory.com/135

그로잉린: https://www.youtube.com/watch?v=oZSA36x1Xtw