idbrii
idbrii

Reputation: 11916

How do I find out what a vim command does?

Many vim blog posts will give a series of vim commands, but don't explain all of the details. How can a new user use vim's help to figure out how it works?

For example, here's a command from this blog post:

ggjV/---<cr>k:v/layout:\|title:/d<cr>

I recognize that /layout:\|title:/ is a regex, but how can I find out what v/regex/d does?

Upvotes: 3

Views: 2146

Answers (1)

idbrii
idbrii

Reputation: 11916

Vim has three methods of looking up help:

  • :help keyword
    • Look up keyword (supports partial matches and tab completion).
    • Good if you know what you're looking for.
  • :helpgrep query
    • Grep all help for specific text query.
    • Good if you don't know what you're looking for.
  • K
    • Look up help for the text under the cursor.
    • Only meaningful when editing vimscript.
    • tpope's vim-scriptease has an improved K that figures out the type of command from the context (to differentiate :call from call()).

In this case, we know part of the command so we can use :help. But what keyword do we use?

Tab completion with the right prefixes makes it pretty quick to find what you're looking for if you already know something about the command:

  • : is used for cmdline/Ex-mode commands
    • Example: :help :help
    • These are input at the bottom of the screen. See :help :
  • ' is used for options
    • Example: :help 'incsearch'
    • These are vim settings applied with :set. See :help :set and :help option-list.
  • No prefix for normal mode commands
    • Example: :help CTRL-]
    • See :help Normal-mode
  • i_ for insert mode
    • Example: :help i_CTRL-[
    • See :help Insert-mode
  • v_ for visual mode
    • Example: :help v_CTRL-]
    • See :help Visual-mode

Vim command names almost always end at punctuation (non-word characters).

If we enter in the sequence of commands, we'll see that v/layout is typed in from the cmdline (input at bottom of screen). That means we need to include the colon. We'll ignore /layout since punctuation terminates the command name.

:help :v

Vim will give you the abbreviated name for the command and information about using it. In this case, it mentions that :v is "Same as :g!", so we can scroll up to look for :g! (:global).

In short, Vim help has everything you need: :help help-summary has the above information and more new user tips.

Upvotes: 6

Related Questions