2015-12-28 13:06:58 +01:00
|
|
|
# vim
|
|
|
|
|
2020-01-27 08:40:57 -07:00
|
|
|
> Vim (Vi IMproved), a command-line text editor, provides several modes for different kinds of text manipulation.
|
2025-03-09 03:23:24 +02:00
|
|
|
> Pressing `<i>` in normal mode enters insert mode. Pressing `<Esc>` goes back to normal mode, which enables the use of Vim commands.
|
2023-11-23 14:55:03 +01:00
|
|
|
> See also: `vimdiff`, `vimtutor`, `nvim`.
|
2019-06-03 02:06:36 +02:00
|
|
|
> More information: <https://www.vim.org>.
|
2015-12-28 13:06:58 +01:00
|
|
|
|
2016-10-06 11:19:06 +01:00
|
|
|
- Open a file:
|
2015-12-28 13:06:58 +01:00
|
|
|
|
2020-01-22 16:38:21 -07:00
|
|
|
`vim {{path/to/file}}`
|
2015-12-28 13:06:58 +01:00
|
|
|
|
2021-08-14 14:48:15 +02:00
|
|
|
- Open a file at a specified line number:
|
|
|
|
|
|
|
|
`vim +{{line_number}} {{path/to/file}}`
|
|
|
|
|
2020-01-27 08:42:51 -07:00
|
|
|
- View Vim's help manual:
|
|
|
|
|
2025-03-09 03:23:24 +02:00
|
|
|
`<:>help<Enter>`
|
2020-01-27 08:42:51 -07:00
|
|
|
|
2022-10-17 12:29:21 +02:00
|
|
|
- Save and quit the current buffer:
|
2015-12-28 13:06:58 +01:00
|
|
|
|
2025-03-09 03:23:24 +02:00
|
|
|
`{{<Esc><Z><Z>|<Esc><:>x<Enter>|<Esc><:>wq<Enter>}}`
|
2020-01-22 16:38:21 -07:00
|
|
|
|
2022-10-17 12:29:21 +02:00
|
|
|
- Enter normal mode and undo the last operation:
|
2015-12-28 13:06:58 +01:00
|
|
|
|
2025-03-09 03:23:24 +02:00
|
|
|
`<Esc><u>`
|
2015-12-29 12:09:30 -05:00
|
|
|
|
2025-03-09 03:23:24 +02:00
|
|
|
- Search for a pattern in the file (press `<n>`/`<N>` to go to next/previous match):
|
2015-12-29 12:09:30 -05:00
|
|
|
|
2025-03-09 03:23:24 +02:00
|
|
|
`</>{{search_pattern}}<Enter>`
|
2015-12-29 12:09:30 -05:00
|
|
|
|
2021-05-10 11:03:12 +02:00
|
|
|
- Perform a regular expression substitution in the whole file:
|
2016-01-05 17:07:51 -05:00
|
|
|
|
2025-03-09 03:23:24 +02:00
|
|
|
`<:>%s/{{regular_expression}}/{{replacement}}/g<Enter>`
|
2020-10-31 21:42:18 +01:00
|
|
|
|
|
|
|
- Display the line numbers:
|
|
|
|
|
2025-03-09 03:23:24 +02:00
|
|
|
`<:>set nu<Enter>`
|