I want to edit text in Vim and want to automate the process. Here's my program:
$ cat /usr/local/bin/example-script
echo "Some Text" > ~/Desktop/filename
nvim ~/Desktop/filenameThe program works as required from the terminal. The file is created and I can edit it from vim.
$ example-script
$ cat ~/Desktop/filename
This text was edited from VimHowever, when launching the program from a keyboard shortcut, Vim is not opened.
Part of the script must have been executed, because the file is reset after executing the shortcut:
$ cat ~/Desktop/filename
Some Text 1 Answer
This is a program that runs in a terminal. Running a terminal command from a keyboard shortcut instead of the terminal emulator will not fire the latter up. Instead, the launched instance of vim is sitting somewhere in your computer memory, waiting on input that will never come.
Change your script to read gnome-terminal -- nvim ~/Desktop/filename (if you use another terminal emulator, substitute the correct syntax for it). That way, the script will open your terminal with vim automatically opened. When you quit vim, the terminal emulator will directly close.