tldr/pages/common/vim.md

38 lines
797 B
Markdown
Raw Normal View History

2015-12-28 15:06:58 +03:00
# vim
2018-08-28 12:25:58 +03:00
> Vi IMproved, a programmer's text editor, provides several modes for different kinds of text manipulation.
> Pressing `i` enters edit mode. `<Esc>` goes back to normal mode, which doesn't allow regular text insertion.
> More information: <https://www.vim.org>.
2015-12-28 15:06:58 +03:00
- Open a file:
2015-12-28 15:06:58 +03:00
`vim {{file}}`
2015-12-28 15:06:58 +03:00
- Enter text editing mode (insert mode):
2015-12-28 15:06:58 +03:00
`<Esc>i`
2015-12-28 15:06:58 +03:00
- Copy ("yank") or cut ("delete") the current line (paste it with `P`):
2015-12-28 15:06:58 +03:00
`<Esc>{{yy|dd}}`
2015-12-28 15:06:58 +03:00
- Undo the last operation:
2015-12-28 15:06:58 +03:00
`<Esc>u`
2015-12-29 20:09:30 +03:00
- Search for a pattern in the file (press `n`/`N` to go to next/previous match):
2015-12-29 20:09:30 +03:00
`<Esc>/{{search_pattern}}<Enter>`
2015-12-29 20:09:30 +03:00
2017-10-21 23:01:49 +03:00
- Perform a regex substitution in the whole file:
2016-01-06 01:07:51 +03:00
2017-10-19 20:27:18 +03:00
`<Esc>:%s/{{pattern}}/{{replacement}}/g<Enter>`
2015-12-29 20:09:30 +03:00
- Save (write) the file, and quit:
2016-01-06 01:07:51 +03:00
`<Esc>:wq<Enter>`
- Quit without saving:
`<Esc>:q!<Enter>`