Ensure proper upper/lower-case for every Ctrl-... shortcut

pull/48/head
Florian Rager 4 years ago
parent 5e95666a2d
commit ef1fc2f3a4

@ -171,7 +171,7 @@ vim -O5 hello1.txt hello2.txt
## Suspending
If you need to suspend Vim while in the middle of editing, you can press `Ctrl-Z`. Alternatively, you can also run either the `:stop` or `:suspend` command.
If you need to suspend Vim while in the middle of editing, you can press `Ctrl-z`. Alternatively, you can also run either the `:stop` or `:suspend` command.
To return to the suspended Vim, run `fg` from the terminal.

@ -87,10 +87,10 @@ Now you are looking at two buffers through **two windows**. The top window displ
By the way, if you want to navigate between windows, you can use these commands:
```
Ctrl-W h Moves the cursor to the left window
Ctrl-W j Moves the cursor to the window below
Ctrl-W k Moves the cursor to the window upper
Ctrl-W l Moves the cursor to the right window
Ctrl-w h Moves the cursor to the left window
Ctrl-w j Moves the cursor to the window below
Ctrl-w k Moves the cursor to the window upper
Ctrl-w l Moves the cursor to the right window
```
@ -113,14 +113,14 @@ You can have multiple windows displaying the same buffer. While you're on the to
Now both top left and top right windows are displaying `file2.js` buffer. If you start typing on the top left, you'll see that the content on both top left and top right window are changing in real time.
To close the current window, you can run `Ctrl-W c` or type `:quit`. When you close a window, the buffer will still be there (again, to view your buffers, you can use `:buffers, :ls, :files`).
To close the current window, you can run `Ctrl-w c` or type `:quit`. When you close a window, the buffer will still be there (again, to view your buffers, you can use `:buffers, :ls, :files`).
Here are some useful normal mode window commands:
```
Ctrl-W v Opens a new vertical split
Ctrl-W s Opens a new horizontal split
Ctrl-W c Closes a window
Ctrl-W o Makes the current window the only one on screen and closes other windows
Ctrl-w v Opens a new vertical split
Ctrl-w s Opens a new horizontal split
Ctrl-w c Closes a window
Ctrl-w o Makes the current window the only one on screen and closes other windows
```
And here is a list of useful window Ex commands:
```
@ -173,7 +173,7 @@ vim -p file1.js file2.js file3.js
```
## Moving In 3D
Moving between windows is like traveling two-dimensionally along X-Y axis in a Cartesian coordinate. You can move to the top, right, bottom, and left window with `Ctrl-W h/j/k/l`.
Moving between windows is like traveling two-dimensionally along X-Y axis in a Cartesian coordinate. You can move to the top, right, bottom, and left window with `Ctrl-w h/j/k/l`.
![cartesian movement in x and y axis](./img/cartesian-xy.png)

