Exit neon sign on brick wall background

Як вийти з VIM і найпопулярніші ярлики VIM

If you are reading this article then you are in trouble. You wanted to edit a file using vim editor but got stuck in it. Stop panicking and wait with re-installing the OS and starting all from scratch – in this article I will show you how to exit a vim trap.

google search with request "how to quit vim"
Vim є другою найважчою річчю після куріння

Вийдіть з редактора VIM за допомогою комбінацій клавіш

Редактор Vim складний для початківців, але коли ви навчитеся правильні комбінації клавіш, користуватися VIM стане легко. Ось найпопулярніші комбінації клавіш для виходу з vim.

Вийти з vim, зберігаючи зміни

Щоб вийти з vim зі збереженням змін, натисніть Esc щоб вийти з режиму редагування, а потім утримуйте Shift і натисніть товста кишка key (:). Then enter “wq” and press Enter. Here “w” stands for write and “q” stands for “quit”. On US keyboards the colon : є тим самим ключем, що і крапка з комою ;, located right of the letter “L” key.

:wq

Вийдіть з vim без збереження змін

To exit vim without saving changes hold down Shift and press the colon key (:). Then enter “q!” and press Enter.

:q!
exit vim without saving changes
вийти з vim без збереження змін

Збережіть зміни без наявного редактора VIM

To save changes without exiting vim hold down Shift and press the colon key (:). Then enter “w” and press Enter.

:w

Оволодіння VIM

Тепер, коли я розглянув основи виходу з Vim і збереження змін, давайте перейдемо до деяких додаткових корисних ярликів і функцій Vim, щоб покращити ваші знання.

Запуск VIM для редагування файлу

Зазвичай розробники запускають vim для редагування файлу за допомогою команди:

vim filename

Якщо файл відсутній, він буде створений. Ви можете вказати кілька файлів для редагування:

vim file1 file2 file3

Щоб відкрити файл у певному рядку, ви можете додати [num] після команди vim. Наприклад, щоб відкрити файл у рядку 127, введіть:

vim filename +127

Once you’ve entered Vim, navigating efficiently is key. Here are some popular shortcuts:

  • Переміщення курсору:
    • Використовуйте клавіші зі стрілками для переміщення у відповідних напрямках (вгору, вниз, вліво, вправо).
    • Alternatively, employ the h, j, k, and l keys for left, down, up, and right movements, respectively.
  • Навігація словами:
    • Move the cursor to the beginning of the next word with w.
    • Navigate to the end of the current word using e.
    • Jump to the beginning of the previous word with b.
  • Лінії навігації:
    • Go to the start of the line by pressing 0.
    • Move to the end of the line with $.

Редагування тексту в VIM

Once you’ve reached the desired location, these shortcuts will aid in text manipulation:

  • Вхід у режим вставки:
    • Press i to enter insert mode before the cursor.
    • Use I to start inserting at the beginning of the line.
    • Employ a to append after the cursor.
    • A дозволяє додавати в кінці рядка.
  • Видалення тексту:
    • Delete the character under the cursor with x.
    • Erase the entire line with dd.
    • Cut (delete) the current line and enter insert mode with cc.
  • Скопіюйте та вставте:
    • Copy a line with yy.
    • Paste the copied line below the current line using p.
  • Скасувати та повторити:
    • Undo the last action with u.
    • Redo with Ctrl + r.

Пошук у VIM

Ефективний пошук має вирішальне значення. Ось кілька комбінацій клавіш, пов’язаних із пошуком:

  • Пошук тексту:
    • Initiate a search with /, followed by the desired term.
    • Use n to jump to the next occurrence and N to go to the previous one.
  • Заміна тексту:
    • Substitute the current word with a new one using :s/old/new/g.

Вихід з Vim

Я вже розглянув основи на початку, але ось ще кілька варіантів:

  • Зберегти та вийти з усіх:
    • To save all changes and quit multiple files simultaneously, use :wa і :qa.
  • Вихід без збереження:
    • If you want to exit Vim without saving any changes made in any of the files, :qa! will do the trick.

Висновок

Пам’ятайте, що для освоєння Vim потрібен час і практика. Чим більше ви використовуєте його, тим зручнішим і потужнішим він стає. Приємного редагування!