1

I use nvim as my main editor, and I run services using systemd. When I edit a unit file directly, there is a built in filetype for systemd, which is great.

However, when I edit a service file with

systemctl edit my-service.service

systemd copies the file to a temporary file named something like .#my-service.servicee18f4d3ef193cd58 and opens it as a buffer, and the filetype isn't detected because of the filename, so I have to manually set it with set ft=systemd in nvim.

I read about the SYSTEMD_EDITOR environment variable, and tried setting it in my zshrc like so:

export SYSTEMD_EDITOR='nvim -c "set ft=systemd"'

but that results in nvim being launched with two buffers named ft=systemd" and .#my-service.servicee18f4d3ef193cd58 when I issue systemctl edit --full my-service.service

How can I correctly set that environment variable? or, alternatively, how can I expand vim's ft detection to include files of this naming pattern?

1

I realized I do know how to set a filetype based on extension in my vimrc:

autocmd BufNewFile,BufRead *.service* set ft=systemd

I'm still interested in what my quoting error in the question is.

3
  • 2
    See also Vim's runtime/filetype.vim. The quoting error is simply that systemd isn't running sh -c "$SYSTEMD_EDITOR". It's splitting the variable on whitespace. So quoting is ineffective. In general you can't rely on quoting, or even whitespace splitting, on the various EDITOR variables. – muru Apr 27 '20 at 8:25
  • @muru Yes, this! Please post it as an answer. – filbranden Apr 27 '20 at 12:23
  • @muru thanks for that link! I put in an issue report here I think nvim merges those changes downstream – jameh Apr 27 '20 at 19:16

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.