03 December 2025

Creating links for table of contents of markdown files

Step 1 - add [ to start of each line

:'a,s/^/[

[1.0 Mobile Devices
[1.1 installing and configuring a battery replacement in a laptop
[1.2 Installing and configuring a keyboard replacement in a laptop

Step 2 - append ] to last non-space in each line

:'a,g/^/normal g_a]

[1.0 Mobile Devices]
[1.1 installing and configuring a battery replacement in a laptop]
[1.2 Installing and configuring a keyboard replacement in a laptop]

Step 3 - copy each whole line and append it to each line

:'a,g/^/normal 0yg_g_p

Step 4 - Change the 2nd '[' into '('

:'a,g/^/normal 0f[r(

Step 5 - Change the 2nd ']' into ')'

:'a,g/^/normal 2f]r)


[1.0 Mobile Devices](Mobile Devices) 

[1.1 installing and configuring a battery replacement in a laptop](installing and configuring a battery replacement in a laptop) 

[1.2 Installing and configuring a keyboard replacement in a laptop](Installing and configuring a keyboard replacement in a laptop) 

Step 6 - Insert a Carriage Return between ']' and '(', i.e. replacing '](' with ']\r(' in every line

:'a,s/\](/\]\r(/
or
:'a,s/\(/\r\(/


Step 7 - In every () line, replace every space with a hyphen

:'a,g/(/s/ /-/g

Step 8 - in every () line, change every uppercase letter into lowercase letter

:'a,g/(/normal 0gu$

Step 9 - in every () line, add '#' after '('

:'a,g/(/normal 0a#


Step 10 - go to every [] line, run the command 'gJ'

:'a,g/\[/normal gJ

Notes:
'J' - there will be a space between the 2 lines which are now joined together
'gJ' - there will be no space between the 2 lines which are now joined together




No comments:

Post a Comment