I am using bspwm so I added this line to my .vimrc:

au BufWritePost $XDG_CONFIG_HOME/sxhkd/sxhkdrc silent exec "!pkill -USR1 -x sxhkd && sxhkd &

So that when I edit sxhkdrc, it automatically reloads it. However, even though I added "silent exec", it still prints a lot of junk all over the text, forcing me to do redraw!. I thought of adding | redraw! and the end of the above line, but the junk still appears, I believe because it will redraw before sxhkd prints all the crap over the terminal.

What would be the best way to "fix" this? I could make a function that sleeps some time and only redraws after, but that doesn't feel very clean, is there a better way?


The output you're getting in your terminal that is messing up the text in Vim is likely from the running sxhkd binary that you're spawning in background.

As a possible way to fix this, you can redirect its output to /dev/null when you launch it from the autocmd.

Instead of ending the external command with:

sxhkd &

Use instead:

sxhkd >/dev/null 2>&1 &

Maybe even use a redirect for stdin as well, to insure even less interference with Vim.

sxhkd </dev/null >/dev/null 2>&1 &

Consider that launching a background process from Vim might have undesirable side effects, such as inheriting the environment variables and the terminal where it's started from.

If you have the option, consider starting sxhkd from your system manager. If you're using systemd, you can configure user services in ~/.config/systemd/user/*.service and if you do so, you can restart it with systemctl --user restart sxhkd.service which happens in foreground and will be completed before you're back to Vim. (If you're interested in that, consider asking in Unix & Linux SE for help to configure it.)

Your Answer

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

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