RSS 피드 구독하기

The Vi application is the default text editor on most Linux systems, so it's the primary interface you will use when you need to edit a configuration file. If you're used to a graphical text editor, such as Notepad++ or VS Code, Vi can be confusing at first.

In its default form, Vi launches and runs in a terminal and is entirely keyboard-driven. But once you learn the basics of Vi, you're likely to find that it's a fast, efficient, and flexible editor.

Start Vi

To start Vi, open a terminal and type vi followed by a file path. If the file you provide doesn't exist, it's created when Vi opens:

$ vi example.txt

The vi command is usually a symlink to the vim (Vi improved) command, but many users refer to Vi as Vi, not Vim.

Command mode and insert mode

Vi has two different modes. There's command mode and insert mode. Command mode is the default, and you can think of it as Vi's menu. Because Vi doesn't have a menu bar like most applications have, you use command mode to tell Vi what you want to do next (move up or down a line, delete a character or a whole word, copy and paste, and so on.)

You can always get back to command mode by pressing Esc on your keyboard. Get used to that; you'll be pressing Esc a lot in Vi.

To enter insert mode, press i. In insert mode, you can type and edit text and use the arrow keys to navigate around your document. There's not much to say about insert mode. It's very much as its name advertises: In insert mode, you can insert text, so there's nothing to learn except, maybe, touch typing.

Command mode, however, has a wealth of keyboard shortcuts and commands for you to discover. Remember, to enter command mode, press Esc. If you're ever in doubt about which mode you're in, just press Esc, and you can be sure that you're now in command mode.

Keyboard shortcuts for command mode

In Vi, you don't use your mouse or any of the keyboard shortcuts you're used to in other editors. For instance, you don't copy with Ctrl+C and paste with Ctrl+V because Vi has its own set of quick shortcuts that optimize key presses. It's unquestionably a learning curve, but one that pays dividends. Once you've got the basic keyboard shortcuts committed to muscle memory, you'll work faster in Vi than you've worked in any editor.

Modes

  • i: for insert mode
  • (that's an upper-case i): insert text at beginning of current line
  • a: append text after cursor
  • A: append text at end of current line
  • Esc: command mode

[ Boost your Linux skills by downloading the Bash shell scripting cheat sheet. ]

Navigation

Navigation happens on the home row of your QWERTY keyboard:

  • h: cursor left
  • j: cursor down (j looks trivially like a down arrow)
  • k: cursor up
  • l (that's a lower-case L): cursor right
  • b: cursor to beginning of current word
  • e: cursor to end of current word
  • $: go to end of line
  • 0 (that's a zero): go to beginning of line
  • gg: go to first line of file
  • G: go to last line of file
  • 9G: go to line 9 of file

Select

  • v: select text
  • V: select line

Copy and paste

  • y: copy ("yank") selection
  • yy: copy ("yank") the entire line
  • p: paste

Delete

  • x: delete character
  • dw: delete word
  • d$: delete from current position to end of line
  • d0: delete from current position to beginning of line
  • dG: delete to last line of file

Undo

  • u: undo

Save

  • :w: save
  • :wq or :ZZ: save and quit
  • :q!: force quit without saving

Get to know Vi

Knowing Vi is a valuable skill on Linux because it's on nearly every Linux system you're likely to encounter. Once you get comfortable with its key bindings and how they enable you to keep your hands on the keyboard instead of bouncing back and forth to your mouse or even to Function keys, you'll see why Vi has endured for so long.


저자 소개

Seth Kenlon is a Linux geek, open source enthusiast, free culture advocate, and tabletop gamer. Between gigs in the film industry and the tech industry (not necessarily exclusive of one another), he likes to design games and hack on code (also not necessarily exclusive of one another).

Read full bio
UI_Icon-Red_Hat-Close-A-Black-RGB

채널별 검색

automation icon

오토메이션

기술, 팀, 인프라를 위한 IT 자동화 최신 동향

AI icon

인공지능

고객이 어디서나 AI 워크로드를 실행할 수 있도록 지원하는 플랫폼 업데이트

open hybrid cloud icon

오픈 하이브리드 클라우드

하이브리드 클라우드로 더욱 유연한 미래를 구축하는 방법을 알아보세요

security icon

보안

환경과 기술 전반에 걸쳐 리스크를 감소하는 방법에 대한 최신 정보

edge icon

엣지 컴퓨팅

엣지에서의 운영을 단순화하는 플랫폼 업데이트

Infrastructure icon

인프라

세계적으로 인정받은 기업용 Linux 플랫폼에 대한 최신 정보

application development icon

애플리케이션

복잡한 애플리케이션에 대한 솔루션 더 보기

Virtualization icon

가상화

온프레미스와 클라우드 환경에서 워크로드를 유연하게 운영하기 위한 엔터프라이즈 가상화의 미래