1

I use bash and like to use the built-in command Ctrl xCtrl e to invoke an editor in the shell in order to edit the current line.

This creates a temporary file, named /tmp/bash-fc.[Some random alphanumeric string], and once that file is saved, whatever you have written gets executed.

Since I have my EDITOR environment variable set to neovim, it's possible for me to turn github copilot on while I'm editing my shell command with the vim command: let b:copilot_enabled = v:true

This is very cool for on the fly scripting. However, since copilot looks for file extensions, I can't turn it on by default without having it on permanently whenever I start nvim.

I thought of mapping a key to the command let b:copilot_enabled = v:true with in my .vimrc, but I can't get it to work. Looking for any suggestions.

0

2 Answers 2

1

It is possible to configure Vim to automatically set the filetype based on other criteria that the mere file extension.

In your ~/.config/nvim/ftdetect/bash you can add the following line:

autocmd BufNewFile,BufRead bash-fc[-.]* set ft=bash

You have to use set ft=bash instead of setfiletype bash because Vim already set the filetype to sh for this pattern.

If you Vim distribution also set the filetype of this pattern to sh maybe could you use the sh filetype to activate copilot.

2
  • Just brilliant. This works!! Mar 12, 2023 at 2:28
  • Thanks for the feedback :-) If it solves your problem you can accept the solution using the v green button next to the arrow voting buttons. It let the question rest :-) Mar 12, 2023 at 5:14
1

@Vivian De Smedt's answer is great. Mapping a custom key like so: map <[KEY CODE HERE]> :let b:copilot_enabled = v:true<CR> can turn Copilot on as well.

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.