Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Mastering Vim

You're reading from   Mastering Vim Efficient and effortless editing with Vim and Vimscript

Arrow left icon
Product type Paperback
Published in Jul 2024
Publisher Packt
ISBN-13 9781835081877
Length 300 pages
Edition 2nd Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Ruslan Osipov Ruslan Osipov
Author Profile Icon Ruslan Osipov
Ruslan Osipov
Arrow right icon
View More author details
Toc

Table of Contents (11) Chapters Close

Preface 1. Chapter 1: Getting Started FREE CHAPTER 2. Chapter 2: Advanced Editing and Navigation 3. Chapter 3: Follow the Leader Plugin Management 4. Chapter 4: Understanding Structured Text 5. Chapter 5: Build, Test, and Execute 6. Chapter 6: Refactoring Code with Regex and Macros 7. Chapter 7: Making Vim Your Own 8. Chapter 8: Transcending the Mundane with Vimscript 9. Chapter 9: Where to Go from Here 10. Index

Read the Vim manual using :help

The best learning tool Vim can offer is certainly a :help command, as can be seen in the following screenshot:

Figure 1.38 – The :help page – if you’ve read it, you probably wouldn’t have needed to read this book

Figure 1.38 – The :help page – if you’ve read it, you probably wouldn’t have needed to read this book

It’s an enormous collection of resources and tutorials that comes installed with Vim. Scroll through using the Page Up and Page Down keys (bonus point for using Ctrl + b and Ctrl + f instead), there is a lot of useful information there.

:help help-summary

Consider reading through the help-summary page at some point in your Vim journey. It’s short, and arms you with many tools needed to navigate Vim help effectively. I incorporated some tips from help-summary in this section, but there are more!

Whenever you are stuck or want to learn more about a particular command, try searching it using :help (you can shorten it to :h). Let’s try searching for the normal mode cc command we’ve learned:

:h cc

Here’s the output of this code:

Figure 1.39 – A :help page for a cc command

Figure 1.39 – A :help page for a cc command

Help tells us the way the command works, as well as how different options and settings affect the command (for instance, the autoindent setting preserves the indentation).

Searching for options

In Vim help, options are always denoted with single quotation marks. For example, if you wanted to look for the autoindent option (remember set autoindent in your .vimrc?), you’ll execute :help 'autoindent'.

:help is a command that navigates a set of help files. As you look through the help files, you’ll notice that certain words are highlighted in color. These are tags, and can be searched for using the :help command. Unfortunately, not every tag name is intuitive. For instance, if we wanted to learn how to search for a string in Vim, we could try using the following:

:h search

However, it looks like this command takes us to the entry on expression evaluation, which is not exactly what we were looking for, as demonstrated by the following screenshot:

Figure 1.40 – A help page for a search() expression

Figure 1.40 – A help page for a search() expression

To find the right entry, type :h search (don’t hit Enter yet) followed by Ctrl + d. This will give you a list of help tags containing the search substring. One of the options shown is search-commands, which is what we’d be looking for. Complete your command in the following way to get to the entry we were looking for:

:h search-commands

The following display shows the right help entry for search:

Figure 1.41 – A :help page for search commands

Navigating search files

A discerning reader might notice certain keywords adorned with various characters ([, {, |, etc.) or highlighted (depending on your color scheme) in help pages. When your cursor is over a keyword in a help file, you can press Ctrl + ] to jump to the definition of the keyword, and Ctrl + o to jump back. Give it a shot!

Search

Speaking of search functionality, you can search inside help pages (or any file open in Vim) using /search term to search forward from the cursor or ?search term to search backward. See Chapter 2 to learn more about how to perform search operations.

Finally, Vim comes with a handy vimtutor utility, which you can invoke on the command line. This book covers most things that vimtutor teaches, but it doesn’t mean you should sleep on it – vimtutor includes many exercises that can build Vim commands into your muscle memory.

Don’t forget to use Vim’s help system any time you have questions or want to better understand the way Vim behaves.

You have been reading a chapter from
Mastering Vim - Second Edition
Published in: Jul 2024
Publisher: Packt
ISBN-13: 9781835081877
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at AU $24.99/month. Cancel anytime