Update the chapter headings

pull/105/head
Igor Irianto 3 years ago
parent 7443ffbb2e
commit f5712e6c11

@ -18,7 +18,7 @@ You can go far using Vim without knowing any Vimscript, but knowing it will help
This guide is written for both beginner and advanced Vimmers. It starts out with broad and simple concepts and ends with specific and advanced concepts. If you're an advanced user already, I would encourage you to read this guide from start to finish anyway, because you will learn something new!
## How To Transition To Vim From Using A Different Text Editor
## How to Transition to Vim From Using a Different Text Editor
Learning Vim is a satisfying experience, albeit hard. There are two main approaches to learn Vim:
@ -39,7 +39,7 @@ Everyone programs differently. Upon introspection, you will find that there are
Once you can edit at 50% of the original speed, it's time to go full-time Vim.
## How To Read This Guide
## How to Read This Guide
This is a practical guide. To become good in Vim you need to develop your muscle memory, not head knowledge.

@ -30,7 +30,7 @@ There are several ways to exit Vim. The most common one is to type:
You can type `:q` for short. That command is a command-line mode command (another one of Vim modes). If you type `:` in normal mode, the cursor will move to the bottom of the screen where you can type some commands. You will learn about the command-line mode later in chapter 15. If you are in insert mode, typing `:` will literally produce the character ":" on the screen. In this case, you need to switch back to normal mode. Type `<Esc>` to switch to normal mode. By the way, you can also return to normal mode from command-line mode by pressing `<Esc>`. You will notice that you can "escape" out of several Vim modes back to normal mode by pressing `<Esc>`.
## Saving A File
## Saving a File
To save your changes, type:
@ -159,7 +159,7 @@ vim -O5 hello1.txt hello2.txt
If you need to suspend Vim while in the middle of editing, you can press `Ctrl-z`. You can also run either the `:stop` or `:suspend` command. To return to the suspended Vim, run `fg` from the terminal.
## Starting Vim The Smart Way
## Starting Vim the Smart Way
You can pass the `vim` command with different options and flags, just like any terminal commands. One of the options is the command-line command (`+{cmd}` or `-c cmd`). As you learn more commands throughout this guide, see if you can apply it on start. Also being a terminal command, you can combine `vim` with many other terminal commands. For example, you can redirect the output of the `ls` command to be edited in Vim with `ls -l | vim -`.

@ -170,7 +170,7 @@ To start Vim with multiple tabs, you can do this from the terminal:
vim -p file1.js file2.js file3.js
```
## Moving In 3D
## 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`.
@ -178,7 +178,7 @@ Moving between buffers is like traveling across the Z axis in a Cartesian coordi
You can move in *three-dimensional space* by combining window and buffer movements. You can move to the top, right, bottom, or left window (X-Y navigations) with window navigations. Since each window contains buffers, you can move forward and backward (Z navigations) with buffer movements.
## Using Buffers, Windows, and Tabs The Smart Way
## Using Buffers, Windows, and Tabs the Smart Way
You have learned what buffers, windows, and tabs are and how they work in Vim. Now that you understand them better, you can use them in your own workflow.

