That’s what this interactive VIM tutorial aims to do, help you learn the basics of VIM so you can start using the text editor with some confidence. The interactive guide is broken into 13 main lessons that cover the essentials: saving and quitting, moving around documents, character matching, finding and replacing characters, adding lines, etc. Apr 28, 2020 The way tag system works in Vim, is that Vim relies on a tag generator to generate a tag file (normally called tags in root directory) that contains a list of definitions. To see where Vim expects to find a tags file, you can run:set tags? Depending on what tags generator you use, the content of your tags file may look different.
Vim +PluginInstall +qall # or run:PluginInstall within Vim To upgrade bundles to their latest version, use the bang version: vim +PluginInstall! +qall # or run:PluginInstall! Within Vim tmux support (optional) If you will be using VIM with tmux for remote pairing or window management, see the pivotal/tmux-config README. Interactive Vim Tutorials (such as vimtutor) vimtutor is an interactive tutorial covering the most basic aspects of text editing. On UNIX-like system, you can start the tutorial with: $ vimtutor On Windows, “Vim tutor” can be found in the “Vim 7.x” directory under “All Programs” in the Windows menu. See:help vimtutor for further. Once we install Vim on our MacOS, we can use it for programming in any of the languages or for editing of any of the documents. To get started with the Vim, we either type simply vim on command line or we can open it via GUI by double clicking the vim icon shown in the Applications. Vim opens in the terminal which is shown in the image.
Using Vim Macro feature you can record and play a sequence of actions inside the editor.
This article explains how to perform record and play inside Vi and Vim editor using two detailed examples.
High Level Steps to Record and Play inside Vim
- Start recording by pressing q, followed by a lower case character to name the macro
- Perform any typical editing, actions inside Vim editor, which will be recorded
- Stop recording by pressing q
- Play the recorded macro by pressing @ followed by the macro name
- To repeat macros multiple times, press : NN @ macro name. NN is a number
Example 1: Sequence number generation inside a file using Vim Macro
1. Start a sequence-test.txt file to generate the sequence.
2. Go to insert mode and type “1 .” as shown below
Vim
Type: Esc i followed by 1.
3. Start the Recording and store it in register a.
Type: Esc q followed by a
- q indicates to start the recording
- a indicates to store the recordings in register a
- When you do q a, it will display “recording” at the bottom of the vi.
4. Copy the 1st line to 2nd line to have two lines with 1 . as shown below
Type: Esc yy followed by p
- yy will copy the current line
- p will paste the line that was just copied
Note: Vim will still show recording at the bottom as shown below.
5. Increment the number.
Type: Control a
By placing the cursor at the 2nd line, press Ctrl+a which increment the number to 2. as shown below.
Note: vim will still show recording at the bottom.
6. Stop the recording
Type: q
Press q to stop the recording. You’ll notice that recording message at the bottom of the vim is now gone.
7. Repeat the recording 98 times.
Type: 98@a
- Now repeat this job, by typing 98 @ a
- @a repeats the macro “a” one time.
- 98@a repeats the macros “a” 98 times generating the sequence number 1 – 100 as shown below using macros.
Example 2: Repeat Vim Macro with different arguments
This example explains how you can executing the same command, with different input for it. i.e Framing the same command, with different arguments.
Before Executing the Macro: change-password.sql
After Recording and executing the Macro: change-password.sql
1. Open the change-password.sql that has only the names.
2. Start the Recording and store it in register a
Type: q a
- q indicates to start the recording
- a indicates to store the recordings in register a
- When you do q a, it will display the message recording at the bottom of the vi.
3. Go to Insert Mode and Type ALTER USER
Type: I (Upper case i) followed by “ALTER USER ”
Place the cursor anywhere in the first line, and then press I. Which will take you to the first character of the line. Type ALTER USER
4. Copy the Next Word (i.e the name)
Type: Esc w yw
Vim Mac Tutorial Youtube
- Press Esc, and then press w to go to the next word ( name ).
- yw, copies the current word ( name ).
5.Go to the end and type IDENTIFIED BY ‘
Type: Esc A followed by ” IDENTIFIED BY ‘”
- Press Esc, and A to move the cursor to the end of the line, and then type space.
- Type IDENTIFIED BY ‘
6. Paste the copied Name
Type: Esc p
Press Esc, and then type p to paste the name that was copied in the step #4.
7. Complete the quote at the end.
Type: Esc A followed by ‘;
Press Esc, and A to go to the end of the line, and ‘;
8. Jump to the next line and stop the record.
Type: Esc j followed by q
- j to move to the next line.
- q to stop the recording
Note: The recording message shown in the bottom of the vi will now disappear. At this stage, the change-password.sql will look like the following.
Fig: Vim Macro completed the recording
9. Repete the Macro with the arguments in the corresponding line
Type: 8 @ a
- Now repeat this job 8 times by typing 8@a
- @a repeats the macro “a” one time.
- 8@a repeats the macros “a” 8 times completing the rest of the line automatically as shown below
Recommended Reading
Vim 101 Hacks, by Ramesh Natarajan. I’m a command-line junkie. So, naturally I’m a huge fan of Vi and Vim editors. Several years back, when I wrote lot of C code on Linux, I used to read all available Vim editor tips and tricks. Based on my Vim editor experience, I’ve written Vim 101 Hacks eBook that contains 101 practical examples on various advanced Vim features that will make you fast and productive in the Vim editor. Even if you’ve been using Vi and Vim Editors for several years and have not read this book, please do yourself a favor and read this book. You’ll be amazed with the capabilities of Vim editor.
Awesome Vim Editor Articles
Following are few awesome Vi / Vim editor tutorials that you might find helpful.
Mac Vim Config
Note: Please subscribe to The Geek Stuff and don’t miss any future Vi and Vim editor tips and tricks.