2015-12-28 13:06:58 +01:00
|
|
|
# vim
|
|
|
|
|
2016-10-06 11:19:06 +01:00
|
|
|
> Vi IMproved, a programmer's text editor, providing several modes for different kinds of text manipulation.
|
|
|
|
> Pressing `i` enters edit mode; the normal mode (accessed via `<Esc>`) doesn't allow regular text editing.
|
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
|
|
|
|
2016-10-06 11:19:06 +01:00
|
|
|
`vim {{file}}`
|
2015-12-28 13:06:58 +01:00
|
|
|
|
2016-10-06 11:19:06 +01:00
|
|
|
- Enter text editing mode (insert mode):
|
2015-12-28 13:06:58 +01:00
|
|
|
|
2016-10-06 11:19:06 +01:00
|
|
|
`<Esc> i`
|
2015-12-28 13:06:58 +01:00
|
|
|
|
2016-10-06 11:19:06 +01:00
|
|
|
- Copy ("yank") or cut ("delete") the current line (paste it with `P`):
|
2015-12-28 13:06:58 +01:00
|
|
|
|
2016-10-06 11:19:06 +01:00
|
|
|
`<Esc> {{yy|dd}}`
|
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-06 11:19:06 +01:00
|
|
|
`<Esc> u`
|
2015-12-29 12:09:30 -05:00
|
|
|
|
2016-10-06 11:19:06 +01:00
|
|
|
- Search for a pattern in the file (press `n` to go to the next result):
|
2015-12-29 12:09:30 -05:00
|
|
|
|
2016-10-06 11:19:06 +01:00
|
|
|
`<Esc> /{{search_pattern}} <Enter>`
|
2015-12-29 12:09:30 -05:00
|
|
|
|
2016-10-06 11:19:06 +01:00
|
|
|
- Perform a regex substitution in the whole file (from the start, `1`, to the end, `$`):
|
2016-01-05 17:07:51 -05:00
|
|
|
|
2016-10-06 11:19:06 +01:00
|
|
|
`<Esc> :1,$s/{{pattern}}/{{replacement}}/g <Enter>`
|
2015-12-29 12:09:30 -05:00
|
|
|
|
2016-10-06 11:19:06 +01:00
|
|
|
- Save (write) the file, and quit vim:
|
2016-01-05 17:07:51 -05:00
|
|
|
|
2016-10-06 11:19:06 +01:00
|
|
|
`<Esc> :wq <Enter>`
|