@ -4,7 +4,7 @@ The goal of this chapter is to introduce you to how to search quickly in Vim. Be
This chapter is divided into two parts: how to search without plugins and how to search with [fzf.vim](https://github.com/junegunn/fzf.vim) plugin. Let's get started!
## Opening And Editing Files
## Opening and Editing Files
To open a file in Vim, you can use `:edit`.
@ -59,7 +59,7 @@ Autocomplete also works with `:find`:
You may notice that `:find` looks like `:edit`. What's the difference?
## Find And Path
## Find and Path
The difference is that `:find` finds file in `path`, `:edit` doesn't. Let's learn a little bit about this `path`. Once you learn how to modify your paths, `:find` can become a powerful searching tool. To check what your paths are, do:
@ -111,7 +111,7 @@ You might be thinking to add the entire project directories so when you press `t
You can add the `set path+={your-path-here}` in your vimrc. Updating `path` takes only a few seconds and doing this will save you a lot of time.
## Searching In Files With Grep
## Searching in Files With Grep
If you need to find in files (find phrases in files), you can use grep. Vim has two ways of doing that:
@ -260,7 +260,7 @@ Since you will be using this command frequently, it is good to have this mapped.
nnoremap <silent> <C-f> :Files<CR>
```
## Finding In Files
## Finding in Files
To search inside files, you can use the `:Rg` command.
@ -309,7 +309,7 @@ You might wonder, "Well, this is nice but I never used `:grep` in Vim, plus can'
That is a very good question. You may need to use `:grep` in Vim to do search and replace in multiple files, which I will cover next.
## Search And Replace In Multiple Files
## Search and Replace in Multiple Files
Modern text editors like VSCode makes it very easy to search and replace a string across multiple files. In this section, I will show you two different methods to easily do that in Vim.
@ -332,7 +332,7 @@ The second method is to search and replace in select files. With this method, yo
3. Select all files you want to perform search-and-replace on. To select multiple files, use `<Tab>` / `<Shift-Tab>`. This is only possible if you have the multiple flag (`-m`) in `FZF_DEFAULT_OPTS`.
4. Run `:bufdo %s/pizza/donut/g | update`. The command `:bufdo %s/pizza/donut/g | update` looks similar to the earlier `:cfdo %s/pizza/donut/g | update` command. The difference is instead of substituting all quickfix entries (`:cfdo`), you are substituting all buffer entries (`:bufdo`).
## Learn Search The Smart Way
## Learn Search the Smart Way
Searching is the bread-and-butter of text editing. Learning how to search well in Vim will improve your text editing workflow significantly.

@ -4,7 +4,7 @@ It is easy to get intimidated by the complexity of Vim commands. If you see a Vi
This is the most important chapter in the entire guide. Once you understand the underlying grammatical structure, you will be able to "speak" to Vim. By the way, when I say *Vim language* in this chapter, I am not talking about Vimscript language (Vim's built-in programming language, you will learn that in later chapters).
## How To Learn A Language
## How to Learn a Language
I am not a native English speaker. I learned English when I was 13 when I moved to the US. There are three things you need to do to learn to speak a new language:
@ -60,7 +60,7 @@ c Delete text, save to register, and start insert mode
Btw, after you yank a text, you can paste it with `p` (after the cursor) or `P` (before the cursor).
## Verb And Noun
## Verb and Noun
Now that you know basic nouns and verbs, let's apply the grammar rule, verb + noun! Suppose you have this expression:
@ -152,7 +152,7 @@ t XML tags
To learn more, check out `:h text-objects`.
## Composability And Grammar
## Composability and Grammar
Vim grammar is subset of Vim's composability feature. Let's discuss composability in Vim and why this is a great feature to have in a text editor.
@ -201,7 +201,7 @@ This composable behavior echoes Unix philosophy: *do one thing well*. An operato
Motions and operators are extendable. You can create custom motions and operators to add to your Vim toolbelt. The [`vim-textobj-user`](https://github.com/kana/vim-textobj-user) plugin allows you to create your own text objects. It also contains a [list](https://github.com/kana/vim-textobj-user/wiki) of user-made custom text objects.
## Learn Vim Grammar The Smart Way
## Learn Vim Grammar the Smart Way
You just learned about Vim grammar's rule: `verb + noun`. One of my biggest Vim "AHA!" moments was when I had just learned about the uppercase (`gU`) operator and wanted to uppercase the current word, I *instinctively* ran `gUiw` and it worked! The word was uppercased. At that moment, I finally began to understand Vim. My hope is that you will have your own "AHA!" moment soon, if not already.

@ -1,4 +1,4 @@
# Ch05. Moving In A File
# Ch05. Moving in a File
In the beginning, moving with a keyboard feels slow and awkward but don't give up! Once you get used to it, you can go anywhere in a file faster than using a mouse.
@ -118,7 +118,7 @@ const hello = "world";
With your cursor at the start of the line, you can go to the last character in current line (";") with one keypress: `$`. If you want to go to "w" in "world", you can use `fw`. A good tip to go anywhere in a line is to look for least-common-letters like "j", "x", "z" near your target.
## Sentence And Paragraph Navigation
## Sentence and Paragraph Navigation
Next two navigation units are sentence and paragraph.
@ -338,7 +338,7 @@ For more, check out `:h jump-motions`.
Why are jumps useful? Because you can navigate the jump list with `Ctrl-O` to move up the jump list and `Ctrl-I` to move down the jump list. You can jump across different files, which I will discuss more in the next part.
## Learn Navigation The Smart Way
## Learn Navigation the Smart Way
If you are new to Vim, this is a lot to learn. I do not expect anyone to remember everything immediately. It takes time before you can execute them without thinking.

@ -4,7 +4,7 @@ Insert mode is the default mode of many text editors. In this mode, what you typ
However, that does not mean there isn't much to learn. Vim's insert mode contains many useful features. In this chapter, you will learn how to use these insert mode features in Vim to improve your typing efficiency.
## Ways To Go To Insert Mode
## Ways to Go to Insert Mode
There are many ways to get into insert mode from the normal mode. Here are some of them:
@ -23,7 +23,7 @@ gI Insert text at the start of line (column 1)
Notice the lowercase / uppercase pattern. For each lowercase command, there is an uppercase counterpart. If you are new, don't worry if you don't remember the whole list above. Start with `i` and `o`. They should be enough to get you started. Gradually learn more over time.
## Different Ways To Exit Insert Mode
## Different Ways to Exit Insert Mode
There are a few different ways to return to the normal mode while in the insert mode:
@ -52,7 +52,7 @@ You can pass a count parameter before entering insert mode. For example:
If you type "hello world!" and exit insert mode, Vim will repeat the text 10 times. This will work with any insert mode method (ex: `10I`, `11a`, `12o`).
## Deleting Chunks In Insert Mode
## Deleting Chunks in Insert Mode
When you make a typing mistake, it can be cumbersome to type `<Backspace>` repeatedly. It may make more sense to go to normal mode and delete your mistake. You can also delete several characters at a time while in insert mode.
@ -120,7 +120,7 @@ In general, Vim looks at the text in all available buffers for autocompletion so
Autocomplete is a vast topic in Vim. This is just the tip of the iceberg. To learn more, check out `:h ins-completion`.
## Executing A Normal Mode Command
## Executing a Normal Mode Command
Did you know Vim can execute a normal mode command while in insert mode?
@ -154,7 +154,7 @@ Ctrl-O dtz Delete from current location till the letter "z"
Ctrl-O D Delete from current location to the end of the line
```
## Learn Insert Mode The Smart Way
## Learn Insert Mode the Smart Way
If you are like me and you come from another text editor, it can be tempting to stay in insert mode. However, staying in insert mode when you're not entering a text is an anti-pattern. Develop a habit to go to normal mode when your fingers aren't typing new texts.

@ -1,4 +1,4 @@
# Ch07. The Dot Command
# Ch07. the Dot Command
In general, you should try to avoid redoing what you just did whenever possible. In this chapter, you will learn how to use the dot command to easily redo the previous change. It is a versatile command for reducing simple repetitions.
@ -22,7 +22,7 @@ let three = "3";
Here the dot command repeated the `cwconst<Esc>` sequence. It saved you from typing eight keystrokes in exchange for just one.
## What Is A Change?
## What Is a Change?
If you look at the definition of the dot command (`:h .`), it says that the dot command repeats the last change. What is a change?
@ -94,7 +94,7 @@ Let's remove all the z's. Starting from the first character on the first line, v
When you deleted a column of three z's (`Ctrl-vjjd`), it was counted as a change. Visual mode operation can be used to target multiple lines as part of a change.
## Including A Motion In A Change
## Including a Motion in a Change
Let's revisit the first example in this chapter. Recall that the command `/letcwconst<Esc>` followed by `n . n .` replaced all "let" with "const" in the following expressions:
@ -110,7 +110,7 @@ There is a faster way to accomplish this. After you searched `/let`, run `cgncon
When you are editing, always be on the lookout for motions that can do several things at once like `gn` whenever possible.
## Learn The Dot Command The Smart Way
## Learn the Dot Command the Smart Way
The dot command's power comes from exchanging several keystrokes for one. It is probably not a profitable exchange to use the dot command for single key operations like `x`. If your last change requires a complex operation like `cgnconst<Esc>`, the dot command reduces nine keypresses into one, a very profitable trade-off.

@ -56,7 +56,7 @@ Ctrl-R a
Where `a` is the register symbol. Now that you know how to store and retrieve registers, let's dive in!
## The Unnamed Register
## The Unnamed Register
To get the text from the unnamed register, do `""p`. It stores the last text you yanked, changed, or deleted. If you do another yank, change, or delete, Vim will automatically replace the old text. The unnamed register is like a computer's standard copy / paste operation.
@ -144,7 +144,7 @@ To get the text from register a, run `"ap`. You can use all twenty-six alphabeti
Sometimes you may want to add to your existing named register. In this case, you can append your text instead of starting all over. To do that, you can use the uppercase version of that register. For example, suppose you have the word "Hello " already stored in register a. If you want to add "world" into register a, you can find the text "world" and yank it using A register (`"Ayiw`).
## The Read-Only Registers
## The Read-only Registers
Vim has three read-only registers: `.`, `:`, and `%`. They are pretty simple to use:
@ -218,19 +218,19 @@ The black hole register is like the `/dev/null` of registers.
To paste your last search (`/` or `?`), you can use the last search pattern register (`"/`). To paste the last search term, use `"/p`.
## Viewing The Registers
## Viewing the Registers
To view all your registers, use the `:register` command. To view only registers "a, "1, and "-, use `:register a 1 -`.
There is a plugin called [vim-peekaboo](https://github.com/junegunn/vim-peekaboo) that lets you to peek into the contents of the registers when you hit `"` or `@` in normal mode and `Ctrl-R` in insert mode. I find this plugin very useful because most times, I can't remember the content in my registers. Give it a try!
## Executing A Register
## Executing a Register
The named registers are not just for storing texts. They can also execute macros with `@`. I will go over macros in the next chapter.
Keep in mind since macros are stored inside Vim registers, you can accidentally overwrite the stored text with macros. If you store the text "Hello Vim" in register a and you later record a macro in the same register (`qa{macro-sequence}q`), that macro will overwrite your "Hello Vim" text stored earlier.
## Clearing A Register
## Clearing a Register
Technically, there is no need to clear any register because the next text that you store under the same register name will overwrite it. However, you can quickly clear any named register by recording an empty macro. For example, if you run `qaq`, Vim will record an empty macro in the register a.
@ -238,7 +238,7 @@ Another alternative is to run the command `:call setreg('a', 'hello register a')
One more way to clear register is to set the content of "a register to an empty string with the expression `:let @a = ''`.
## Putting The Content Of A Register
## Putting the Content of a Register
You can use the `:put` command to paste the content of any one register. For example, if you run `:put a`, Vim will print the content of register a below the current line. This behaves much like `"ap`, with the difference that the normal mode command `p` prints the register content after the cursor and the command `:put` prints the register content at newline.
@ -246,7 +246,7 @@ Since `:put` is a command-line command, you can pass it an address. `:10put a` w
One cool trick to pass `:put` with the black hole register (`"_`). Since the black hole register does not store any text, `:put _` will insert a blank line instead. You can combine this with the global command to insert multiple blank lines. For example, to insert blank lines below all lines that contain the text "end", run `:g/end/put _`. You will learn about the global command later.
## Learning Registers The Smart Way
## Learning Registers the Smart Way
You made it to the end. Congratulations! If you are feeling overwhelmed by the sheer information, you are not alone. When I first started learning about Vim registers, there were way too much information to take at once.

@ -80,7 +80,7 @@ Running `@a` in normal mode is not the only way you can execute macros in Vim. Y
The `:normal` command accepts range as arguments. You can use this to run macro in select ranges. If you want to execute your macro between lines 2 and 3, you can run `:2,3 normal @a`.
## Executing A Macro Across Multiple Files
## Executing a Macro Across Multiple Files
Suppose you have multiple `.txt` files, each contains some texts. Your task is to uppercase the first word only on lines containing the word "donut". Assume you have `0W~j` in register a (the same macro as before). How can you quickly accomplish this?
@ -148,7 +148,7 @@ Now you can just run `@a` and watch Vim execute the macro recursively.
How did the macro know when to stop? When the macro was on the last line, it triedto run `j`, since there was no more line to go to, it stopped the macro execution.
## Appending A Macro
## Appending a Macro
If you need to add actions to an existing macro, instead of recreating the macro from scratch, you can append actions to an existing one. In the register chapter, you learned that you can append a named register by using its uppercased symbol. The same rule applies. To append actions to register a macro, use register A.
@ -165,7 +165,7 @@ The breakdown:
Now when you execute `@a`, it not only toggles the case of the next WORD, it also adds a dot at the end of the line.
## Amending A Macro
## Amending a Macro
What if you need to add new actions in the middle of a macro?
@ -213,7 +213,7 @@ You can easily duplicate macros from one register to another. For example, to du
I find creating a redundancy useful on my most frequently used macros. In my workflow, I usually record macros in the first seven alphabetical letters (a-g) and I often replace them without much thought. If I move the useful macros towards the end of the alphabets, I can preserve them without worrying that I might accidentally replace them.
## Series Vs Parallel Macro
## Series vs Parallel Macro
Vim can execute macros in series and parallel. Suppose you have this text:
@ -258,7 +258,7 @@ Recall from earlier section that macros can be executed using the command line
Although internally Vim does not actually run the macros in parallel, outwardly, it behaves like it. Vim executes `@a` *independently* on each line from the first to the last line (`1,$`). Since Vim executes these macros independently, each line does not know that one of the macro executions had failed on the "foo" line.
## Learn Macros The Smart Way
## Learn Macros the Smart Way
Many things you do in editing are repetitive. To get better at editing, get into the habit of detecting repetitive actions. Use macros (or dot command) so you don't have to perform the same action twice. Almost everything that you can do in Vim can be replicated with macros.

@ -2,7 +2,7 @@
We all make all sorts of typing mistakes. That's why undo is an essential feature in any modern software. Vim's undo system is not only capable of undoing and redoing simple mistakes, but also accessing different text states, giving you control to all the texts you have ever typed. In this chapter, you will learn how to undo, redo, navigate an undo branch, persist undo, and travel across time.
## Undo, Redo, And UNDO
## Undo, Redo, and UNDO
To perform a basic undo, you can use `u` or run `:undo`.
@ -64,7 +64,7 @@ I personally do not use `U` because it is hard to remember the original state (I
Vim sets a maximum number of how many times you can undo in `undolevels` option variable. You can check it with `:echo &undolevels`. I have mine set to be 1000. To change yours to 1000, run `:set undolevels=1000`. Feel free to set it to any number you like.
## Breaking The Blocks
## Breaking the Blocks
I mentioned earlier that `u` undoes a single "change" similar to the dot command's change: the texts inserted from when you enter the insert mode until you exit it count as a change.
@ -270,7 +270,7 @@ The same set of arguments work with `:earlier` counterpart: `:later`.
:later 10f go to the state 10 saves later
```
## Learn Undo The Smart Way
## Learn Undo the Smart Way
`u` and `Ctrl-R` are two indispensable Vim commands for correcting mistakes. Learn them first. 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.

@ -2,7 +2,7 @@
Highlighting and applying changes to a body of text is a common feature in many text editors and word processors. Vim can do this using visual mode. In this chapter, you will learn how to use the visual mode to manipulate texts efficiently.
## The Three Types Of Visual Modes
## The Three Types of Visual Modes
Vim has three different visual modes. They are:
@ -163,7 +163,7 @@ Chapter One
To learn more about operators in visual mode, check out `:h visual-operators`.
## Visual Mode And Command-line Commands
## Visual Mode and Command-line Commands
You can selectively apply command-line commands on a highlighted text block. If you have these statements and you want to substitute "const" with "let" only on the first two lines:
@ -183,7 +183,7 @@ const three = "three";
Notice I said you can do this with *any* visual mode. You do not have to highlight the entire line to run the command on that line. As long as you select at least a character on each line, the command is applied.
## Adding Text On Multiple Lines
## Adding Text on Multiple Lines
You can add text on multiple lines in Vim using the block-wise visual mode. If you need to add a semicolon at the end of each line:
@ -262,7 +262,7 @@ Put your cursor on the second "app-a". Use the same technique as above (`Ctrl-V
<div id="app-e"></div>
```
## Selecting The Last Visual Mode Area
## Selecting the Last Visual Mode Area
Earlier in this chapter I mentioned that `gv` can quickly highlight the last visual mode highlight. You can also go to the location of the start and the end of the last visual mode with these two special marks:
@ -313,7 +313,7 @@ Contrast this select mode with visual mode: if you highlight a line of text with
I personally never used select mode, but it's good to know that it exists.
## Learn Visual Mode The Smart Way
## Learn Visual Mode the Smart Way
The visual mode is Vim's representation of the text highlighting procedure.

@ -1,4 +1,4 @@
# Ch12. Search And Substitute
# Ch12. Search and Substitute
This chapter covers two separate but related concepts: search and substitute. Often when editing, you need to search multiple texts based on their least common denominator patterns. By learning how to use regular expressions in search and substitute instead of literal strings, you will be able to target any text quickly.
@ -32,7 +32,7 @@ Hello
There is one downside. What if you need to search for only a lowercase string? When you do `/hello`, Vim now does case insensitive search. You can use `\C` pattern anywhere in your search term to tell Vim that the subsequent search term will be case sensitive. If you do `/\Chello`, it will strictly match "hello", not "HELLO" or "Hello".
## First And Last Character In A Line
## First and Last Character in a Line
You can use `^` to match the first character in a line and `$` to match the last character in a line.
@ -60,7 +60,7 @@ What if you want to quickly recall *n* last search term? You can quickly travers
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`.
## Searching For Alternative Words
## Searching for Alternative Words
It is common to search for multiple words at once. If you need to search for *either* "hello vim" or "hola vim", but not "salve vim" or "bonjour vim", you can use the `|` pattern.
@ -77,7 +77,7 @@ To match both "hello" and "hola", you can do `/hello\|hola`. You have to escape
If you don't want to type `\|` every time, you can use the `magic` syntax (`\v`) at the start of the search: `/\vhello|hola`. I will not cover `magic` in this guide, but with `\v`, you don't have to escape special characters anymore. To learn more about `\v`, feel free to check out `:h \v`.
## Setting The Start And End Of A Match
## Setting the Start and End of a Match
Maybe you need to search for a text that is a part of a compound word. If you have these texts:
@ -119,7 +119,7 @@ You can combine these ranges together. If you need to search for digits 0-9 and
To do a negative search, you can add `^` inside the character range brackets. To search for a non-digit, run `/[^0-9]`. Vim will match any character as long as it is not a digit. Beware that the caret (`^`) inside the range brackets is different from the beginning-of-a-line caret (ex: `/^hello`). If a caret is outside of a pair of brackets and is the first character in the search term, it means "the first character in a line". If a caret is inside a pair of brackets and it is the first character inside the brackets, it means a negative search operator. `/^abc` matches the first "abc" in a line and `/[^abc]` matches any character except for an "a", "b", or "c".
## Searching For Repeating Characters
## Searching for Repeating Characters
If you need to search for double digits in this text:
@ -163,7 +163,7 @@ Vim has predefined ranges for common characters like digits and alphas. I will n
You can use them like you would use character ranges. To search for any single digit, instead of using `/[0-9]`, you can use `/\d` for a more concise syntax.
## Search Example: Capturing A Text Between A Pair Of Similar Characters
## Search Example: Capturing a Text Between a Pair of Similar Characters
If you want to search for a phrase surrounded by a pair of double quotes:
@ -188,7 +188,7 @@ When Vim sees the first `"`, it begins the pattern capture. The moment it sees t
- To capture a phrase surrounded by single quotes, you can use `/'[^']\+'`.
- To capture a phrase surrounded by zeroes, you can use `/0[^0]\+0`.
## Search Example: Capturing A Phone Number
## Search Example: Capturing a Phone Number
If you want to match a US phone number separated by a hyphen (`-`), like `123-456-7890`, you can use:
@ -230,7 +230,7 @@ Let's substitute "good" with "awesome" because Vim is awesome. Run `:s/good/awes
vim is awesome
```
## Repeating The Last Substitution
## Repeating the Last Substitution
You can repeat the last substitute command with either the normal command `&` or by running `:s`. If you have just run `:s/good/awesome/`, running either `&` or `:s` will repeat it.
@ -426,7 +426,7 @@ There are more flags that I do not list above. To read about all the flags, chec
By the way, the repeat-substitution commands (`&` and `:s`) do not retain the flags. Running `&` will only repeat `:s/pancake/donut/` without `g`. To quickly repeat the last substitute command with all the flags, run `:&&`.
## Changing The Delimiter
## Changing the Delimiter
If you need to replace a URL with a long path:
@ -542,7 +542,7 @@ Here is the breakdown:
- `\1` is the first group, which is either the text "hello" or "hola".
- `friend` is the literal word "friend".
## Substituting The Start And The End Of A Pattern
## Substituting the Start and the End of a Pattern
Recall that you can use `\zs` and `\ze` to define the start and the end of a match. This technique works in substitution too. If you have:
@ -566,7 +566,7 @@ strawberry sweetcake
blueberry hotdog
```
## Greedy And Non-Greedy
## Greedy and Non-greedy
You can substitute the nth match in a line with this trick:
@ -710,7 +710,7 @@ The breakdown:
- `q` stops the macro recording.
- `99@q` executes the macro ninety-nine times. Vim will stop the macro execution after it encounters the first error, so Vim won't actually execute the macro ninety-nine times.
## Learning Search And Substitution The Smart Way
## Learning Search and Substitution the Smart Way
The ability to do search well is a necessary skill in editing. Mastering the search lets you to utilize the flexibility of regular expressions to search for any pattern in a file. Take your time to learn these. To get better with regular expression you need to be actively using regular expressions. I once read a book about regular expression without actually doing it and I forgot almost everything I read afterwards. Active coding is the best way to master any skill.

@ -1,4 +1,4 @@
# Ch13. The Global Command
# Ch13. the Global Command
So far you have learned how to repeat the last change with the dot command (`.`), to replay actions with macros (`q`), and to store texts in the registers (`"`).
@ -132,7 +132,7 @@ To match the lines containing between three to six zeroes, run:
:g/0\{3,6\}/d
```
## Passing A Range
## Passing a Range
You can pass a range before the `g` command. Here are some ways you can do it:
- `:1,5g/console/d` matches the string "console" between lines 1 and 5 and deletes them.
@ -174,7 +174,7 @@ Let's break it down:
- `/./` is a pattern for "non-empty lines". It matches the lines with at least one character, so it matches the lines with "const" and "console" and it does not match empty lines.
- `normal A;` runs the `:normal` command-line command. `A;` is the normal mode command to insert a ";" at the end of the line.
## Executing A Macro
## Executing a Macro
You can also execute a macro with the global command. A macro can be executed with the `normal` command. If you have the expressions:
@ -249,7 +249,7 @@ You can also combine `g` with `v` to find positive and negative patterns. For ex
Instead of looking for the line containing the pattern "two", it will look for the lines *not* containing the pattern "two".
## Changing The Delimiter
## Changing the Delimiter
You can change the global command's delimiter like the substitute command. The rules are the same: you can use any single byte character except for alphabets, numbers, `"`, `|`, and `\`.
@ -293,7 +293,7 @@ It spells *"grep"*, the same `grep` from the command line. This is **not** a coi
Your computer probably still has the Ed editor. Run `ed` from the terminal (hint: to quit, type `q`).
## Reversing The Entire Buffer
## Reversing the Entire Buffer
To reverse the entire file, run:
@ -311,7 +311,7 @@ If you need to reverse only a few lines, pass it a range. To reverse the lines b
To learn more about the move command, check out `:h :move`.
## Aggregating All TODOs
## Aggregating All Todos
When coding, sometimes I would write TODOs in the file I'm editing:
@ -392,7 +392,7 @@ Recall from the register chapter that deleted texts are stored inside the number
By passing `_` after `d`, Vim won't use up your scratch registers.
## Reduce Multiple Empty Lines To One Empty Line
## Reduce Multiple Empty Lines to One Empty Line
If you have a text with multiple empty lines:
@ -541,7 +541,7 @@ This is great! But the command looks complicated. Let's break it down. This comm
- `/\[/+1,/\]/-1` then refers to any lines between "[" and "]".
- `sort` is a command-line command to sort.
## Learn The Global Command The Smart Way
## Learn the Global Command the Smart Way
The global command executes the command-line command against all matching lines. With it, you only need to run a command once and Vim will do the rest for you. To become proficient at the global command, two things are required: a good vocabulary of command-line commands and a knowledge of regular expressions. As you spend more time using Vim, you will naturally learn more command-line commands. A regular expression knowledge will require a more active approach. But once you become comfortable with regular expressions, you will be ahead of many.

@ -14,7 +14,7 @@ Vim has a bang (`!`) command that can do three things:
Let's go through each of them.
## Reading The STDOUT Of A Command Into Vim
## Reading the STDOUT of a Command Into Vim
The syntax to read the STDOUT of an external command into the current buffer is:
@ -58,7 +58,7 @@ The `r` command also accepts an address:
Now the STDOUT from running `cat file1.txt` will be inserted after line 10.
## Writing The Buffer Content Into An External Command
## Writing the Buffer Content Into an External Command
The command `:w`, in addition to saving a file, can be used to pass the text in the current buffer as the STDIN for an external command. The syntax is:
@ -91,7 +91,7 @@ Vim only uses the text from the second line into the `node` interpreter.
There is a subtle but significant difference between `:w !node` and `:w! node`. With `:w !node`, you are "writing" the text in the current buffer into the external command `node`. With `:w! node`, you are force-saving a file and naming the file "node".
## Executing An External Command
## Executing an External Command
You can execute an external command from inside Vim with the bang command. The syntax is:
@ -209,7 +209,7 @@ The breakdown:
The filter normal command only works on motions / text objects that are at least one line or longer. If you had tried running `!iwtr '[a-z]' '[A-Z]'` (execute `tr` on inner word), you will find that it applies the `tr` command on the entire line, not the word your cursor is on.
## Learn External Commands The Smart Way
## Learn External Commands the Smart Way
Vim is not an IDE. It is a lightweight modal editor that is highly extensible by design. Because of this extensibility, you have an easy access to any external command in your system. Armed with these external commands, Vim is one step closer from becoming an IDE. Someone said that the Unix system is the first IDE ever.

@ -4,7 +4,7 @@ In the last three chapters, you learned how to use the search commands (`/`, `?`
In this chapter, you will learn various tips and tricks for the command-line mode.
## Entering And Exiting The Command-line Mode
## Entering and Exiting the Command-line Mode
The command-line mode is a mode in itself, just like normal mode, insert mode, and visual mode. When you are in this mode, the cursor goes to the bottom of the screen where you can type in different commands.
@ -19,7 +19,7 @@ To leave the command-line mode, you can use `<Esc>`, `Ctrl-C, or Ctrl-[`.
*Other literatures might refer the "Command-line command" as "Ex command" and the "External command" as "filter command" or "bang operator".*
## Repeating The Previous Command
## Repeating the Previous Command
You can repeat the previous command-line command or external command with `@:`.
@ -44,7 +44,7 @@ Finally, if you want to edit the command like you would a normal textfile use `C
This also allows you to search through the previous commands, edit them and rerun them by pressing `<Enter>` in "command-line editing normal mode".
## Register And Autocomplete
## Register and Autocomplete
While in 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, 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.
@ -54,14 +54,14 @@ You can also autocomplete existing commands. To autocomplete the `echo` command,
Some command-line commands accept file names as arguments. One example is `edit`. You can autocomplete here too. After typing the command, `:e ` (don't forget the space), press `<Tab>`. Vim will list all the relevant file names that you can choose from so you don't have to type it from scratch.
## History Window And Command-line Window
## History Window and Command-line Window
You can view the histoy of command-line commands and search terms (this requires the `+cmdline_hist` feature).
To open the command-line history, run `:his :`. You should see something like the following:
```
## cmd History
## Cmd history
2 e file1.txt
3 g/foo/d
4 s/foo/bar/g
@ -89,7 +89,7 @@ To quit this window, press `Ctrl-C`, `Ctrl-W C`, or type `:quit`.
Vim has hundreds of built-in commands. To see all the commands Vim have, check out `:h ex-cmd-index` or `:h :index`.
## Learn Command-line Mode The Smart Way
## Learn Command-line Mode the Smart Way
Compared to the other three modes, the command-line mode is like the Swiss Army knife of text editing. You can edit text, modify files, and execute commands, just to name a few. This chapter is a collection of odds and ends of the command-line mode. It also brings Vim modes into closure. Now that you know how to use the normal, insert, visual, and command-line mode you can edit text with Vim faster than ever.

@ -148,7 +148,7 @@ To add a new tag file location, use the following:
set tags+=path/to/my/tags/file
```
## Generating Tags For A Large Project
## Generating Tags for a Large Project
If you tried to run ctags in a large project, it may take a long time because Vim also looks inside every nested directories. If you are a Javascript developer, you know that `node_modules` can be very large. Imagine if you have a five sub-projects and each contains its own `node_modules` directory. If you run `ctags -R .`, ctags will try to scan through all 5 `node_modules`. You probably don't need to run ctags on `node_modules`.
@ -325,7 +325,7 @@ One of the biggest drawbacks of Vim tags is that each time you make a significan
Luckily there are several methods you can employ to generate tags automatically.
## Generate A Tag On Save
## Generate a Tag on Save
Vim has an autocommand (`autocmd`) method to execute any command on an event trigger. You can use this to generate tags on each save. Run:
@ -353,11 +353,11 @@ There are several plugins to generate ctags automatically:
I use vim-gutentags. It is simple to use and will work right out of the box.
## Ctags And Git Hooks
## Ctags and Git Hooks
Tim Pope, author of many great Vim plugins, wrote a blog suggesting to use git hooks. [Check it out](https://tbaggery.com/2011/08/08/effortless-ctags-with-git.html).
## Learn Tags The Smart Way
## Learn Tags the Smart Way
A tag is useful once configured properly. Suppose you are faced with a new codebase and you want to understand what `functionFood` does, you can easily read it by jumping to its definition. Inside it, you learn that it also calls `functionBreakfast`. You follow it and you learn that it calls `functionPancake`. Your function call graph looks something like this:

@ -361,7 +361,7 @@ Now after you fold inside a `.txt` file and exit Vim, the next time you open tha
By default, Vim saves the fold information when running `mkview` inside `~/.vim/view` for the Unix system. For more information, check out `:h 'viewdir'`.
## Learn Fold The Smart Way
## Learn Fold the Smart Way
When I first started Vim, I neglected ot learn fold because I didn't think it was useful. However, the longer I code, the more useful I find folding is. Strategically placed folds can give you a better overview of the text structure, like a book's table of content.

@ -58,7 +58,7 @@ If you need to transfer the text from the other buffer (orange juice, `file2.txt
If you have multiple buffers, you can run `:diffput fileN.txt` and `:diffget fileN.txt` to target the the fileN buffer.
## Vim As A Merge Tool
## Vim As a Merge Tool
> "I love resolving merge conflicts!" - Nobody
@ -284,7 +284,7 @@ When you run the `:Gdiffsplit` command, vim-fugitive runs a `vimdiff` of the cur
Because you are in a `vimdiff` mode, you can *get* or *put* the diff with `:diffput` and `:diffget`.
## Gwrite And Gread
## Gwrite and Gread
When you run the `:Gwrite` command in a file after you make changes, vim-fugitive stages the changes. It is like running `git add <current-file>`.
@ -300,13 +300,13 @@ While in this `"git log"` mode, you can do two things:
You can pass to `:Gclog` arguments just like the `git log` command. If your project has a long commit history and you only need to view the last three commits, you can run `:Gclog -3`. If you need to filter it based on the committer's date, you can run something like `:Gclog --after="January 1" --before="March 14"`.
## More Vim-Fugitive
## More Vim-fugitive
These are only a few examples of what vim-fugitive can do. To learn more about vim-fugitive, check out `:h fugitive.txt`. Most of the popular git commands are probably optimized with vim-fugitive. You just have to look for them in the documentation.
If you are inside one of vim-fugitive's "special mode" (for example, inside `:Git` or `:Git blame` mode) and you want to learn what shortcuts are available, press `g?`. Vim-fugitive will display the appropriate `:help` window for the mode you are in. Neat!
## Learn Vim And Git The Smart Way
## Learn Vim and Git the Smart Way
You may find vim-fugitive to be a good compliment to your workflow (or not). Regardless, I would strongly encourage you to check out all the plugins listed above. There are probably others I didn't list. Go try them out.

@ -124,7 +124,7 @@ When you run `:make` from inside `./hello.cpp`, it is compiled into `./hello`. T
For more, check out `:h :compiler` and `:h write-compiler-plugin`.
## Auto-compile On Save
## Auto-compile on Save
You can make life even easier by automating compilation. Recall that you can use Vim's `autocmd` to trigger automatic actions based on certain events. To automatically compile `.cpp` files on each save add this on your vimrc:
@ -160,7 +160,7 @@ Vim runs the `$VIMRUNTIME/compiler/ruby.vim` script and changes the `makeprg` to
You don't have to use the `:compiler` and `makeprg` to compile a program. You can run a test script, lint a file, send a signal, or anything you want.
## Creating A Custom Compiler
## Creating a Custom Compiler
Let's create a simple Typescript compiler. Install Typescript (`npm install -g typescript`) to your machine. You should now have the `tsc` command. If you haven't played with typescript before, `tsc` compiles a Typescript file into a Javascript file. Suppose that you have a file, `hello.ts`:
@ -287,7 +287,7 @@ autocmd BufEnter *_spec.rb let b:dispatch = 'bundle exec rspec %'
Now each time you enter a file (`BufEnter`) that ends with `_spec.rb`, running `:Dispatch` automatically executes `bundle exec rspec {your-current-ruby-spec-file}`.
## Learn Compile The Smart Way
## Learn Compile the Smart Way
In this chapter, you learned that you can use the `make` and `compiler` commands to run *any* process from inside Vim asynchronously to complement your programming workflow. Vim's ability to extend itself with other programs makes it powerful.

@ -1,4 +1,4 @@
# Ch20. Views, Sessions, And Viminfo
# Ch20. Views, Sessions, and Viminfo
After you worked on a project for a while, you may find the project to gradually take shape with its own settings, folds, buffers, layouts, etc. It's like decorating your apartment after living in it for a while. The problem is, when you close Vim, you lose those changes. Wouldn't it be nice if you can keep those changes so the next time you open Vim, it looks just like you had never left?
@ -65,7 +65,7 @@ To learn what other options are available for `viewoptions`, check out `:h viewo
viewoptions=folds,cursor,curdir,localoptions
```
### Saving The View
### Saving the View
With the `foo.txt` window properly folded and having `nonumber norelativenumber` options, let's save the View. Run:
@ -89,7 +89,7 @@ In Unix based OS the default should say `~/.vim/view` (if you have a different O
set viewdir=$HOME/else/where
```
### Loading The View File
### Loading the View File
Close the `foo.txt` if you haven't, then open `foo.txt` again. **You should see the original text without the changes.** That's expected.
@ -166,7 +166,7 @@ Now you don't have to worry about creating and loading View anymore when you are
If a View saves the settings of a window, a Session saves the information of all windows (including the layout).
### Creating A New Session
### Creating a New Session
Suppose you are working with these 3 files in a `foobarbaz` project:
@ -231,7 +231,7 @@ If you want to save the Session file somewhere else, you can pass an argument to
If you want to overwrite the existing Session file, call the command with a `!` (`:mksession! ~/some/where/else.vim`).
### Loading A Session
### Loading a Session
To load a Session, run:
@ -314,7 +314,7 @@ The default Viminfo location for Unix is `$HOME/.viminfo` (`~/.viminfo`). If you
*Make sure that you have `nocompatible` option set (`set nocompatible`), otherwise your Viminfo will not work.*
### Writing And Reading Viminfo
### Writing and Reading Viminfo
Although you will use only one Viminfo file, you can create multiple Viminfo files. To write a Viminfo file, use the `:wviminfo` command (`:wv` for short).
@ -385,7 +385,7 @@ This looks cryptic. Let's break it down:
There are other options that you can pass. To learn more, check out `:h 'viminfo'`.
## Using Views, Sessions, And Viminfo The Smart Way
## Using Views, Sessions, and Viminfo the Smart Way
Vim has View, Session, and Viminfo to take different level of your Vim environment snapshots. For micro projects, use Views. For larger projects, use Sessions. You should take your time to check out all the options that View, Session, and Viminfo offers.

@ -32,7 +32,7 @@ The sixth, `$VIMRUNTIME/defaults.vim` is the default vimrc that comes with your
For the remaining of this chapter, I am assuming that the vimrc uses the `~/.vimrc` path.
## What To Put In My Vimrc?
## What to Put in My Vimrc?
A question I asked when I started was, "What should I put in my vimrc?"
@ -369,7 +369,7 @@ Your vimrc should look like this:
+-- 5 lines: mappings --------
```
## Running Vim With Or Without Vimrc And Plugins
## Running Vim With or Without Vimrc and Plugins
If you need to run Vim without both vimrc and plugins, run:
@ -395,6 +395,6 @@ If you need to run Vim with a *different* vimrc, say `~/.vimrc-backup`, run:
vim -u ~/.vimrc-backup
```
## Configure Vimrc The Smart Way
## Configure Vimrc the Smart Way
Vimrc is an important component of Vim customization. A good way to start building your vimrc is by reading other people's vimrcs and gradually build it over time. The best vimrc is not the one that developer X uses, but the one that is tailored exactly to fit your thinking framework and editing style.

@ -8,7 +8,7 @@ To see if your Vim build has the ability to use packages, run `:version` and loo
Check if you have a `~/.vim/` directory in the root path. If you don't, create one. Inside it, create a directory called `pack` (`~/.vim/pack/)`. Vim automatically knows to search inside this directory for packages.
## Two Types Of Loading
## Two Types of Loading
Vim package has two loading mechanisms: automatic and manual loading.
@ -86,7 +86,7 @@ else
endif
```
## Organizing packages
## Organizing Packages
Recall that the requirement to use Vim's package system is to have either:
@ -121,7 +121,7 @@ You can still use `start/` and `opt/` inside each of the directories.
~/.vim/pack/games/opt/
```
## Adding Packages The Smart Way
## Adding Packages the Smart Way
You may wonder if Vim package will make popular plugin managers like vim-pathogen, vundle.vim, dein.vim, and vim-plug obsolete.

@ -279,6 +279,6 @@ If inside `~/box/of/donuts/`, you have a plugin directory (`~/box/of/donuts/plug
Try this yourself: create an arbitrary path and add it to your runtimepath. Add some of the runtime paths you learned from this chapter. Make sure they work as expected.
## Learn Runtime The Smart Way
## Learn Runtime the Smart Way
Take your time reading it and play around with these runtime paths. To see how runtime paths are being used in the wild, go to the repository of one of your favorite Vim plugins and study its directory structure. You should be able to understand most of them now. Try to follow along and discern the big picture. Now that you understand Vim directory structure, you're ready to learn Vimscript.

@ -285,7 +285,7 @@ On the other hand, this is falsy:
Vim coerces "donuts12" into 0, because the first character is not a number.
### Double vs Single quotes
### Double vs Single Quotes
Double quotes behave differently than single quotes. Single quotes display characters literally while double quotes accept special characters.
@ -784,7 +784,7 @@ Similar to `v:none`.
" returns {"test": null}
```
## Learn Data Types The Smart Way
## Learn Data Types the Smart Way
In this chapter, you learned about Vimscript's basic data types: number, float, string, list, dictionary, and special. Learning these is the first step to start Vimscript programming.

@ -1,4 +1,4 @@
# Ch25. Vimscript Conditionals And Loops
# Ch25. Vimscript Conditionals and Loops
After learning what the basic data types are, the next step is to learn how to combine them together to start writing a basic program. A basic program consists of conditionals and loops.
@ -199,7 +199,7 @@ let &background = strftime("%H") < 18 ? "light" : "dark"
`&background` is the `'background'` option in Vim. `strftime("%H")` returns the current time in hours. If it is not yet 6 PM, use a light background. Otherwise, use a dark background.
## Or
## or
The logical "or" (`||`) works like many programming languages.
@ -243,7 +243,7 @@ echo two_dozen || one_dozen
Note that `two_dozen` is never defined. The expression `one_dozen || two_dozen` doesn't throw any error because `one_dozen` is evaluated first found to be truthy, so Vim doesn't evaluate `two_dozen`.
## And
## and
The logical "and" (`&&`) is the complement of the logical or.
@ -281,7 +281,7 @@ echo exists("one_dozen") && one_dozen == 12
" returns 1
```
## For
## for
The `for` loop is commonly used with the list data type.
@ -403,7 +403,7 @@ echo total_word
This time it returns `one two three four five`. It skips the line with the word "donut", but the loop continues.
### Try, Finally, And Catch
### try, finally, and catch
Vim has a `try`, `finally`, and `catch` to handle errors. To simulate an error, you can use the `throw` command.
@ -507,7 +507,7 @@ endtry
Now if you `source` vimrc without `gruvbox` directory, Vim will use the `colorscheme default`.
## Learn conditionals the smart way
## Learn Conditionals the Smart Way
In the previous chapter, you learned about Vim basic data types. In this chapter, you learned how to combine them to write basic programs using conditionals and loops. These are the building blocks of programming.

@ -2,7 +2,7 @@
Before diving into Vimscript functions, let's learn about the different sources and scopes of Vim variables.
## Mutable And Immutable Variables
## Mutable and Immutable Variables
You can assign a value to a variable in Vim with `let`:
@ -104,7 +104,7 @@ a: Function formal parameter variable
v: Built-in Vim variable
```
### Global variable
### Global Variable
When you are declaring a "regular" variable:
@ -196,7 +196,7 @@ const t:donut = "blackberry donut"
On each tab, you can call `echo t:donut` to get unique values.
### Script variable
### Script Variable
A variable preceded with `s:` is a script variable. These variables can only be accessed from inside that script.
@ -241,7 +241,7 @@ endfunction
Now when you source `dozen.vim` while in the middle of decrementing, Vim reads `!exists("s:dozen")`, finds that it is true, and doesn't reset the value back to 12.
### Function Local And Function Formal Parameter variable
### Function Local and Function Formal Parameter Variable
Both the function local variable (`l:`) and the function formal variable (`a:`) will be covered in the next chapter.
@ -255,7 +255,7 @@ A variable prepended with `v:` is a special built-in Vim variable. You cannot de
There are other variables. For a list of Vim built-in variables, check out `:h vim-variable` or `:h v:`.
## Using Vim Variable Scopes The Smart Way
## Using Vim Variable Scopes the Smart Way
Being able to quickly access environment, option, and register variables give you a broad flexibility to customize your editor and terminal environment. You also learned that Vim has 9 different variable scopes, each existing under a certain constraints. You can take advantage of these unique variable types to decouple your program.

@ -61,7 +61,7 @@ function fzf#vim#maps(mode, ...)
Last set from ~/.vim/plugged/fzf.vim/autoload/fzf/vim.vim line 1263
```
## Removing A Function
## Removing a Function
To remove an existing function, use `:delfunction {Function_name}`. To delete `Tasty`, run `:delfunction Tasty`.
@ -162,7 +162,7 @@ echo Calories()
" returns "I do not count my calories"
```
## Calling A Function
## Calling a Function
Vim has a `:call` command to call a function.
@ -519,7 +519,7 @@ endfunction
Now if you run `echo Lunch()()`, Vim will return "shrimp".
## Learn Vimscript Functions The Smart Way
## Learn Vimscript Functions the Smart Way
In this chapter, you learned the anatomy of Vim function. You learned how to use different special keywords `range`, `dict`, and `closure` to modify function behavior. You also learned how to use lambda and to chain multiple functions together. Functions are important tools for creating complex abstractions.

Loading…
Cancel
Save