1. 실행 환경

  • RHEL 9.0

 

2. 목표

!https://blog.kakaocdn.net/dn/bk3nxM/btsHB7wQwqK/fA1mpnVNTIAkDicQoYYqB1/img.png

yaml에서 들여쓰기는 탭을 사용하면 안되며 공백을 사용해야합니다. 그런데 공백 수만큼 스페이스바를 눌러주는 일은 수고롭기 때문에 이번 문서에서는 아래와 같은 목표로 작업을 하고자 합니다.

  1. yaml 파일을 편집할 때 탭을 누르면 공백 2칸이 입력되도록 변경
  2. 공백 2칸마다 "|"를 나타내는 방법

 

3. 탭을 공백 2칸으로 바꾸기

$HOME/.vimrc 파일 작성

cat ~/.vimrc
autocmd FileType yaml setlocal ts=2 sts=2 sw=2 expandtab
  • autocmd FileType yaml: YAML 파일을 열 때 자동으로 실행되는 명령을 설정
  • ts=2: 탭 문자를 2칸으로 설정
  • sts=2: 소프트 탭을 2칸으로 설정
  • sw=2: 들여쓰기를 2칸으로 설정
  • expandtab: 탭을 스페이스로 변환
  • 즉, YAML 파일을 편집할 때 모든 탭을 2칸의 스페이스로 취급하여 일관된 들여쓰기를 유지

 

4. 들여쓰기 가이드(indentLine Guide) 추가

indentLine plugin을 방문해서 적용 방법을 찾을 수 있습니다.

터미널에 아래와 같은 명령어를 입력하면 됩니다.

git clone <https://github.com/Yggdroot/indentLine.git> ~/.vim/pack/vendor/start/indentLine
vim -u NONE -c "helptags  ~/.vim/pack/vendor/start/indentLine/doc" -c "q"

 

5. vimrc 적용

Vim의 설정 파일인 /etc/vimrc를 수정한 후 변경 사항을 적용하려면 Vim을 재시작하거나 현재 열려 있는 Vim 세션에서 수동으로 설정을 다시 로드해야합니다.

하지만 bash 환경에서는 source /etc/vimrc 를 하면 적용되지 않습니다. 아래와 같은 오류가 출력됩니다.

source /etc/vimrc
bash: /etc/vimrc: line 6: synstax error near unexpected token `('
bash: /etc/vimrc: line 6: `" Use Vim settings, rather than Vi settings (much better!).

왜냐하면  Bash는 해당 파일을 쉘 스크립트로 인식하고 구문 오류를 발생시킵니다. 이는 /etc/vimrc가 Vim 설정 파일이지, 쉘 스크립트가 아니기 때문이다. vimrc를 적용하는 방법은 아래와 같습니다.

  1. vim 명령어 입력
  2. :source /etc/vimrc  # Vim 명령 모드에서 설정 파일을 다시 로드
  3. :exit 로 빠져나가기

이후 vim 명령어로 yaml 파일 등을 열어보면 vimrc에 추가한대로 탭이 공백 2칸으로 적용되고 들여쓰기 가이드가 노출됩니다. 또한 공백을 '·' 으로 설정했을 경우 아래 첫번째 사진과 같이 보일 것입니다.

!https://blog.kakaocdn.net/dn/bk3nxM/btsHB7wQwqK/fA1mpnVNTIAkDicQoYYqB1/img.png

 

참고:

- https://www.arthurkoziel.com/setting-up-vim-for-yaml/

 

Setting up Vim for YAML editing

Setting up Vim for YAML editing March 23, 2020 In this blog post I'm going to show how to set up Vim for easier YAML editing. You can scroll down to the end for a summary of all installed plugins and config file changes. There's not much to do here. VIM ha

www.arthurkoziel.com

 

- https://www.baeldung.com/linux/vim-indentation-guides

 

Add Indentation and Guides to Vim’s Edit View | Baeldung on Linux

Learn how to add indentation and guides to Vim's edit view on Linux.

www.baeldung.com

 

+ Recent posts