2

I've assembled the following command to take a markdown file and add a ==== under each line that starts with a #:

:g/^#/t. | s/./=/g

How exactly does this work? As far as I understand:

  • :g/ start a global command
  • ^#/ where the line starts with a #
  • /t. (not sure what this is or does, had trouble finding it in help)
  • | (also not quite sure exactly how this works, I've seen a few different examples of this)
  • s/./=/g substitute every character (.) with a =

Any clarification/pointers on the above two components of the commands would be great.

David542
  • 2,445
  • 14
  • 50
  • 2
    See :h :t and :h :bar. Important feature when searching for help is <C-d>. Just enter :h |<C-d>, it will show any help topics that contains the word bar (Vim is automatically replacing | with bar). Less helpful with :h t<C-d> I have to admit :-). – Ralf May 31 '20 at 07:07
  • @Ralf -- cool, thanks for that tip. Now clear on the t ==> alias for co[py]. Still working through . and | -- there are lots of references for them in the docs... – David542 May 31 '20 at 07:17
  • 1
    The :t -> :copy seems to be historical. It's also in original vi. And: :h :.. David, I don't want to annoy you with all the "see help", but the help of Vim is really good and extensive. It is sometimes a little bit difficult to find the right help subject. Another cool feature is :helpgrep to search through the help files. – Ralf May 31 '20 at 07:26
  • @Ralf sure, I appreciate you pointing that out. Out of curiosity, why do you do :h :. instead of just :h . (which is what I was doing previously)? – David542 May 31 '20 at 07:28
  • You are using . with a (ex-)command, so the leading colon means "dot on the command line". Like the different between :h bar and :h :bar. Sometimes also with leading c_ like :help c_<CR>. – Ralf May 31 '20 at 07:59
  • 2
    @David542 Simply :h . means "give me help about "dot" in Normal mode", i.e. repeat-operator. While :h :. means "say what is "dot" in the command-line?" Just read the main topic <F1> - right after the words "Get specific help" there are several examples, and also the link to :h help-summary which gives full explanation. – Matt May 31 '20 at 07:59
  • And another: :help help.txt`. The start of that file explains the different prefixes used with help subjects. – Ralf May 31 '20 at 08:07

1 Answers1

4

The command :to is a synonym of :copy that can be abbreviated to :t. So :[range]t. is a short way of saying copy the lines in the range to the current line.

The | is the command separator; it’s a bit like a semicolon in most C-like languages. See :help :bar.

D. Ben Knoble
  • 26,070
  • 3
  • 29
  • 65