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.
Выйдите из редактора VIM, используя комбинации клавиш.
Редактор Vim сложен для новичков, но когда вы выучите правильные комбинации клавиш, использование VIM станет простым. Вот наиболее популярные комбинации клавиш для выхода из Vim.
Выйти из vim, сохранив изменения
Чтобы выйти из vim с сохранением изменений, нажмите Esc клавиша для выхода из режима редактирования, затем нажмите и удерживайте Сдвиг и нажмите толстая кишка key (:). Then enter “вк” 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!

Сохраните изменения без существующего редактора 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
Навигация в VIM
Once you’ve entered Vim, navigating efficiently is key. Here are some popular shortcuts:
- Перемещение курсора:
- Используйте клавиши со стрелками для перемещения в соответствующих направлениях (вверх, вниз, влево, вправо).
- Alternatively, employ the
h,j,k, andlkeys 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.
- Move the cursor to the beginning of the next word with
- Навигационные линии:
- Go to the start of the line by pressing
0. - Move to the end of the line with
$.
- Go to the start of the line by pressing
Редактирование текста в VIM
Once you’ve reached the desired location, these shortcuts will aid in text manipulation:
- Вход в режим вставки:
- Press
ito enter insert mode before the cursor. - Use
Ito start inserting at the beginning of the line. - Employ
ato append after the cursor. Aпозволяет добавлять в конец строки.
- Press
- Удаление текста:
- 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.
- Delete the character under the cursor with
- Скопируйте и вставьте:
- Copy a line with
yy. - Paste the copied line below the current line using
p.
- Copy a line with
- Отменить и повторить:
- Undo the last action with
u. - Redo with
Ctrl + r.
- Undo the last action with
Поиск в ВИМ
Эффективный поиск имеет решающее значение. Вот несколько ярлыков, связанных с поиском:
- Поиск текста:
- Initiate a search with
/, followed by the desired term. - Use
nto jump to the next occurrence andNto go to the previous one.
- Initiate a search with
- Замена текста:
- Substitute the current word with a new one using
:s/old/new/g.
- Substitute the current word with a new one using
Выход из Vim
Вначале я уже рассмотрел основы, но вот еще несколько вариантов:
- Сохранить и закрыть все:
- To save all changes and quit multiple files simultaneously, use
:waи:qa.
- To save all changes and quit multiple files simultaneously, use
- Выход без сохранения:
- If you want to exit Vim without saving any changes made in any of the files,
:qa!will do the trick.
- If you want to exit Vim without saving any changes made in any of the files,
Заключение
Помните, что освоение Vim требует времени и практики. Чем больше вы его используете, тем удобнее и мощнее он становится. Приятного редактирования!






