BanditHijo.dev

Memasang GitHub Copilot dan CopilotChat di Neovim macOS

Created at: 2025-12-18
Author by: BanditHijo

Saya terbilang cukup terlambat untuk mencoba GitHub Copilot di Neovim. Karena teman-teman yang lain di group Telegram Vim Indonesia sudah lebih dulu mencobanya dan membagikan pengalaman mereka dalam menggunakan GitHub Copilot ataupun code assistant lainnya di Neovim.

Requirements

neovim 0.10.0+, curl 8.0.0+, nodejs, gh, plenary.nvim, telescope.nvim

Optional Dependencies

  1. tiktoken - for accurate token counting
  2. git - for git diff context features
  3. ripgrep - for improved search performance
  4. lynx - for improved URL context features

Instalasi

Authentikasi GitHub via GitHub CLI

Saya menggunakan Homebrew untuk memasang GitHub CLI di macOS.

$ brew install gh

Setelah terpasang, saya melakukan autentikasi dengan perintah berikut,

$ gh auth login

Nanti akan muncul pilihan untuk memilih metode autentikasi. Saya memilih Web browser lalu mengikuti langkah-langkah yang diberikan.

Pasang di Neovim

Saya menggunakan packer.nvim sebagai plugin manager di Neovim.

1require("packer").startup(function(use)
2 -- github copilot
3 use {
4 'CopilotC-Nvim/CopilotChat.nvim',
5 requires = {
6 { "github/copilot.vim" },
7 { "nvim-lua/plenary.nvim" },
8 { "nvim-telescope/telescope.nvim" },
9 }
10 }
11end)

Lalu saya jalankan perintah :PackerInstall di Neovim untuk menginstal plugin tersebut.

Build tiktoken

Untuk memasang tiktoken di macOS, saya menggunakan make di direktori repositori CopilotChat.nvim.

Saya masuk ke direktori berikut,

$ cd ~/.local/share/nvim/site/pack/packer/start/CopilotChat.nvim/

Lalu saya jalankan perintah berikut,

$ make tiktoken

Outputnya seperti berikut, berarti pemasangan tiktoken berhasil.

mkdir -p build
curl -LSsf https://github.com/gptlang/lua-tiktoken/releases/latest/download/tiktoken_core-macOS-arm64-luajit.dylib -o build/tiktoken_core.dylib
curl -LSsf https://github.com/gptlang/lua-tiktoken/releases/latest/download/tiktoken_core-macOS-arm64-lua51.dylib -o build/tiktoken_core-lua51.dylib

Karena saya menggunakan macOS M4 dengan arsitektur ARM64, make titktoken tidak melakukan kompilasi, tetapi mengunduh file prebuit binary .dylib dari repositori lua-tiktoken di GitHub.

Untuk mengetahui apakah sudah berhasil atau belum, saya melakukan pengecekan dengan menjalankan perintah berikut di Neovim,

:lua print(require("CopilotChat.tiktoken"))

Outputnya seperti berikut, berarti tiktoken sudah berhasil dipasang.

table: 0x010180e018

Setelah berhasil, saya menambahkan run = "make tiktoken" di konfigurasi packer.nvim seperti berikut,

1require("packer").startup(function(use)
2 -- github copilot
3 use {
4 'CopilotC-Nvim/CopilotChat.nvim',
5 requires = {
6 { "github/copilot.vim" },
7 { "nvim-lua/plenary.nvim" },
8 { "nvim-telescope/telescope.nvim" },
9 },
10 run = "make tiktoken", -- 👈
11 }
12end)

Setup file konfigurasi di Neovim

Agar bisa merubah-rubah konfigurasi di GitHub CopilotChat, saya menambahkan konfigurasi berikut Neovim saya.

1require("packer").startup(function(use)
2 -- github copilot
3 use {
4 'CopilotC-Nvim/CopilotChat.nvim',
5 requires = {
6 { "github/copilot.vim" },
7 { "nvim-lua/plenary.nvim" },
8 { "nvim-telescope/telescope.nvim" },
9 },
10 config = require("config.CopilotChat"), -- 👈
11 run = "make tiktoken",
12 }
13end)

Lalu saya membuat file ~/.config/nvim/lua/config/CopilotChat.lua dengan isi sebagai berikut,

Dan ini adalah konfigurasi yang saya gunakan.

