'2021/07/16'에 해당되는 글 1건

  1. 2021.07.16 vimrc
카테고리 없음 | 2021. 7. 16. 10:35 | /31

서론

20년 10월부터 vim을 쓰기 시작한 이후, 전에는 어떻게 살았나 싶을 정도로 유용하게 사용하고 있다. 모든 코딩 작업은 전부 vim으로 진행을 하고, IDE의 부가적인 기능이 필요한 경우 IDE와 함께 열어서 돌릴 때만 IDE를 쓰고 그 이외의 코드 편집 작업은 vim에서 하는 방식으로도 쓴다.

 

8개월 가량 vim을 쓰면서 숙련도도 머리보다 손이 먼저 나갈만큼 증가했지만 vimrc 파일에도 크고작은 변화가 있었다. 특히 문제가 되었던 것은 집, 학교 컴퓨터와 노트북에 동일한 vim 환경을 구축하는 것이었는데 vimrc를 쪼개고 batch script를 만들고, git을 사용해 동일한 환경을 구축할 수 있도록 설정했다. 이 글은 최근에 바꾼 vimrc 파일을 공유하기 위함이다.

 

vimrc

  • Plugin 관리는 Plug로 정착을 했다. 사용법이 쉽고, github 기반 plugin들은 README.md를 읽을 필요도 없이 쉽게 적용이 가능하다.
  • 여러 plugin들을 테스트 해보다가 마음에 들거나 필요한게 생기면 하나씩 추가/수정을 진행했다.
  • 이전 글에서 열심히 만들어두었던 python에서 선택영역을 실행하는 기능은 결국 잘 안쓰게 되더라. 이전 명령들을 보기 어려워서 그런지 편리한 IDE로 자꾸 손이 간다.
" vim runtime config file

" Written by Knowblesse 2020

" Adapted from miguelgrinberg/.vimrc



"""""""""""""""""""""""""""""""""""

"             Basics              "

"""""""""""""""""""""""""""""""""""

" sane text files

set fileformat=unix " uses line ending LF (not DOS-style CR LF)

set encoding=utf-8

set fileencoding=utf-8

set nu

set tabstop=4

set shiftwidth=4

set softtabstop=4

set colorcolumn=100

set expandtab

set hlsearch

if has('unix')

    echo "Unix option is applied"

    set guifont=Bitstream\ Vera\ Sans\ Mono\ 12

else

    echo "Consier as Window OS"

    set guifont=Bitstream\ Vera\ Sans\ Mono:h12

endif

" Key Bindings

imap jk <Esc>

nmap <Tab> >>

nmap <S-tab> <<



" color scheme

syntax on

colorscheme monokai

filetype on

filetype plugin indent on



"""""""""""""""""""""""""""""""""""

"             Plugin              "

"""""""""""""""""""""""""""""""""""

"monokai theme is manually installed

"ctag is manually installed



call plug#begin()

Plug 'yegappan/taglist'

Plug 'tpope/vim-sensible'

"Plug 'terryma/vim-multiple-cursors'

Plug 'mg979/vim-visual-multi'

"buffer lists instead of tab

Plug 'ap/vim-buftabline'



"NERD

Plug 'preservim/nerdtree'



"Git

Plug 'airblade/vim-gitgutter'

Plug 'Xuyuanp/nerdtree-git-plugin'

Plug 'tpope/vim-fugitive'



"Coding

Plug 'davidhalter/jedi-vim'

Plug 'ervandew/supertab'

Plug 'dense-analysis/ale'

Plug 'itchyny/lightline.vim'



"Color theme

Plug 'joshdick/onedark.vim'



"Table generataion

Plug 'dhruvasagar/vim-table-mode'



call plug#end()





"""""""""""""""""""""""""""""""""""

"       Start up Functions        "

"""""""""""""""""""""""""""""""""""

"autocmd VimEnter * call StartUp()

"function! StartUp()

"    if 0 == argc()

"        NERDTree

"    end

"endfunction

"

"""""""""""""""""""""""""""""""""""

"        Plugin Options           "

"""""""""""""""""""""""""""""""""""

" lightline

set noshowmode

let g:lightline = { 'colorscheme': 'onedark' }



"nerdtree

let g:nerdtree_open = 0

map <leader>t :call NERDTreeToggle()<CR>

function NERDTreeToggle()

    NERDTreeToggle

    if g:nerdtree_open == 1

        let g:nerdtree_open = 0

    else

        let g:nerdtree_open = 1

        wincmd p

    endif

endfunction



"""""""""""""""""""""""""""""""""""

"             Python              "

"""""""""""""""""""""""""""""""""""

"Python execute selected line script

autocmd FileType python setlocal completeopt-=preview

python3 << EOL

import vim



def ExecuteSelectedLine(l1, l2):

    for i in range(l1-1,l2):

        print(">>" + vim.current.buffer[i])

        exec(vim.current.buffer[i],globals())

def ExecuteExpression(exp):

    print(">>" + exp)

    exec(exp,globals())

EOL

command! -range Ev <line1>,<line2> python3 ExecuteSelectedLine(<line1>, <line2>)

 

https://github.com/knowblesse/vimrc

 

knowblesse/vimrc

Contribute to knowblesse/vimrc development by creating an account on GitHub.

github.com

 

git integration

  • 아래는 내가 git을 사용해서 vim 환경을 동일하게 유지한 방법이다.
  • 새 환경을 설정할 때는 먼저 knowblesse/vimrc를 clone해서 저장해둔다.
  • vim이 윈도우나 Ubuntu에서 home 경로에서 _vimrc 혹은 .vimrc을 읽기 때문에 레포에 _vimrc 파일을 만들어 두고 리눅스인경우 .vimrc, 윈도우인경우 _vimrc로 이름을 바꾸어 home 위치에 넣어주는 스크립트, 각각 setVim_linux.sh와 setVim_win.ps1을 만들어두었다.
  • 이 _vimrc에는 사실 별게 들어있지 않다. 쉽게 환경별로 업데이트를 할 수 있도록 git을 clone 해둔 경로만 수정해주면 git pull을 통해서 vimrc.vim 파일이 업데이트가 되고 _vimrc가 이 .vim 파일을 읽는 방식이다.
  • 그리고 왜인지 OS마다 폰트 설정 방식이 달라서 OS를 읽고 상황에 따라 다른 명령어를 적용하도록 만들어두기도 했다.
  •  

 

Posted by Knowblesse