Skip to content

Commit cb3e80b

Browse files
committed
refactor(modules): refactore plugins for quarto
into sensible modules
1 parent 6464e7f commit cb3e80b

File tree

6 files changed

+579
-574
lines changed

6 files changed

+579
-574
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ https://youtube.com/playlist?list=PLabWm-zCaD1axcMGvf7wFxJz8FZmyHSJ7
1414
Clone this repo into `~/.config/nvim/` or copy-paste just the parts you like.
1515

1616
If you already have your own configuration, check out `lua/plugins/quarto.lua`
17-
for the configuration of all plugins directly relevant to your Quarto experience.
17+
for the configuration of plugins directly relevant to your Quarto experience.
18+
The comments in this file will also point to to other plugins required for
19+
the full functionality.
1820

1921
This configuration can make use of a "Nerd Font" for icons and symbols.
2022
Download one here: <https://www.nerdfonts.com/> and set it as your terminal font.
@@ -48,10 +50,8 @@ rm -r ~/.local/state/nvim
4850

4951
## Screenshots
5052

51-
![image](https://user-images.githubusercontent.com/17450586/210392216-a99815ac-1872-4c48-bf24-5a50df14c6d2.png)
5253
![image](https://user-images.githubusercontent.com/17450586/210392419-3ee2b3e3-e805-4e36-99ab-6922abe3a66b.png)
5354
![image](https://user-images.githubusercontent.com/17450586/210392573-57c0ad1c-5db0-4f2a-9119-608bd2398494.png)
54-
![image](https://user-images.githubusercontent.com/17450586/210392838-1c643a65-e792-4a54-bbdb-3ae959995a79.png)
5555

5656
Use the integrated neovim terminal to execute code chunks:
5757

lua/plugins/completion.lua

+177
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
return {
2+
{
3+
'windwp/nvim-autopairs',
4+
config = function()
5+
require('nvim-autopairs').setup {}
6+
require('nvim-autopairs').remove_rule '`'
7+
end,
8+
},
9+
10+
{ -- completion
11+
'hrsh7th/nvim-cmp',
12+
event = 'InsertEnter',
13+
dependencies = {
14+
{ 'hrsh7th/cmp-nvim-lsp' },
15+
{ 'hrsh7th/cmp-nvim-lsp-signature-help' },
16+
{ 'hrsh7th/cmp-buffer' },
17+
{ 'hrsh7th/cmp-path' },
18+
{ 'hrsh7th/cmp-calc' },
19+
{ 'hrsh7th/cmp-emoji' },
20+
{ 'saadparwaiz1/cmp_luasnip' },
21+
{ 'f3fora/cmp-spell' },
22+
{ 'ray-x/cmp-treesitter' },
23+
{ 'kdheepak/cmp-latex-symbols' },
24+
{ 'jmbuhr/cmp-pandoc-references' },
25+
{ 'L3MON4D3/LuaSnip' },
26+
{ 'rafamadriz/friendly-snippets' },
27+
{ 'onsails/lspkind-nvim' },
28+
},
29+
config = function()
30+
local cmp = require 'cmp'
31+
local luasnip = require 'luasnip'
32+
local lspkind = require 'lspkind'
33+
34+
local has_words_before = function()
35+
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
36+
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match '%s' == nil
37+
end
38+
39+
cmp.setup {
40+
snippet = {
41+
expand = function(args)
42+
luasnip.lsp_expand(args.body)
43+
end,
44+
},
45+
completion = { completeopt = 'menu,menuone,noinsert' },
46+
mapping = {
47+
['<C-f>'] = cmp.mapping.scroll_docs(-4),
48+
['<C-d>'] = cmp.mapping.scroll_docs(4),
49+
50+
['<C-n>'] = cmp.mapping(function(fallback)
51+
if luasnip.expand_or_jumpable() then
52+
luasnip.expand_or_jump()
53+
fallback()
54+
end
55+
end, { 'i', 's' }),
56+
['<C-p>'] = cmp.mapping(function(fallback)
57+
if luasnip.jumpable(-1) then
58+
luasnip.jump(-1)
59+
else
60+
fallback()
61+
end
62+
end, { 'i', 's' }),
63+
['<C-e>'] = cmp.mapping.abort(),
64+
['<c-y>'] = cmp.mapping.confirm {
65+
select = true,
66+
},
67+
['<CR>'] = cmp.mapping.confirm {
68+
select = true,
69+
},
70+
71+
['<Tab>'] = cmp.mapping(function(fallback)
72+
if cmp.visible() then
73+
cmp.select_next_item()
74+
elseif has_words_before() then
75+
cmp.complete()
76+
else
77+
fallback()
78+
end
79+
end, { 'i', 's' }),
80+
['<S-Tab>'] = cmp.mapping(function(fallback)
81+
if cmp.visible() then
82+
cmp.select_prev_item()
83+
else
84+
fallback()
85+
end
86+
end, { 'i', 's' }),
87+
88+
['<C-l>'] = cmp.mapping(function()
89+
if luasnip.expand_or_locally_jumpable() then
90+
luasnip.expand_or_jump()
91+
end
92+
end, { 'i', 's' }),
93+
['<C-h>'] = cmp.mapping(function()
94+
if luasnip.locally_jumpable(-1) then
95+
luasnip.jump(-1)
96+
end
97+
end, { 'i', 's' }),
98+
},
99+
autocomplete = false,
100+
101+
---@diagnostic disable-next-line: missing-fields
102+
formatting = {
103+
format = lspkind.cmp_format {
104+
mode = 'symbol',
105+
menu = {
106+
otter = '[🦦]',
107+
nvim_lsp = '[LSP]',
108+
luasnip = '[snip]',
109+
buffer = '[buf]',
110+
path = '[path]',
111+
spell = '[spell]',
112+
pandoc_references = '[ref]',
113+
tags = '[tag]',
114+
treesitter = '[TS]',
115+
calc = '[calc]',
116+
latex_symbols = '[tex]',
117+
emoji = '[emoji]',
118+
},
119+
},
120+
},
121+
sources = {
122+
{ name = 'otter' }, -- for code chunks in quarto
123+
{ name = 'path' },
124+
{ name = 'nvim_lsp' },
125+
{ name = 'nvim_lsp_signature_help' },
126+
{ name = 'luasnip', keyword_length = 3, max_item_count = 3 },
127+
{ name = 'pandoc_references' },
128+
{ name = 'buffer', keyword_length = 5, max_item_count = 3 },
129+
{ name = 'spell' },
130+
{ name = 'treesitter', keyword_length = 5, max_item_count = 3 },
131+
{ name = 'calc' },
132+
{ name = 'latex_symbols' },
133+
{ name = 'emoji' },
134+
},
135+
view = {
136+
entries = 'native',
137+
},
138+
window = {
139+
documentation = {
140+
border = require('misc.style').border,
141+
},
142+
},
143+
}
144+
145+
-- for friendly snippets
146+
require('luasnip.loaders.from_vscode').lazy_load()
147+
-- for custom snippets
148+
require('luasnip.loaders.from_vscode').lazy_load { paths = { vim.fn.stdpath 'config' .. '/snips' } }
149+
-- link quarto and rmarkdown to markdown snippets
150+
luasnip.filetype_extend('quarto', { 'markdown' })
151+
luasnip.filetype_extend('rmarkdown', { 'markdown' })
152+
end,
153+
},
154+
155+
{ -- gh copilot
156+
'zbirenbaum/copilot.lua',
157+
enabled = false,
158+
config = function()
159+
require('copilot').setup {
160+
suggestion = {
161+
enabled = true,
162+
auto_trigger = true,
163+
debounce = 75,
164+
keymap = {
165+
accept = '<c-a>',
166+
accept_word = false,
167+
accept_line = false,
168+
next = '<M-]>',
169+
prev = '<M-[>',
170+
dismiss = '<C-]>',
171+
},
172+
},
173+
panel = { enabled = false },
174+
}
175+
end,
176+
},
177+
}

lua/plugins/editing.lua

+53-8
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,6 @@ return {
1111
opts = {},
1212
},
1313

14-
{
15-
'windwp/nvim-autopairs',
16-
config = function()
17-
require('nvim-autopairs').setup {}
18-
require('nvim-autopairs').remove_rule '`'
19-
end,
20-
},
21-
2214
-- commenting with e.g. `gcc` or `gcip`
2315
-- respects TS, so it works in quarto documents
2416
{
@@ -28,6 +20,59 @@ return {
2820
config = true,
2921
},
3022

23+
{ -- Autoformat
24+
'stevearc/conform.nvim',
25+
enabled = true,
26+
config = function()
27+
require('conform').setup {
28+
notify_on_error = false,
29+
format_on_save = {
30+
timeout_ms = 500,
31+
lsp_fallback = true,
32+
},
33+
formatters_by_ft = {
34+
lua = { 'mystylua' },
35+
python = { 'isort', 'black' },
36+
},
37+
formatters = {
38+
mystylua = {
39+
command = 'stylua',
40+
args = { '--indent-type', 'Spaces', '--indent-width', '2', '-' },
41+
},
42+
},
43+
}
44+
-- Customize the "injected" formatter
45+
require('conform').formatters.injected = {
46+
-- Set the options field
47+
options = {
48+
-- Set to true to ignore errors
49+
ignore_errors = false,
50+
-- Map of treesitter language to file extension
51+
-- A temporary file name with this extension will be generated during formatting
52+
-- because some formatters care about the filename.
53+
lang_to_ext = {
54+
bash = 'sh',
55+
c_sharp = 'cs',
56+
elixir = 'exs',
57+
javascript = 'js',
58+
julia = 'jl',
59+
latex = 'tex',
60+
markdown = 'md',
61+
python = 'py',
62+
ruby = 'rb',
63+
rust = 'rs',
64+
teal = 'tl',
65+
r = 'r',
66+
typescript = 'ts',
67+
},
68+
-- Map of treesitter language to formatters to use
69+
-- (defaults to the value from formatters_by_ft)
70+
lang_to_formatters = {},
71+
},
72+
}
73+
end,
74+
},
75+
3176
{ -- generate docstrings
3277
'danymat/neogen',
3378
cmd = { 'Neogen' },

0 commit comments

Comments
 (0)