0

So, I wrote next bash script:

#!/bin/bash

if [ "$#" -gt 1 ]; then
    path=$1
else
    path=$(cat subject.txt | tr -d '\n')
fi

nvim -p 1 "setup/$path/body.tex" -p 1 preamble/preamble.tex -p 1 -O 1 homework.tex -o 1 setup.tex variables/variables.tex

By the

nvim -p 1 "setup/$path/body.tex" -p 1 preamble/preamble.tex -p 1 -O 1 homework.tex -o 1 setup.tex variables/variables.tex

I mean:

-p 1 - create one tab and open "setup/$path/body.tex" int it (so that tab is taken), then do -p 1 - open preamble/preamble.tex in second tab so second tab is also taken, then do -p 1 -O 1 - create third tab and vertically divide it into two windows, in first vertical window we should open homework.tex then divide second window horizontally and in first half of second vertical window we should open setup.tex and in the second half of second vertical window we should open variables/variables.tex.

So, as a result of these simple operations we should have the next:

enter image description here

But, instead I get:

enter image description here

How to open files from terminal in desired pattern?

2 Answers 2

0

You can run custom script with -S option. Using bash heredoc, you can pass a fd as file to vim. You can also interpolate with bash variables.

fname=someFilePath

vim -S /proc/self/fd/9 9<<VIMS
vsp fileOnSplit
sp $fname
tabe fileOnTab1
tabe fileOnTab2
tabr
VIMS
1
  • The /proc/ but shouldn’t be necessary, I think, and isn’t OS portable. I’ll suggest a few other versions when I get to my computer
    – D. Ben Knoble
    Commented Apr 3, 2023 at 12:32
0

Options for custom layout:

  • If the commands are short, using -c will do, like vim -c 'edit foo' -c 'split bar'
  • Otherwise, use a session file with -S. This can be created in several ways:
    • with :mksession
    • by typing commands into a file
    • with herefiles in supported shells:
      vim -S <(cat <<EOF
      edit foo
      split bar
      EOF
      )
      
      Notably, this version of a herefile or heredoc does not rely on the /proc filesystem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.