@ -198,11 +198,11 @@ nG Go to line n
n% Go to n% in file
```
By the way, if you want to see total lines in a file, you can use `CTRL-G`.
By the way, if you want to see total lines in a file, you can use `Ctrl-g`.
## Window Navigation
To quickly go to the top, middle, or bottom of your *window*, you can use `H`, `M`, and `L`.
To quickly go to the top, middle, or bottom of your *window*, you can use `H`, `M`, and `L`.
You can also pass a count to `H` and `L`. If you use `10H`, you will go to 10 lines below the top of window. If you use `3L`, you will go to 3 lines above the last line of window.
```
@ -215,7 +215,7 @@ nL Go n line from bottom
## Scrolling
To scroll, you have 3 speed increments: full-screen (`CTRL-F/CTRL-B`), half-screen (`CTRL-D/CTRL-U`), and line (`CTRL-E/CTRL-Y`).
To scroll, you have 3 speed increments: full-screen (`Ctrl-f/Ctrl-b`), half-screen (`Ctrl-d/Ctrl-u`), and line (`Ctrl-e/Ctrl-y`).
```
Ctrl-e Scroll down a line

@ -22,7 +22,7 @@ If you do `u`, Vim undoes the text "two".
How does Vim know how much to undo? Vim undoes a single "change" at a time, similar to a dot command's change (unlike the dot command, command-line commands also count as change).
To redo the last change, run `Ctrl-R` or `:redo`. After you undo the text above to remove "two", you can run `Ctrl-R` to get the removed text back.
To redo the last change, run `Ctrl-r` or `:redo`. After you undo the text above to remove "two", you can run `Ctrl-r` to get the removed text back.
Vim also has UNDO that you can run with `U`. It undoes all latest changes.
@ -68,9 +68,9 @@ I mentioned earlier that `u` undoes a single "change" similar to the dot command
If you do `ione two three<esc>` then press `u`, Vim removes the entire "one two three" text because it is considered a change. This would have been acceptable if you have a short text, but what if you have written several paragraphs under one insert mode session without exiting and later you realized you made a mistake? If you press `u`, everything you had written would be removed. Wouldn't it be useful if you can press `u` to remove only a section of your text?
Luckily, you can break the undo blocks. When you are typing in insert mode, pressing `Ctrl-G u` creates an undo breakpoint. For example, if you do `ione <Ctrl-G u>two <Ctrl-G u>three<esc>`, then press `u`, you will only lose the text "three". Press `u` one more time to remove "two". When you write a long text, use `Ctrl-G u` strategically. The end of each sentence, between two paragraphs, or after each line of code are good locations to add undo breakpoints to make it easier to undo your mistakes if you ever make one.
Luckily, you can break the undo blocks. When you are typing in insert mode, pressing `Ctrl-g u` creates an undo breakpoint. For example, if you do `ione <Ctrl-g u>two <Ctrl-g u>three<esc>`, then press `u`, you will only lose the text "three". Press `u` one more time to remove "two". When you write a long text, use `Ctrl-g u` strategically. The end of each sentence, between two paragraphs, or after each line of code are good locations to add undo breakpoints to make it easier to undo your mistakes if you ever make one.
It is also useful to create an undo breakpoint when deleting chunks in insert mode with `Ctrl-W` (delete the word before the cursor) and `Ctrl-U` (delete all text before the cursor). A friend suggested to use the following mappings:
It is also useful to create an undo breakpoint when deleting chunks in insert mode with `Ctrl-w` (delete the word before the cursor) and `Ctrl-u` (delete all text before the cursor). A friend suggested to use the following mappings:
```
inoremap <c-u> <c-g>u<c-u>
inoremap <c-w> <c-g>u<c-w>
@ -165,7 +165,7 @@ four
In Vim, every time you press `u` and then make a different change, Vim stores the previous state's text by creating an "undo branch". In this example, after you typed "two", then pressed `u`, then typed "three", you created an undo leaf branch that stores the state containing the text "two". At that moment, the undo tree contained at least two leaf nodes: the main node containing the text "three" (most recent) and the undo branch node containing the text "two". If you had done another undo and typed the text "four", you now have at least three nodes: a main node containing the text "four" and two nodes containing the texts "three" and "two".
To traverse each node in the undo tree, you can use `g+` to go to a newer state and `g-` to go to an older state. The difference between `u`, `Ctrl-R`, `g+`, and `g-` is that both `u` and `Ctrl-R` traverse only the *main* nodes in undo tree while `g+` and `g-` traverse *all* nodes in the undo tree.
To traverse each node in the undo tree, you can use `g+` to go to a newer state and `g-` to go to an older state. The difference between `u`, `Ctrl-r`, `g+`, and `g-` is that both `u` and `Ctrl-r` traverse only the *main* nodes in undo tree while `g+` and `g-` traverse *all* nodes in the undo tree.
Undo tree is not easy to visualize. I find [vim-mundo](https://github.com/simnalamburt/vim-mundo) plugin to be very useful to help visualize Vim's undo tree. Give it some time to play around with it.
@ -260,7 +260,7 @@ The same set of arguments work with `:earlier` counterpart: `:later`.
## Learn Undo The Smart Way
`u` and `Ctrl-R` are two indispensable Vim commands. Learn them first. I do not use UNDO in my workflow, however I think it's good to be aware that it exists. Next, learn how to use `:earlier` and `:later` using the time arguments first. After that, take your time to understand the undo tree. The [vim-mundo](https://github.com/simnalamburt/vim-mundo) plugin helped me a lot. Type along the texts in this chapter and check the undo tree as you make each change. Once you grasp it, you will never see undo system the same way again.
`u` and `Ctrl-r` are two indispensable Vim commands. Learn them first. I do not use UNDO in my workflow, however I think it's good to be aware that it exists. Next, learn how to use `:earlier` and `:later` using the time arguments first. After that, take your time to understand the undo tree. The [vim-mundo](https://github.com/simnalamburt/vim-mundo) plugin helped me a lot. Type along the texts in this chapter and check the undo tree as you make each change. Once you grasp it, you will never see undo system the same way again.
Prior to this chapter, you learned how to find any text in a project space, with undo, you can now find any text in a time dimension. You are now able to search for any text by its location and time written. You have achieved Vim-omnipresence.

@ -22,15 +22,15 @@ Character-wise visual mode is used to select individual characters. Press `v` on
Line-wise visual mode works with line units. Press `V` and watch Vim selects the entire line your cursor is on. Just like character-wise visual mode, if you run `gU`, Vim uppercases the highlighted characters.
Block-wise visual mode works with rows and columns. It gives you more freedom to move around than the other two modes. Press `Ctrl-V`. Vim highlights the character under the cursor just like character-wise visual mode, except instead of highlighting each character until the end of the line before going to the next line, it can go to the next line without highlighting the entire character on the current line. Try moving around with `h/j/k/l` and watch the cursor movements.
Block-wise visual mode works with rows and columns. It gives you more freedom to move around than the other two modes. Press `Ctrl-v`. Vim highlights the character under the cursor just like character-wise visual mode, except instead of highlighting each character until the end of the line before going to the next line, it can go to the next line without highlighting the entire character on the current line. Try moving around with `h/j/k/l` and watch the cursor movements.
On the bottom left of your Vim window, you will see either `-- VISUAL --`, `-- VISUAL LINE --`, or `-- VISUAL BLOCK --` displayed to indicate which visual mode you are in.
While you are inside a visual mode, you can switch to another visual mode by pressing either `v`, `V`, or `Ctrl-V`. For example, if you are in line-wise visual mode and you want to switch to block-wise visual mode, run `Ctrl-V`. Try it!
While you are inside a visual mode, you can switch to another visual mode by pressing either `v`, `V`, or `Ctrl-v`. For example, if you are in line-wise visual mode and you want to switch to block-wise visual mode, run `Ctrl-v`. Try it!
There are three ways to exit the visual mode: `esc`, `Ctrl-C`, and the same key as your current visual mode.
There are three ways to exit the visual mode: `esc`, `Ctrl-c`, and the same key as your current visual mode.
What the latter one means is if you are currently in the line-wise visual mode (`V`), you can exit it by pressing `V` again. If you are in the character-wise visual mode, you can exit it by pressing `v`. If you are in the block-wise visual mode, press `Ctrl-V`.
What the latter one means is if you are currently in the line-wise visual mode (`V`), you can exit it by pressing `V` again. If you are in the character-wise visual mode, you can exit it by pressing `v`. If you are in the block-wise visual mode, press `Ctrl-v`.
There is actually one more way to enter the visual mode:
```
@ -189,7 +189,7 @@ const three = "three"
```
With your cursor on the first line:
- Run block-wise visual mode and go down two lines (`Ctrl-V jj`).
- Run block-wise visual mode and go down two lines (`Ctrl-v jj`).
- Highlight to the end of the line (`$`).
- Append (`A`) then type ";".
- Exit visual mode (`esc`).
@ -205,7 +205,7 @@ Remember, `:normal` command executes normal mode commands. You can instruct it t
## Incrementing Numbers
Vim has `Ctrl-X` and `Ctrl-A` commands to decrement and increment numbers. When used with visual mode, you can increment numbers across multiple lines.
Vim has `Ctrl-x` and `Ctrl-a` commands to decrement and increment numbers. When used with visual mode, you can increment numbers across multiple lines.
If you have these HTML elements:
```
@ -218,8 +218,8 @@ If you have these HTML elements:
It is a bad practice to have several ids having the same name, so let's increment them to make them unique:
- Move your cursor to the *second* "1".
- Start block-wise visual mode and go down 3 lines (`Ctrl-V 3j`). This highlights the remaining "1"s.
- Run `g Ctrl-A`.
- Start block-wise visual mode and go down 3 lines (`Ctrl-v 3j`). This highlights the remaining "1"s.
- Run `g Ctrl-a`.
You should see this result:
```
@ -230,13 +230,13 @@ You should see this result:
<div id="app-5"></div>
```
`g Ctrl-A` increments numbers on multiple lines. `Ctrl-X/Ctrl-A` can increment letters too. If you run:
`g Ctrl-a` increments numbers on multiple lines. `Ctrl-x/Ctrl-a` can increment letters too. If you run:
```
:set nrformats+=alpha
```
The `nrformats` option instructs Vim which bases are considered as "numbers" for `Ctrl-A` and `Ctrl-X` to increment and decrement. By adding `alpha`, an alphabetical character is now considered as a number. If you have the following HTML elements:
The `nrformats` option instructs Vim which bases are considered as "numbers" for `Ctrl-a` and `Ctrl-x` to increment and decrement. By adding `alpha`, an alphabetical character is now considered as a number. If you have the following HTML elements:
```
<div id="app-a"></div>
<div id="app-a"></div>
@ -245,7 +245,7 @@ The `nrformats` option instructs Vim which bases are considered as "numbers" for
<div id="app-a"></div>
```
Put your cursor on the second "app-a". Use the same technique as above (`Ctrl-V 3j` then `g Ctrl-A`) to increment the ids.
Put your cursor on the second "app-a". Use the same technique as above (`Ctrl-v 3j` then `g Ctrl-a`) to increment the ids.
```
<div id="app-a"></div>
<div id="app-b"></div>
@ -277,10 +277,10 @@ You were actually executing `s/const/let/g` command using marks as range. You ca
You can also enter visual mode from the insert mode. To go to character-wise visual mode while you are in insert mode:
```
Ctrl-O v
Ctrl-o v
```
Recall that running `Ctrl-O` while in the insert mode lets you to execute a normal mode command. While in this normal-mode-command-pending mode, run `v` to enter character-wise visual mode. Notice that on the bottom left of the screen, it says `--(insert) VISUAL--`. This trick works with any visual mode operator: `v`, `V`, and `Ctrl-V`.
Recall that running `Ctrl-o` while in the insert mode lets you to execute a normal mode command. While in this normal-mode-command-pending mode, run `v` to enter character-wise visual mode. Notice that on the bottom left of the screen, it says `--(insert) VISUAL--`. This trick works with any visual mode operator: `v`, `V`, and `Ctrl-v`.
## Select Mode

@ -58,7 +58,7 @@ Running `/hello$` will not match anything because "friend" is the last term in t
You can repeat the previous search with `//`. If you have just searched for `/hello`, running `//` is equivalent to running `/hello`. This shortcut can save you some keystrokes especially if you just did a long search term. Also recall that you can also use `n` and `N` to repeat the last search with the same direction and opposite direction, respectively.
What if you want to quickly recall *n* last search term? You can quickly traverse the search history by first pressing `/`, then press `up`/`down` arrow keys (or `Ctrl-N`/`Ctrl-P`) until you find the search term you need. To see all your search history, you can run `:history /`.
What if you want to quickly recall *n* last search term? You can quickly traverse the search history by first pressing `/`, then press `up`/`down` arrow keys (or `Ctrl-n`/`Ctrl-p`) until you find the search term you need. To see all your search history, you can run `:history /`.
When you reach the end of a file while searching, Vim throws an error: `"Search hit the BOTTOM without match for: <your-search>"`. Sometimes this can be a good safeguard from oversearching, but other times you want to cycle the search back to the top again. You can use the `set wrapscan` option to make Vim to search back at the top of the file when you reach the end of the file. To turn this feature off, do `set nowrapscan`.

@ -14,7 +14,7 @@ There are 4 different commands you can use to enter the command-line mode:
You can enter the command-line mode from the normal mode or the visual mode.
To leave the command-line mode, you can use `<esc>`, `Ctrl-C, or Ctrl-[`.
To leave the command-line mode, you can use `<esc>`, `Ctrl-c, or Ctrl-[`.
*Sometimes other literatures might refer the "Command-line command" as "Ex command" and the "External command" as "filter command" or "bang operator".*
@ -31,16 +31,16 @@ While in the command-line mode, you can move to the left or to the right, one ch
If you need to move word-wise, use `Shift-Left` or `Shift-Right` (in some OS, you might have to use `Ctrl` instead of `Shift`).
To go to the start of the line, use `Ctrl-B`. To go to the end of the line, use `Ctrl-E`.
To go to the start of the line, use `Ctrl-b`. To go to the end of the line, use `Ctrl-e`.
Similar to the insert mode, inside the command-line mode, you have three ways to delete characters:
```
Ctrl-H Delete one character
Ctrl-W Delete one word
Ctrl-U Delete the entire line
Ctrl-h Delete one character
Ctrl-w Delete one word
Ctrl-u Delete the entire line
```
Finally, if you want to edit the command like you would a normal textfile use `Ctrl-F`.
Finally, if you want to edit the command like you would a normal textfile use `Ctrl-f`.
This also allows you to search through the previous commands, edit them and rerun them by pressing `Enter` in "command-line editing normal mode".
@ -48,9 +48,9 @@ This also allows you to search through the previous commands, edit them and reru
When programming, whenever possible, do not repeat if you can autocomplete it. This mindset will not only save you time but reduces the chances of typing the wrong characters.
You can insert texts from Vim register with `Ctrl-R` (the same way as the insert mode). If you have the string "foo" saved in the register "a" (`"a`), you can insert it by running `Ctrl-R a`. Everything that you can get from the register in the insert mode, you can do the same from the command-line mode.
You can insert texts from Vim register with `Ctrl-r` (the same way as the insert mode). If you have the string "foo" saved in the register "a" (`"a`), you can insert it by running `Ctrl-r a`. Everything that you can get from the register in the insert mode, you can do the same from the command-line mode.
You can also autocomplete commands. To autocomplete the `echo` command, while in the command-line mode, type "ec", then press `<Tab>`. You should see on the bottom left Vim commands starting with "ec" (example: `echo echoerr echohl echomsg econ`). To go to the next option, press either `<Tab>` or `Ctrl-N`. To go the previous option, press either `<Shift-Tab>` or `Ctrl-P`.
You can also autocomplete commands. To autocomplete the `echo` command, while in the command-line mode, type "ec", then press `<Tab>`. You should see on the bottom left Vim commands starting with "ec" (example: `echo echoerr echohl echomsg econ`). To go to the next option, press either `<Tab>` or `Ctrl-n`. To go the previous option, press either `<Shift-Tab>` or `Ctrl-p`.
Some command-line commands accept file names as arguments. One example is `edit`. After typing the command, `:e ` (don't forget the space), press `<Tab>`. Vim will list all the relevant file names.
@ -92,7 +92,7 @@ q/ Forward search window
q? Backward search window
```
Run `q:` to launch the command-line window for command-line commands. Vim will launch a new window at the bottom of the screen. You can traverse upward with the `Up` or `Ctrl-P` keys and traverse downward with the `Down` or `Ctrl-N` keys. If you press `<Return>`, Vim executes that command. To quit the command-line window, either press `Ctrl-C`, `Ctrl-W C`, or type `:quit`.
Run `q:` to launch the command-line window for command-line commands. Vim will launch a new window at the bottom of the screen. You can traverse upward with the `Up` or `Ctrl-p` keys and traverse downward with the `Down` or `Ctrl-n` keys. If you press `<Return>`, Vim executes that command. To quit the command-line window, either press `Ctrl-c`, `Ctrl-w c`, or type `:quit`.
Similarly, to launch the command-line window for search, run `q/` to search forward and `q?` to search backward.

@ -285,9 +285,9 @@ Vim has a normal mode key for `tjump`: `g Ctrl-]`. I personally like `g Ctrl-]`
## Autocompletion With Tags
Tags can assist autocompletions. Recall from chapter 6, Insert Mode, that you can use `Ctrl-X` sub-mode to do various autocompletions. One autocompletion sub-mode that I did not mention was `Ctrl-]`. If you do `Ctrl-X Ctrl-]` while in the insert mode, Vim will use the tag file for autocompletion.
Tags can assist autocompletions. Recall from chapter 6, Insert Mode, that you can use `Ctrl-x` sub-mode to do various autocompletions. One autocompletion sub-mode that I did not mention was `Ctrl-]`. If you do `Ctrl-x Ctrl-]` while in the insert mode, Vim will use the tag file for autocompletion.
If you go into the insert mode and type `Ctrl-X Ctrl-]`, you will see:
If you go into the insert mode and type `Ctrl-x Ctrl-]`, you will see:
```
One
@ -324,7 +324,7 @@ Note that the `>` symbol is now on line two, where the `donut` is. `pop` one mor
2 1 donut 9 one.donut
```
In normal mode, you can run `Ctrl-T` to achieve the same effect as `:pop`.
In normal mode, you can run `Ctrl-t` to achieve the same effect as `:pop`.
## Automatic Tag Generation

@ -32,7 +32,7 @@ You can open a folded text with `zo`. To close the fold, use `zc`.
Vim fold follows the grammar rule. You can pass the fold operator with a motion or text object. To fold an outer paragraph, run `zfap`. To fold to the end of a file, run `zfG`. To fold the texts between `{` and `}`, run `zfa{`.
You can fold from the visual mode. Highlight the area you want to fold (`v`, `V`, or `Ctrl-V`), then run `zf`.
You can fold from the visual mode. Highlight the area you want to fold (`v`, `V`, or `Ctrl-v`), then run `zf`.
A Vim operator is not complete without the command-line mode version. You can execute a fold from the command-line mode with the `:fold` command. To fold the current line and the line after it, run:

@ -247,7 +247,7 @@ To get started, install the vim-fugitive with a vim plugin manager ( [vim-plug](
When you run the `:Git` command without any parameters, vim-fugitive displays a git summary window. It shows the untracked, unstaged, and staged file(s). While in this "`git status`" mode, you can do several things:
- `Ctrl-N` / `Ctrl-P` to go up or down the file list.
- `Ctrl-n` / `Ctrl-p` to go up or down the file list.
- `-` to stage or unstage the file name under the cursor.
- `s` to stage the file name under the cursor.
- `u` to unstage the file name under the cursor.

Loading…
Cancel
Save