Рубрики
Uncategorized

Как генерировать TOC с помощью функции VIM

У меня было это требование при написании файла readme.md для автоматически генерировать TOC (таблица содержимого) Помечено с Vim, DevOps, функционально.

У меня было это требование при написании Readme.md файл для генерации TOC (Таблица содержимого) автоматически в погибший прямо выше конкретного ### 34. Название XYZ.

https://github.com/xjantoth/helmfile-course/blob/master/img/vim-trick.svg

Давайте притворяться здесь Мой титул в порядке.

vim README.md

...
### 20. This is my title I would like to generate TOC for

Lorem Ipsum is simply dummy text of the printing 
and typesetting industry. Lorem Ipsum has been 
the industrys standard dummy text ever since 
the 1500s, when an unknown printer took a galley 
of type and scrambled it to make a type specimen book. 
It has survived not only five centuries, but publishing 
software like Aldus PageMaker including versions of Lorem Ipsum.

...
:wq!

Вот фрагмент кода, который вам нужно вставить в свой ~/.vimrc.

" quick .vimrc access with ,t
function! Toc()
  let $file = @%
  let $linenr = line(".")
  .t.
  w
  "echo system('sed -i -E "${linenr}s/^[#]{2,} (.*)/
### 20. This is my title I would like to generate TOC for

Lorem Ipsum is simply dummy text of the printing 
and typesetting industry. Lorem Ipsum has been 
the industrys standard dummy text ever since 
the 1500s, when an unknown printer took a galley 
of type and scrambled it to make a type specimen book. 
It has survived not only five centuries, but publishing 
software like Aldus PageMaker including versions of Lorem Ipsum.
...

:wq!

Проверьте мою другую работу на UDEMY Узнайте AWS EKS Kubernetes Cluster и DEVOPS в AWS (часть 1)

Узнайте Kubernetes Docker/DevOps и Helm Charts с нуля

Узнайте devops helm/helmfile kubernetes развертывание

Узнайте devops kubernetes развертывание kops и terraform

Оригинал: «https://dev.to/xjantoth/how-to-generate-toc-by-using-vim-function-2djd»