summaryrefslogtreecommitdiff
path: root/Homework/engl3085/Technical-Comm/vim-docs-for-3085/docs/quickstart.md
blob: 9dadcd4c5d0d8af87b420e119aa09dabef50c017 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# Quick Start

Welcome to the QuickStart guide for Vim. This guide will help you get the bare bones knowledge of using Vim and will get you to the point where you can embark on the long but fun, journey to using Vim as your main text editor!

## Installation

<h6>Eric</h6>

### MacOS

Using [homebrew](https://brew.sh/), you can install the latest version of Vim with `brew install vim`, though an older version comes pre-installed on MacOS if you don't wish to use homebrew.

### Windows

If you are on a Windows machine, navigate to [vim.org](https://www.vim.org), [downloads](https://www.vim.org/download.php), and select your version. Afterwards, it will be accessable from the `cmd` Terminal, or if chosen in the installation, can be launched from the Desktop Icon.

### Linux

#### Fedora

```bash
sudo dnf install vim
```

#### Arch Linux

```bash
sudo pacman -S vim
```

#### Debian/Ubuntu

```bash
sudo apt install vim
```

### Verify Installation

Verify that Vim is installed by opening a terminal and running `vim`. If you see something like this, you are good to go! Now you can exit Vim by typing `:q`.

![Vim Screenshot](./img/vim_window.png)

## A Quick Adventure - Making A Todo File

### Creating a New Todo List
<h6>Tyler</h6>

Creating a new file with vim is really simple just type:

```bash
vim todo.txt
```

Whenever you pass a file that doesn't exist vim creates it for you and opens it up for editing.

### Navigating the cursor
<h6>Tyler</h6>

Vim does not support the usage of a mouse so movement of the cursor is handled entirely with the keyboard.
The basic movements of the cursor are as follows:

| Command | Description                               |
| ------- | ----------------------------------------- |
| `h`     | `(←)` Move the cursor left one character  |
| `j`     | `(↓)` Move the cursor down one line       |
| `k`     | `(↑)` Move the cursor up one line         |
| `l`     | `(→)` Move the cursor right one character |

### Adding a Todo

<h6>Eric</h6>

Now that you have opened a file in Vim, it's time to insert text. For now, press the `i` key to enter into Insert Mode. More details on the different modes will be covered a little further on. For now, lets practice adding some text to Vim.

Inserting text works just like any other text editor, so try and insert some text, following this format:

![TODO List](./img/vimtodo.png)

This will probably end up with something to the likes of:

```
My Todos
- [ ] Eat Vegetables
- [ ] Take a Nap
- [ ] Learn Vim
```

#### A Quick Aside: Normal vs Insert Mode
<h6>Logan</h6>

Insert mode, used to actually type text into the document, can be accessed by pressing `i`. To exit this mode, press the `ESC` key.

For now, think of Normal Mode as the mode to move the text cursor around, and Insert Mode as how to actually insert text into the document (this will be further explained in [Understanding Vim](understanding.md)).

### Saving

###### Authored by Alaina D

Once you have added text to a file (see "Adding a Todo" if you are not sure how to insert text), you will want to save the file for later editing.

In Vim, there are three common ways to save a file:

- using `:w`
- using `:x`
- using `:wq`

Before you attempt any of the above commands, hit `ESC` (the "escape" key) to make sure Vim is in Normal mode. You should see a blank line in bottom of your terminal (hint: if the bottom of your terminal says "-- INSERT --", you are **not** in Normal mode).

The following is a screenshot of Vim in normal mode:

![Vim Screenshot](./img/save_in_normal_mode.png)

Once Vim is in normal mode, you can enter any of the previously mentioned "save" commands (`:w`, `:x`, or `:wq`), followed by the `ENTER` key. 

**Note**: These commands are case-sensitive (the letters in each command must be lower-case). 
<br><br>
###### Using `:w`

The command `:w` will save (write) the file that you are currently editing. If you use `:w` to write (save) your file, your file will remain open in Vim. This command is great for saving a file that you would like to continue editing.

###### Using `:x`

The command `:x` will save (write) the file that you are currently editing. If you use `:x` to write (save) your file, your file will only be saved _if_ changes have been made to the file. This command will not change the modification timestamp of the file if you have not made changes to the file after opening it. If you use `:x` to save your file, Vim will exit when you hit enter. 

###### Using `:wq`

The command `:wq` will save (write) the file that you are currently editing, _and_ will exit Vim after the file is saved. If you want to save and quit Vim all in the same command, `:wq` should be your weapon of choice.
<br><br>

**NOTE:** `:wq` is not **_the only_** command to use to exit Vim--it is merely a convenient way to save a file and exit Vim at the same time.

### Exiting

###### Trevor

The Command for exiting vim is `:q`. If the file has been edited since it was opened, `:q` will not work, instead giving a warning about unwritten changes. To bypass this, you can add an `!` to the command, making it `:q!`, which will quit without saving.

### Reopening The File
<h6>Tyler</h6>

After saving (using `:w`, `:x`, `:wq`, etc.), re-open the todo file to prove that the changes made have been saved: 

```bash
vim todo.txt
```

### Mark A Todo As Done
<h6>Tyler</h6>

Navigate the cursor between the brackets of the task you want to mark as done and enter Insert mode `i`.

Mark the task done by entering a capital X.

Then, enter Normal mode by pressing the `Escape` key, press `j` to go down a line to the next todo, and mark it as done the same way.

![Vim Screenshot](./img/marked_todos.png)

### Delete A Todo
<h6>Tyler</h6>

One way to remove a todo from the list is to delete the entire line. To do this, get into Normal mode and navigate the cursor to the line you want to delete. Then, press the `d` key twice: `dd`, to remove the line.

![Vim Screenshot](./img/deleted_todos.png)

## Further Understanding Vim

Amazing! You've made it this far. Let's take a look at how you can do more by [understanding Vim](understanding.md).