mirror of
https://github.com/iggredible/Learn-Vim
synced 2024-11-12 22:17:07 +00:00
Add file type in code samples
This commit is contained in:
parent
c9659f8a5e
commit
7e3cfc854e
3 changed files with 19 additions and 19 deletions
|
@ -16,7 +16,7 @@ Alternatively, you can also check out Vim's [official github repository](https:/
|
|||
|
||||
Now that you have Vim installed, run this from the terminal:
|
||||
|
||||
```
|
||||
```bash
|
||||
vim
|
||||
```
|
||||
|
||||
|
@ -76,13 +76,13 @@ Or `:h` for short. You can also pass the `:h` command the subject you want to le
|
|||
|
||||
From the terminal, to open `hello1.txt` file, run:
|
||||
|
||||
```
|
||||
```bash
|
||||
vim hello1.txt
|
||||
```
|
||||
|
||||
You can also open multiple files at once:
|
||||
|
||||
```
|
||||
```bash
|
||||
vim hello1.txt hello2.txt hello3.txt
|
||||
```
|
||||
|
||||
|
@ -94,7 +94,7 @@ You can pass the `vim` terminal command with different flags and options.
|
|||
|
||||
To check the current Vim version, run:
|
||||
|
||||
```
|
||||
```bash
|
||||
vim --version
|
||||
```
|
||||
|
||||
|
@ -118,13 +118,13 @@ If you want to open the file `hello.txt` and immediately execute a command, you
|
|||
|
||||
In Vim, you can substitute text with the `:s` command (short for `:substitute`). If you want to open `hello.txt` and substitute all "foo" with "bar", run:
|
||||
|
||||
```
|
||||
```bash
|
||||
vim +%s/foo/bar/g hello.txt
|
||||
```
|
||||
|
||||
These commands can also be stacked:
|
||||
|
||||
```
|
||||
```bash
|
||||
vim +%s/foo/bar/g +%s/bar/baz/g +%s/baz/donut/g hello.txt
|
||||
```
|
||||
|
||||
|
@ -132,7 +132,7 @@ Vim will first replace all instances of "foo" with "bar", then replace "bar" wit
|
|||
|
||||
You can also pass the `c` flag followed by the command instead of the `+` syntax:
|
||||
|
||||
```
|
||||
```bash
|
||||
vim -c %s/foo/bar/g hello.txt
|
||||
vim -c %s/foo/bar/g -c %s/bar/baz/g -c %s/baz/donut/g hello.txt
|
||||
```
|
||||
|
@ -145,25 +145,25 @@ You can launch Vim on split windows, horizontal and vertical, with `o` and `O`,
|
|||
|
||||
To open Vim with two horizontal windows, run:
|
||||
|
||||
```
|
||||
```bash
|
||||
vim -o
|
||||
```
|
||||
|
||||
To open Vim with 5 horizontal windows, run:
|
||||
|
||||
```
|
||||
```bash
|
||||
vim -o5
|
||||
```
|
||||
|
||||
To open Vim with 5 horizontal windows and fill up the first two with `hello1.txt` and `hello2.txt`, run:
|
||||
|
||||
```
|
||||
```bash
|
||||
vim -o5 hello1.txt hello2.txt
|
||||
```
|
||||
|
||||
Retrospectively, to open Vim with two vertical windows, 5 vertical windows, and 5 vertical windows with 2 files:
|
||||
|
||||
```
|
||||
```bash
|
||||
vim -O
|
||||
vim -O5
|
||||
vim -O5 hello1.txt hello2.txt
|
||||
|
|
|
@ -14,7 +14,7 @@ A buffer is an in-memory space where you can write and edit some text. When you
|
|||
|
||||
If your buffer isn't bound to a file yet but you want to save its content, you can save it with `:w </path/to/file>`.
|
||||
|
||||
```
|
||||
```bash
|
||||
vim file1.js
|
||||
```
|
||||
|
||||
|
@ -24,7 +24,7 @@ What you are seeing is `file1.js` *buffer*. Whenever we open a new file, Vim cre
|
|||
|
||||
Exit Vim. This time, open two new files:
|
||||
|
||||
```
|
||||
```bash
|
||||
vim file1.js file2.js
|
||||
```
|
||||
![one buffer displayed.png](./img/screen-one-buffer.png)
|
||||
|
@ -68,7 +68,7 @@ A window is a viewport on a buffer. You can have multiple windows. Most text edi
|
|||
![VSCode showing 3 windows](./img/screen-vscode-3-windows.png)
|
||||
|
||||
Let's open `file1.js` from the terminal again:
|
||||
```
|
||||
```bash
|
||||
vim file1.js
|
||||
```
|
||||
![one buffer displayed.png](./img/screen-one-buffer.png)
|
||||
|
@ -136,7 +136,7 @@ For more, check out `:h window`. Take your time to understand them.
|
|||
A tab is a collection of windows. Think of it like a layout for windows. In most modern text editors (and modern internet browsers), a tab means an open file/ page and when you close it, that file/page goes away. In Vim, a tab does not represent an open file. When you close a tab in Vim, you are not closing a file. Remember, Vim stores files in-memory via buffers. Closing a tab (or a window) does not make that file disappear from the buffers.
|
||||
|
||||
Let's see Vim tabs in action. Open `file1.js`:
|
||||
```
|
||||
```bash
|
||||
vim file1.js
|
||||
```
|
||||
|
||||
|
@ -168,7 +168,7 @@ One advantage of having multiple tabs is you can have different window arrangeme
|
|||
![second tab with multiple windows](./img/tabs-file2js.png)
|
||||
|
||||
To start Vim with multiple tabs, you can do this from the terminal:
|
||||
```
|
||||
```bash
|
||||
vim -p file1.js file2.js file3.js
|
||||
```
|
||||
## Moving In 3D
|
||||
|
|
|
@ -61,7 +61,7 @@ c Delete text, save to register, and start insert mode
|
|||
|
||||
Now that you know basic nouns and verbs, let's apply our grammar rule! Suppose you have this expression:
|
||||
|
||||
```
|
||||
```javascript
|
||||
const learn = "vim";
|
||||
```
|
||||
- To yank everything from your current location to the end of the line: `y$`.
|
||||
|
@ -99,7 +99,7 @@ Inner text object selects the object inside *without* the white space or the sur
|
|||
|
||||
Let's look at a different example. Suppose you have this Javascript function and your cursor is on "Hello":
|
||||
|
||||
```
|
||||
```javascript
|
||||
const hello = function() {
|
||||
console.log("Hello Vim");
|
||||
return true;
|
||||
|
@ -113,7 +113,7 @@ const hello = function() {
|
|||
Text objects are powerful because you can target different objects from one location. You can delete the objects inside the pair of parentheses, the function block, or the whole word. Moreover, when you see `di(`, `di{`, and `diw`, you get a pretty good idea what text objects they represent (a pair of parentheses, a pair of braces, and a word).
|
||||
|
||||
Let's look at one last example. Suppose you have these HTML tags:
|
||||
```
|
||||
```html
|
||||
<div>
|
||||
<h1>Header1</h1>
|
||||
<p>Paragraph1</p>
|
||||
|
|
Loading…
Reference in a new issue