Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
linux:vim-editor [2017/08/29 09:32] – [Moving Around in Command Mode] michael | linux:vim-editor [2019/05/21 11:20] (current) – michael | ||
---|---|---|---|
Line 13: | Line 13: | ||
This guide will be very introductory. There are entire books written about Vi/Vim, but I want to make sure you know at least the basics so you can get up and operating with it. | This guide will be very introductory. There are entire books written about Vi/Vim, but I want to make sure you know at least the basics so you can get up and operating with it. | ||
- | ---- | ||
===== Configuring Vim ===== | ===== Configuring Vim ===== | ||
Our first step is to configure Vim. Since we'll generally be working with code or configuration, | Our first step is to configure Vim. Since we'll generally be working with code or configuration, | ||
+ | <WRAP center box 100%> | ||
==== Step 1 - Open a Terminal ==== | ==== Step 1 - Open a Terminal ==== | ||
Open up a terminal session such as putty and ensure you are at your home directory with the command: | Open up a terminal session such as putty and ensure you are at your home directory with the command: | ||
Line 26: | Line 26: | ||
The terminal should show that you are in / | The terminal should show that you are in / | ||
This will change the directory to your home directory. | This will change the directory to your home directory. | ||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | <WRAP center box 100%> | ||
==== Step 2 - Edit the vimrc File ==== | ==== Step 2 - Edit the vimrc File ==== | ||
**Your .vimrc file is where your Vim configurations are stored.** As you use Vim, you will start to have more custom configuration in your .vimrc file. I keep a copy of my complex .vimrc on my GitHub, but in general, when you are using Vim on a remote host, unless you are an authorized user, you won't have a custom .vimrc so it's important to be familiar with basic behavior. | **Your .vimrc file is where your Vim configurations are stored.** As you use Vim, you will start to have more custom configuration in your .vimrc file. I keep a copy of my complex .vimrc on my GitHub, but in general, when you are using Vim on a remote host, unless you are an authorized user, you won't have a custom .vimrc so it's important to be familiar with basic behavior. | ||
Line 47: | Line 51: | ||
On the bottom left of the screen, we can see we are in insert mode. Now we can type in our configuration. You will want the following lines in the file: | On the bottom left of the screen, we can see we are in insert mode. Now we can type in our configuration. You will want the following lines in the file: | ||
- | * <wrap em>syntax on</ | + | * '' |
- | * <wrap em>set wrapmargin=8</ | + | * '' |
- | * <wrap em>set number</ | + | * '' |
{{linux: | {{linux: | ||
**Syntax on** enables built-in syntax highlighting for many programming languages and configuration files. **Set wrapmargin=8** gives us an 8-character buffer before the end of the terminal and makes the screen more legible. **Set number** simply turns on line numbering. | **Syntax on** enables built-in syntax highlighting for many programming languages and configuration files. **Set wrapmargin=8** gives us an 8-character buffer before the end of the terminal and makes the screen more legible. **Set number** simply turns on line numbering. | ||
+ | </ | ||
+ | |||
+ | |||
+ | ---- | ||
+ | <WRAP center box 100%> | ||
==== Step 3 - Write Your Changes & Quit ==== | ==== Step 3 - Write Your Changes & Quit ==== | ||
We will now need to press the **'' | We will now need to press the **'' | ||
Line 70: | Line 79: | ||
That looks a whole lot better. | That looks a whole lot better. | ||
- | ---- | + | </ |
===== Moving Around in Command Mode ===== | ===== Moving Around in Command Mode ===== | ||
Line 78: | Line 88: | ||
__Some additional movement keys:__ | __Some additional movement keys:__ | ||
- | * **e** will move you forward to the end of a word | + | * '' |
- | * **w** will move you forward to the beginning of a word | + | * '' |
- | * **b** will move you backward to the beginning of a word | + | * '' |
- | * **$** will move you to the end of a line | + | * '' |
- | * **0** (zero) will move you the beginning of a line | + | * '' |
- | * **G** will move you to the end of a file | + | * '' |
- | * **gg** will move you to the start of a file | + | * '' |
</ | </ | ||
Line 90: | Line 100: | ||
There are, of course, many more ways to move around a file, but these should cover most use-cases. | There are, of course, many more ways to move around a file, but these should cover most use-cases. | ||
- | ---- | ||
===== Searching a File ===== | ===== Searching a File ===== | ||
Line 100: | Line 109: | ||
In order to search and replace, we use the **: | In order to search and replace, we use the **: | ||
- | * <wrap em>: | + | * '' |
- | * <wrap em>: | + | * '' |
Vim also supports regular expressions in the same way that [[https:// | Vim also supports regular expressions in the same way that [[https:// | ||
- | ---- | ||
===== Saving, Quitting & Shell Escaping ===== | ===== Saving, Quitting & Shell Escaping ===== | ||
Line 111: | Line 119: | ||
Exiting Vim is always a problem for people just starting out. In order to exit, use these commands: | Exiting Vim is always a problem for people just starting out. In order to exit, use these commands: | ||
- | * **:w** will write the file | + | * '' |
- | * **:wq** will write the file and quit | + | * '' |
- | * <wrap em>:q!</ | + | * '' |
- | * **:w** someFileName will write the changes to a file called someFileName | + | * '' |
In some cases, we might want to escape to a shell to browse directory trees or look at other files. In order to execute a system command in Vim, we use the command: | In some cases, we might want to escape to a shell to browse directory trees or look at other files. In order to execute a system command in Vim, we use the command: | ||
- | * **:!command** | + | * '' |
- | This will execute whatever command we put after the bang. This can be a shell '' | + | This will execute whatever command we put after the bang. This can be a shell '' |