1local status_ok, _ = pcall(require, "CopilotChat")
2if not status_ok then
3 return
4end
5
6require("CopilotChat").setup({
7 model = 'gpt-5-mini', -- Default model to use, see ':CopilotChatModels' for available models (can be specified manually in prompt via $).
8 language = 'Indonesian', -- Default language to use for answers
9 show_help = true, -- Shows help message as virtual lines when waiting for user input
10 show_folds = true, -- Shows folds for sections in chat
11 auto_fold = false, -- Automatically non-assistant messages in chat (requires 'show_folds' to be true)
12 highlight_selection = true, -- Highlight selection
13 highlight_headers = true, -- Highlight headers in chat
14 auto_follow_cursor = true, -- Auto-follow cursor in chat
15 insert_at_end = true, -- Move cursor to end of buffer when inserting text
16 window = {
17 layout = 'vertical', -- 'vertical', 'horizontal', 'float', 'replace', or a function that returns the layout
18 relative = 'editor',
19 border = 'single',
20 -- width = 0.3, -- fractional width of parent, or absolute width in columns when > 1
21 width = 70, -- fractional width of parent, or absolute width in columns when > 1
22 height = 0.5, -- fractional height of parent, or absolute height in rows when > 1
23 }, --- î°®
24 headers = {
25 user = ' User', -- Header to use for user questions
26 assistant = 'ï„“ Copilot', -- Header to use for AI answers
27 tool = ' Tool', -- Header to use for tool calls
28 },
29 mappings = {
30 accept_diff = {
31 insert = "<C-S-y>",
32 normal = "<C-S-y>"
33 },
34 close = {
35 insert = "<C-c>",
36 normal = "q"
37 },
38 complete = {
39 insert = "<Tab>"
40 },
41 jump_to_diff = {
42 normal = "gj"
43 },
44 quickfix_answers = {
45 normal = "gqa"
46 },
47 quickfix_diffs = {
48 normal = "gqd"
49 },
50 reset = {
51 insert = "<C-l>",
52 normal = "<C-l>"
53 },
54 show_diff = {
55 normal = "gd"
56 },
57 show_help = {
58 normal = "gh"
59 },
60 show_info = {
61 normal = "gc"
62 },
63 submit_prompt = {
64 insert = "<C-s>",
65 normal = "<CR>"
66 },
67 yank_diff = {
68 normal = "gy",
69 register = '"'
70 },
71 disable_default_keymaps = false,
72 },
73
74 -- default providers
75 providers = require('CopilotChat.config.providers'),
76
77 -- default functions
78 functions = require('CopilotChat.config.functions'),
79
80 -- default prompts
81 prompts = require('CopilotChat.config.prompts'),
82
83 -- default mappings
84 -- mappings = require('CopilotChat.config.mappings'),
85})
86
87-- Auto-command to customize chat buffer behavior
88vim.api.nvim_create_autocmd('BufEnter', {
89 pattern = 'copilot-*',
90 callback = function()
91 vim.opt_local.relativenumber = false
92 vim.opt_local.number = false
93 vim.opt_local.conceallevel = 0
94 -- vim.bo.filetype = 'markdown'
95 end,
96})
97
98-- In your colorscheme or init.lua
99vim.api.nvim_set_hl(0, 'CopilotChatHeader', { fg = '#D16969', bold = true })
100vim.api.nvim_set_hl(0, 'CopilotChatSeparator', { fg = '#D16969' })
101
102-- Some plugins (e.g. copilot.vim) may also map common keys like <Tab> in insert mode.
103-- To avoid conflicts, disable Copilot's default <Tab> mapping with:
104vim.g.copilot_no_tab_map = true
105vim.keymap.set('i', '<S-Tab>', 'copilot#Accept("\\<S-Tab>")', { expr = true, replace_keycodes = false })
  1. Secara default saya menggunakan model gpt-5-mini.
  2. Saya juga membuat language menjadi Indonesian agar jawaban yang diberikan dalam bahasa Indonesia.
  3. Saya juga mengganti mapping accept_diff menjadi <C-S-y> agar tidak bentrok dengan mapping navigasi <C-y di Neovim yang digunakan untuk scroll ke atas.
  4. Untuk accept suggestion dari Copilot, saya mengganti mapping dari <Tab> menjadi <S-Tab> agar tidak bentrok dengan mapping complete di CopilotChat yang menggunakan <Tab>.
  5. Saya juga membuat conceallevel menjadi 0 agar tidak ada karakter yang disembunyikan di buffer chat CopilotChat.

Authentikasi GitHub Copilot

Setelah semua terpasang, saya melakukan autentikasi GitHub Copilot dengan perintah berikut di Neovim,

:Copilot setup

Tinggal mengikuti langkah-langkah yang diberikan untuk menyelesaikan proses autentikasi.

Jika berhasil, bisa cek dengan perintah berikut di Neovim,

:Copilot status
Copilot: Ready

Sip! GitHub Copilot dan CopilotChat sudah siap digunakan.

Penggunaan

Setelah semua terpasang, saya bisa memulai chat dengan GitHub CopilotChat dengan perintah berikut di Neovim,

:CopilotChat

Lalu akan muncul buffer baru untuk melakukan chat dengan GitHub CopilotChat.

 User ──────────────────────────────────────────────────────────
gh to show help
_

Setelah menulis pertanyaan, saya bisa mengirimkannya dengan menekan <C-s> di mode insert.

 User ──────────────────────────────────────────────────────────

hello

 Copilot ───────────────────────────────────────────────────────

Halo — ada yang bisa saya bantu hari ini?

 User ──────────────────────────────────────────────────────────
gh to show help
1079/128000 tokens used
_

Untuk melihat help, saya bisa menekan gh di mode normal.

**`Special tokens`**
`@<function>` to share function
`#<function>` to add resource
`#<function>:<input>` to add resource with input
`/<prompt>` to select a prompt
`$<model>` to select a model
`> <text>` to make a sticky prompt (copied to next prompt)

**`Mappings`**
`<C-S-y>` to accept diff
`<C-l>` to reset
`<CR>` or `<C-s>` in insert mode to submit prompt
`<Tab>` in insert mode to complete
`gc` to show info
`gd` to show diff
`gh` to show help
`gj` to jump to diff
`gqa` to quickfix answers
`gqd` to quickfix diffs
`gy` to yank diff
`q` or `<C-c>` in insert mode to close

q to close

Selesai! Sekarang saya sudah bisa menggunakan GitHub Copilot dan CopilotChat di Neovim di macOS.

Untuk command lengkap dan dokumentasi lainnya, bisa dilihat di repositori GitHub dari CopilotChat.nvim.

Referensi

  1. https://github.com/github/copilot.vim
    Tanggal diakses: 2025-12-18

  2. https://github.com/CopilotC-Nvim/CopilotChat.nvim
    Tanggal diakses: 2025-12-18