본문 바로가기

리눅스

vim 편집기(editor)의 설정과 사용법

반응형

vim 편집기(editor)의 설정과 사용법

vim은 매우 강력한 텍스트 편집기로서 리눅스 및 유닉스 기반 시스템에서 많이 사용됩니다. Vim은 다양한 모드를 갖고 있으며, 처음 사용하면 다소 복잡해 보일 수 있지만 익숙해지면 빠른 편집과 효율적인 작업을 제공합니다. 아래에서 Vim 편집기의 설정과 사용법에 대해 설명하겠습니다.

Vim 설정

1. Vim 실행

Vim을 실행하려면 터미널 또는 콘솔에서 vim 명령어를 입력합니다.

vim

2. Vim 설정 파일 (vimrc)

Vim은 설정 파일인 .vimrc를 통해 사용자 정의 설정을 제공합니다. ~/.vimrc 파일을 생성하여 원하는 설정을 추가할 수 있습니다. 예를 들어, .vimrc 파일에 다음과 같이 설정을 추가할 수 있습니다.

vim ~/.vimrc
" ~/.vimrc
syntax enable          " 구문 강조 사용
set number             " 라인 번호 표시
set tabstop=4          " 탭을 4 칸으로 설정
set shiftwidth=4       " 자동 들여쓰기를 4 칸으로 설정
set expandtab          " 탭 대신 스페이스 사용
set smartindent        " 스마트 들여쓰기 사용
set autoindent         " 자동 들여쓰기 사용
더보기
" Begin .vimrc
set nowrap                              " don't wrap lines
set tabstop=4                           " a tab is four spaces
set backspace=indent,eol,start          " allow backspacing over everything in insert mode
set autoindent                          " always set autoindenting on
set copyindent                          " copy the previous indentation on autoindenting
set number                              " always show line numbers
set shiftwidth=4                        " number of spaces to use for autoindenting
set shiftround                          " use multiple of shiftwidth when indenting with '<' and '>'
set showmatch                           " set show matching parenthesis
set ignorecase                          " ignore case when searching
set smartcase                           " ignore case if search pattern is all lowercase, case-sensitive otherwise
set smarttab                            " insert tabs on the start of a line according to shiftwidth, not tabstop
set hlsearch                            " highlight search terms
set incsearch                           " show search matches as you type
set history=1000                        " remember more commands and search history
set undolevels=1000                     " use many muchos levels of undo
set wildignore=*.swp,*.bak,*.pyc,*.class
set title                               " change the terminal's title
set visualbell                          " don't beep
set noerrorbells                        " don't beep
set nobackup

" --- vim map (macro) commands ---
func! Remarkon()
exe "'<,'>norm i#"
endfunc

func! Remarkoff()
exe "'<,'>norm 2x"
endfunc
" Begin .vimrc
728x90
  • Ctrl + V (visual block) ; 주석 처리할 부분 선택
:'<,'> ;'<,'> 삭제
  • 주석 ON
:call Remarkon()
  • 주석 OFF
:call Remarkoff()

Vim 사용법

Vim은 다양한 모드가 있으며, 각 모드에서 다른 동작을 수행합니다. 기본적으로 Vim은 Normal 모드에서 시작합니다.

 

  • Normal 모드 (Command 모드): Vim을 시작하면 Normal 모드로 진입합니다. 여기서는 명령을 입력하여 다른 모드로 전환하거나 파일을 저장하고 종료하는 등의 동작을 수행할 수 있습니다.
  • Insert 모드: Normal 모드에서 i, I, a, A, o, O 등을 누르면 Insert 모드로 전환되어 텍스트를 입력할 수 있습니다.
  • Visual 모드: Normal 모드에서 v, V, Ctrl + v 등을 누르면 Visual 모드로 전환되어 텍스트를 선택할 수 있습니다.
  • 명령 모드: Normal 모드에서 :를 누르면 명령 모드로 전환되어 파일 저장, 종료, 검색 등의 명령을 실행할 수 있습니다.
  • 명령어: 명령 모드에서 다양한 명령어를 사용할 수 있습니다. 예를 들어, :w는 저장, :q는 종료, :wq는 저장 후 종료를 의미합니다.

Vim은 강력한 편집기로서 학습 곡선이 있지만, 익숙해지면 편집 작업을 더욱 빠르고 효율적으로 수행할 수 있습니다. 추가적으로, vimtutor 명령어를 통해 Vim 튜토리얼을 시작하여 Vim 사용법을 익힐 수도 있습니다.

 

참고URL

- yaml 편집을 위한 vi/vim 설정 (vi/vim 환경 설정) : https://scbyun.com/1348

- vim 에디터 환경 설정 파일 : https://scbyun.com/612

- www.vimconfig.com

 

728x90
반응형