Copy from vim to clipboard

You may be familiar with the yank command: y to copy selected text, yy to copy the current line. To copy to the system clipboard, we’ll use the same command with a few extras modifier to select the correct register.

  1. Choosing a register In Vim, you choose a register using ".
  2. The system register For both Mac and Windows, you can select the system register by using *.
  3. Putting it all together Enter visual mode by hitting v. Select the text you want to copy, then type: "*y

Block comment

Method 2 – Visual Mode

The other method you can use to comment out multiple lines is to use Visual Mode.

To do this, press ESC and navigate to the lines you want to comment out.

  • Press CTRL + V to enable Visual Mode.

    • Using the up and down arrow key, highlight the lines you wish to comment out.
  • Once you have the lines selected, press the SHIFT + I keys to enter insert mode.
  • Enter your command symbol, for example, # sign, and press the ESC key. Vim will comment out all the highlighted lines.

How to insert soft line break?

<!--- add two spaces -->
My line of text<space><space>
[Name of link](url)
<!--- or add one blackslash -->
My line of text\
[Name of link](url)

Regular expression

Regex 正则表达式

Short totorial: https://www3.ntu.edu.sg/home/ehchua/programming/howto/Regexe.html

The [...], known as character class (or bracket list), encloses a list of characters. It matches any SINGLE character in the list. In this example, [0-9] matches any SINGLE character between 0 and 9 (i.e., a digit), where dash (-) denotes the range.

Symbol Meaning Example
* the preceding character can occur 0 or more times. meo*w will match mew, meow, meooow, and meoooooooooooow.
[0-9]* matches zero or more digits. It accepts all those in [0-9]+ plus the empty string.
+ the preceding character can occur 1 or more times. meo+w will match meow, meooow, and meoooooooooooow, but not match mew.
[0-9]+ matches one or more digits such as 123, 000.
. any character .* means zero or more of any character.
[A-Za-z] all letters (uppercase and lowercase)  
{m} repetition indicator, meaning the preceding character can repeat exactly m times  
{m,} the preceding character can repeat m or more times  
{m,n} the preceding character can repeat m to n times, inclusive  
^ start-of-line  
$ end-of-line ^[0-9]+$ matches a numeric string.