Cannot Launch Vim from Keyboard Shortcut

Cannot Launch Vim from Keyboard Shortcut

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/filename

The 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 Vim

However, 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.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Alexander Ross
Author

Alexander Ross

Alexander Ross has covered the video game industry for a decade, writing deep dives on game design, esports tournaments, VR developments, and gaming culture.