ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • LINUX VI 및 VIM 편집기 Set number 설정하는 방법
    System of Infra/Linux System 2022. 6. 27. 22:54
    반응형

    LINUX 로고이미지

    LINUX VI 및 VIM 편집기 Set num 설정하는 방법

    [root@localhost /]# find / -name vi*rc
    /etc/vimrc
    /etc/virc
    ▶ 기본적으로 리눅스 초기 설치 시에는  /etc 디렉토리에 vimrc와 virc 파일이 존재합니다. 간혹 vim 패키지가 설치 안되어 있다면 dnf -y install vim을 통해서 vim 패키지를 설치하시면 됩니다.

    ★Vi 와 Vim의 차이점
    유닉스의 기본 편집기인 VI 에디터를 개량한 버전이, 바로 VIM (빔) 에디터입니다. 따라서 본질적인 차이는 없습니다.
    1. VI는 텍스트 편집에 필요한 최소한의 기능만 가지고 있고 문법 강조 기능이 없음
    2. VIM은 윈도우의 울트라에디트만큼이나 강력한 기능들이 많이 추가되어 있음

    [root@localhost /]# vi /etc/ssh/sshd_config
    #       $OpenBSD: sshd_config,v 1.103 2018/04/09 20:41:22 tj Exp $
    
    # This is the sshd server system-wide configuration file.  See
    # sshd_config(5) for more information.
    
    # This sshd was compiled with PATH=/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin
    
    # The strategy used for options in the default sshd_config shipped with
    # OpenSSH is to specify options with their default value where
    # possible, but leave them commented.  Uncommented options override the
    # default value.
    
    # If you want to change the port on a SELinux system, you have to tell
    # SELinux about this change.
    # semanage port -a -t ssh_port_t -p tcp #PORTNUMBER
    #
    #Port 22
    #AddressFamily any
    #ListenAddress 0.0.0.0
    #ListenAddress ::
    
    HostKey /etc/ssh/ssh_host_rsa_key
    HostKey /etc/ssh/ssh_host_ecdsa_key
    HostKey /etc/ssh/ssh_host_ed25519_key
    ...이하 생략
    ▶ VI 편집기를 테스트 하기 위해서 /etc/ssh/sshd_config 파일을 열었을 때 라인 설정이 되어 있지 않기 때문에 에러 메시지 출력 시 몇 번째 줄인 지 확인하기 어렵습니다.
          1 #       $OpenBSD: sshd_config,v 1.103 2018/04/09 20:41:22 tj Exp $
          2 
          3 # This is the sshd server system-wide configuration file.  See
          4 # sshd_config(5) for more information.
          5 
          6 # This sshd was compiled with PATH=/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin
          7 
          8 # The strategy used for options in the default sshd_config shipped with
          9 # OpenSSH is to specify options with their default value where
         10 # possible, but leave them commented.  Uncommented options override the
         11 # default value.
         12 
         13 # If you want to change the port on a SELinux system, you have to tell
         14 # SELinux about this change.
         15 # semanage port -a -t ssh_port_t -p tcp #PORTNUMBER
         16 #
         17 #Port 22
         18 #AddressFamily any
         19 #ListenAddress 0.0.0.0
         20 #ListenAddress ::
         21 
         22 HostKey /etc/ssh/ssh_host_rsa_key
         23 HostKey /etc/ssh/ssh_host_ecdsa_key
         24 HostKey /etc/ssh/ssh_host_ed25519_key
         ...이하 생략
    :set nu
    ▶ 임시방편으로 일회성으로 :set nu를 설정하게 되면 편집기 파일안에 라인 number를 확인할 수 있습니다. 하지만 저장 후 다시 열게 되면 반복적으로 set nu 명령어를 수행해야 하는 번거로움으로 인해 고정시킬 수 있는 방법이 있습니다.
    [root@localhost etc]# vi virc
    if v:lang =~ "utf8$" || v:lang =~ "UTF-8$"
       set fileencodings=ucs-bom,utf-8,latin1
    endif
    
    set nocompatible        " Use Vim defaults (much better!)
    set bs=indent,eol,start         " allow backspacing over everything in insert mode
    "set ai                 " always set autoindenting on
    "set backup             " keep a backup file
    set history=50          " keep 50 lines of command line history
    set ruler               " show the cursor position all the time
    set number --> 추가
    " Only do this part when compiled with support for autocommands
    if has("autocmd")
      augroup redhat
      autocmd!
      " In text files, always limit the width of text to 78 characters
      " autocmd BufRead *.txt set tw=78
      " When editing a file, always jump to the last cursor position
      autocmd BufReadPost *
    ...이하 생략
    ▶ /etc/virc 파일을 열어 set ruler 아래 set number 텍스트 한줄을 추가하고 저장합니다.
    [root@localhost etc]# vi /etc/ssh/sshd_config
    1 #       $OpenBSD: sshd_config,v 1.103 2018/04/09 20:41:22 tj Exp $
          2 
          3 # This is the sshd server system-wide configuration file.  See
          4 # sshd_config(5) for more information.
          5 
          6 # This sshd was compiled with PATH=/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin
          7 
          8 # The strategy used for options in the default sshd_config shipped with
          9 # OpenSSH is to specify options with their default value where
         10 # possible, but leave them commented.  Uncommented options override the
         11 # default value.
         12 
         13 # If you want to change the port on a SELinux system, you have to tell
         14 # SELinux about this change.
         15 # semanage port -a -t ssh_port_t -p tcp #PORTNUMBER
         16 #
         17 #Port 22
         18 #AddressFamily any
         19 #ListenAddress 0.0.0.0
         20 #ListenAddress ::
         21 
         22 HostKey /etc/ssh/ssh_host_rsa_key
         23 HostKey /etc/ssh/ssh_host_ecdsa_key
         24 HostKey /etc/ssh/ssh_host_ed25519_key
    ...이하 생략
    ▶ :set nu를 별도로 수행하지 않고 파일안에 몇 번째 라인인지 출력되었습니다. 이 설정을 해놓게 되면 모든 파일을 편집기로 오픈했을 시 몇 번째 라인인지 확인이 가능합니다.
    [root@localhost /]# vim /etc/ssh/sshd_config
    #       $OpenBSD: sshd_config,v 1.103 2018/04/09 20:41:22 tj Exp $
    
    # This is the sshd server system-wide configuration file.  See
    # sshd_config(5) for more information.
    
    # This sshd was compiled with PATH=/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin
    
    # The strategy used for options in the default sshd_config shipped with
    # OpenSSH is to specify options with their default value where
    # possible, but leave them commented.  Uncommented options override the
    # default value.
    
    # If you want to change the port on a SELinux system, you have to tell
    # SELinux about this change.
    # semanage port -a -t ssh_port_t -p tcp #PORTNUMBER
    #
    #Port 22
    #AddressFamily any
    #ListenAddress 0.0.0.0
    #ListenAddress ::
    
    HostKey /etc/ssh/ssh_host_rsa_key
    HostKey /etc/ssh/ssh_host_ecdsa_key
    HostKey /etc/ssh/ssh_host_ed25519_key
    ...이하 생략
    ▶ vim 명령어 수행시 vimrc 파일에 set number 라인이 추가되지 않아 /etc/ssh/sshd_config 파일을 편집기로 열었을 때 라인 표기가 되어 있지 않는 것을 확인할 수 있습니다.
    virc 파일과 동일하게 vimrc 파일을 열어 set number 라인을 추가해줍니다.
    [root@localhost /]# vim /etc/ssh/sshd_config
     1 #       $OpenBSD: sshd_config,v 1.103 2018/04/09 20:41:22 tj Exp $
      2 
      3 # This is the sshd server system-wide configuration file.  See
      4 # sshd_config(5) for more information.
      5 
      6 # This sshd was compiled with PATH=/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin
      7 
      8 # The strategy used for options in the default sshd_config shipped with
      9 # OpenSSH is to specify options with their default value where
     10 # possible, but leave them commented.  Uncommented options override the
     11 # default value.
     12 
     13 # If you want to change the port on a SELinux system, you have to tell
     14 # SELinux about this change.
     15 # semanage port -a -t ssh_port_t -p tcp #PORTNUMBER
     16 #
     17 #Port 22
     18 #AddressFamily any
     19 #ListenAddress 0.0.0.0
     20 #ListenAddress ::
     21 
     22 HostKey /etc/ssh/ssh_host_rsa_key
     23 HostKey /etc/ssh/ssh_host_ecdsa_key
     24 HostKey /etc/ssh/ssh_host_ed25519_key
     ...이하 생략
    ▶ vim 명령어로 편집기 파일을 오픈했을때 마찬가지로 라인에 표시줄이 설정된 것을 확인할 수 있습니다.

     

    2020.12.08 - [System of Infra/LINUX] - LINUX vi 편집기 사용 방법

     

    LINUX vi 편집기 사용 방법

    LINUX vi 편집기 사용 방법 ● vi 편집기 생성 - vi 파일명 : 해당하는 파일이 없으면 새 파일이 생성된다. ● vi 종료하기 - 명령 모드로 이동한다.(입력 모드에 있다면 ESC를 누르면 된다.) - 그 상

    pinetreeday.tistory.com

     

    PS. 포스팅의 내용은 제 기준으로 작성한 것이기 때문에 참고해서 보시면 감사하겠습니다.

    포스팅 과정의 오류 및 오타 그리고 궁금한 점에 대해서는 댓글 남겨주세요.

    반응형

    댓글

Designed by Tistory.