From a9c119a2fdf5af353ddbc93910a22806d772f848 Mon Sep 17 00:00:00 2001 From: tocariimaa Date: Sun, 9 Mar 2025 14:19:58 -0300 Subject: [PATCH] articles/vi.md: update --- articles/vi.md | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/articles/vi.md b/articles/vi.md index d48ca61..eb16976 100644 --- a/articles/vi.md +++ b/articles/vi.md @@ -1,11 +1,21 @@ # vi vi is a family of **vi**sual text editors originated in [BSD](bsd.md) [Unix](unix.md). +vi was created by Bill Joy as a visual form of the line-based ex editor +(an extension to the classic [ed](ed.md), also line-based). + In contrast to most editors, vi is a modal editor, in which its behavior depends on the current -mode that is in. For example, the starting mode is the *normal* mode in which vi accept -commands; the *insert* mode, where vi accepts keys and writes them to the current buffer; the -*replacement* mode, similar to insert mode but replaces the characters under the cursor instead of -adding them to the buffer; the *visual* mode which allows for selection of text. +mode that is in. For example, the starting mode is the *normal* mode; the *command* mode entered +by typing `:` in normal mode; the *insert* mode, where vi accepts keys and writes them to the +current buffer; the *replacement* mode, similar to insert mode but replaces the characters under +the cursor instead of adding them to the buffer; the *visual* mode which allows for selection of text. + +## vi keybinds or: why HJKL for navigation and Escape +vi was developed in a ADM-3A video terminal. This terminal had of course a different keyboard layout +from the modern standard IBM PC layout. On that keyboard, the Escape key was actually where is now the +Tab key. It also lacked dedicated arrow keys, instead using the keys H, J, K, L as the arrow keys. + +[Emacs](emacs.md) is also a victim of the IBM PC keyboard (Control was where now the Alt key is located). ## Tutorial Vim provides a tutorial, accesible through the `vimtutor` *shell* command; Neovim provides the same @@ -14,6 +24,9 @@ tutorial with the `:Tutor` *editor* command. TODO ## Cheatsheet +This is a basic quick cheatsheet of some Vim commands/keybinds. Always refer to the documentation +in doubt of something by using the `:help ` command or `` to access the help index. + Some of these can be prefixed with a register name and a count number (in that order). Commands that work with registers use by default an anonymous registers if none is explicitly specified. @@ -73,6 +86,7 @@ a command or normal mode binding was executed. - (n) `c`: change, roughly equivalent to a combined delete and insert ### Mode changing +- (n) `:`: Enter command mode - (n) `i`: Enter insert mode after the cursor - (n) `I`: Enter insert mode, at the start of the line - (n) `a`: Enter insert mode before the cursor @@ -109,8 +123,18 @@ It has to be noted that `Home`, `End`, `PageUp/Down` and cursor keys also work. - (v) `U`: uppercase the current selection - (n) `q:`: open command-line history window, here you can edit the commands and execute them with enter. - (n) `q/`: search pattern history +- (n) `K`: look for the identifier under the cursor in the man pages, really useful when you're doing C programming. +- (n) `.`: repeat last action - `:help`, `:h`: Vim help pages +### Macros +- (n) `q`: start recording macro to register + - `qq`: record macro using register `@q` +- (n) `@`: replay macro in register + - `@q`: replay macro from `@q` register + - `4@q`: ditto, but repeat it four times +- (n) `Q`: replay last recorded macro + ### Windows (splits) - `:vs`: create vertical split - `:sp`: horizontal split @@ -134,7 +158,7 @@ It has to be noted that `Home`, `End`, `PageUp/Down` and cursor keys also work. - `:bd!`: same but doesn't nag if the buffer wasn't been saved - `:bp`: go to previous buffer - `:bn`: go to next buffer -- `:b#`: go to last buffer (`#` holds the last buffer ID) +- `:b#`: go to last used buffer (`#` holds the ID of that buffer) ### "Go to" binds - `gg`: go to.. @@ -163,3 +187,6 @@ VimScript for extending the editor. ## Resources - [Vim Kōans](https://blog.sanctum.geek.nz/vim-koans/) - [The Dharma of Vi](https://blog.samwhited.com/2015/04/the-dharma-of-vi/) + +## See also +- [ed](ed.md)