Home  >  Q&A  >  body text

vimrc - Can vim realize the complex requirement of automatically detecting jpg files in the working directory and then automatically filling in the content based on the number of files?

My requirement is to detect the images in the working directory, and then fill in the corresponding img tags into page.html. Just like the effect I manually had.

PHPzPHPz2712 days ago599

reply all(2)I'll reply

  • 黄舟

    黄舟2017-05-16 16:36:42

    You don’t know how to use your own brain.

    …wait, you’re Windows? Then I will just say that the idea is good.

    1. Read in the file list. For example, you can use the !r ls *.jpg 来读。Windows 上自己想办法。如果你没办法通过外部命令获取文件名列表,也可以试试 Vim 的 glob() function under Linux.

    2. Ctrl-V Enter column block visual mode and write the same part in front of the file name (select the beginning and press I)

    3. This step is not very intuitive. Use V to enter line selection, then press :s/$/..../ to append characters at the end with replace

    Of course you can also use substitution in step 2.

    There is also a plug-in called visincr, which is very suitable for generating this kind of numerical sequence.

    reply
    0
  • PHPz

    PHPz2017-05-16 16:36:42

    This is the purpose of HTML template engines and various front-end construction tool chains. . . . .

    vim is possible, but it is not recommended because you still need to update it manually

    reply
    0
  • Cancelreply