0

I am running vim 8.2.2121.

I am trying to open 3 tabs

  • One tab has instructions in it and is opened read only.
  • Both tabs 2 and 3 create :new files and read template files into them on separate tabs.

There are two mysteries in the vimscript / python code below...

  1. Why can't I "template" the files into the buffer one after another?

  2. Why can't I delay the running of a vim.command() user command without it freezing?

I suspect the problem is that the User Commands are not running sequentially, but rather all at once, and thus some sleep is in order. But I have also tried running multiple commands in the same User Command prompt and I get the same result, three tabs, first file opens and the rest are empty.

function Init()

" Configure tabs in vim for different steps.
"
python3 << EOF
import vim
import time

setup_cmd_list = (
    # Change to the project directory
    'cd ~/projects/proj',

    # Open the read me instructions, read only.
    "silent view! ./README.md",

    # Create a new buffer with filename der_file.txt
    "new! der_file.txt",

    # Read a template into the buffer...
    "read $HOME/templates/template1.txt",

    # MYSTERY_1: Open new tab (the new tab is opened, but none of the templates show up...???)
    "tabnew",

    # Create a new buffer with filename die_file.txt
    "new! die_file.txt",

    # Read a template into the buffer...
    "read $HOME/templates/template2.txt",

    # ...more stuff
)

    for cmd in setup_cmd_list:
       try:
          # time.delay(300) # MYSTERY_2: Couldn't get this to work, it freezes vim in the terminal.
          vim.command(cmd)
       except vim.error:
          print("fail! " + cmd)
EOF
endfunction
11
  • 2
    First: does it work if you leave Python out of the equation? Commented Jan 23 at 4:25
  • @romainl It's worth a shot... Commented Jan 23 at 5:03
  • @romainl Yeah, that worked. So is vim+python just lousy or something? I could have just written it in vimscript, I just wanted to try out vim with python integration. It doesn't seem to work real well. Commented Jan 23 at 5:38
  • 1
    You might want to test the Python code in isolation, as well. FWIW, your indentation is off. Commented Jan 23 at 7:30
  • 1
    And the tuple misses a closing ). Commented Jan 23 at 10:30

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.