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