2015-12-28 13:06:58 +01:00
|
|
|
# vim
|
|
|
|
|
2020-01-22 16:38:21 -07:00
|
|
|
> Vim (Vi IMproved), a programmer's command-line text editor, provides several modes for different kinds of text manipulation.
|
2016-10-11 22:28:22 -05:00
|
|
|
> Pressing `i` enters edit mode. `<Esc>` goes back to normal mode, which doesn't allow regular text insertion.
|
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
|
|
|
|
2020-01-22 16:38:21 -07:00
|
|
|
- Save a file:
|
2015-12-28 13:06:58 +01:00
|
|
|
|
2020-01-22 16:38:21 -07:00
|
|
|
`:write`
|
2015-12-28 13:06:58 +01:00
|
|
|
|
2020-01-22 16:38:21 -07:00
|
|
|
- Quit without saving:
|
|
|
|
|
|
|
|
`<Esc>:quit!<Enter>`
|
|
|
|
|
|
|
|
- Open a file at a specified line number:
|
|
|
|
|
|
|
|
`vim +{{line_number}} {{path/to/file}}`
|
|
|
|
|
|
|
|
- View help for setting (such as {{set number}}):
|
2015-12-28 13:06:58 +01:00
|
|
|
|
2020-01-22 16:38:21 -07:00
|
|
|
`<Esc>:help '{{setting_name}}'`
|
2015-12-28 13:06:58 +01:00
|
|
|
|
2016-10-06 11:19:06 +01:00
|
|
|
- Undo the last operation:
|
2015-12-28 13:06:58 +01:00
|
|
|
|
2016-10-11 22:28:22 -05:00
|
|
|
`<Esc>u`
|
2015-12-29 12:09:30 -05:00
|
|
|
|
2016-10-11 22:28:22 -05: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
|
|
|
|
2016-10-11 22:28:22 -05:00
|
|
|
`<Esc>/{{search_pattern}}<Enter>`
|
2015-12-29 12:09:30 -05:00
|
|
|
|
2017-10-21 22:01:49 +02:00
|
|
|
- Perform a regex substitution in the whole file:
|
2016-01-05 17:07:51 -05:00
|
|
|
|
2017-10-19 19:27:18 +02:00
|
|
|
`<Esc>:%s/{{pattern}}/{{replacement}}/g<Enter>`
|