Skip to content

Commit b700e69

Browse files
committed
refactor!: structure
1 parent 6dd2556 commit b700e69

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+610
-344
lines changed

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
# nvimconf
22

33
_Configuration for my Neovim_
4+
5+
## Acknowledgements
6+
7+
- [bekaboo/nvim](https://github.com/Bekaboo/nvim) for many plugin and LSP configurations, tree-wide structure, etc
8+
- [idm1try/dotfiles](https://github.com/idm1try/dotfiles) for the oxocarbon override above catppuccin/nvim

after/ftplugin/c/lsp.lua

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
require('utils.lsp').start({
2+
cmd = { 'clangd' },
3+
root_patterns = {
4+
'.clangd',
5+
'.clang-tidy',
6+
'.clang-format',
7+
'compile_commands.json',
8+
'compile_flags.txt',
9+
'configure.ac',
10+
},
11+
})

after/ftplugin/c/options.lua

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
vim.bo.commentstring = '// %s'

after/ftplugin/cpp/lsp.lua

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../c/lsp.lua

after/ftplugin/diff.lua

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
vim.opt_local.spell = false

after/ftplugin/git.lua

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
vim.opt_local.spell = false
2+
vim.opt_local.foldmethod = 'syntax'

after/ftplugin/help.lua

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
man.lua

after/ftplugin/html/spell.lua

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../text/spell.lua

after/ftplugin/lisp.lua

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
vim.bo.commentstring = ';; %s'

after/ftplugin/lua/lsp.lua

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
local lsp = require('utils.lsp')
2+
3+
-- Use efm to attach stylua formatter as a language server
4+
local stylua_root_patterns = { 'stylua.toml', '.stylua.toml' }
5+
local efm = vim.fn.executable('stylua') == 1
6+
and lsp.start({
7+
cmd = { 'efm-langserver' },
8+
name = 'efm-formatter-stylua',
9+
root_patterns = stylua_root_patterns,
10+
init_options = {
11+
documentFormatting = true,
12+
documentRangeFormatting = true,
13+
},
14+
settings = {
15+
languages = {
16+
lua = {
17+
{
18+
formatStdin = true,
19+
formatCanRange = true,
20+
formatCommand = 'stylua ${--indent-width:tabSize} ${--range-start:charStart} ${--range-end:charEnd} --color Never -',
21+
rootMarkers = stylua_root_patterns,
22+
},
23+
},
24+
},
25+
},
26+
})
27+
28+
-- Luanch lua-language-server, disable its formatting capabilities
29+
-- if efm launched successfully
30+
lsp.start({
31+
cmd = { 'lua-language-server' },
32+
root_patterns = { '.luarc.json', '.luarc.jsonc' },
33+
settings = {
34+
Lua = {
35+
hint = { enable = true },
36+
format = { enable = not efm },
37+
},
38+
},
39+
})

after/ftplugin/man.lua

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
if vim.bo.ma then
2+
return
3+
end
4+
5+
vim.bo.buflisted = false
6+
vim.opt_local.list = false
7+
vim.opt_local.number = false
8+
vim.opt_local.relativenumber = false
9+
vim.opt_local.scrolloff = 999
10+
vim.opt_local.signcolumn = 'no'
11+
vim.opt_local.spell = false
12+
vim.opt_local.statuscolumn = ''
13+
14+
vim.keymap.set({ 'n', 'x' }, 'q', 'ZQ', { buffer = true, nowait = true })
15+
vim.keymap.set({ 'n', 'x' }, 'd', '<C-d>', { buffer = true, nowait = true })
16+
vim.keymap.set({ 'n', 'x' }, 'u', '<C-u>', { buffer = true, nowait = true })

after/ftplugin/markdown/lsp.lua

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
require('utils.lsp').start({
2+
cmd = { 'marksman' },
3+
root_patterns = { '.marksman.toml' },
4+
})

after/ftplugin/markdown/spell.lua

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../text/spell.lua

after/ftplugin/nix/lsp.lua

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
require('utils.lsp').start({
2+
cmd = { 'nixd' },
3+
root_patterns = {
4+
'flake.nix',
5+
},
6+
})

after/ftplugin/sh/lsp.lua

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
local lsp = require('utils.lsp')
2+
3+
local efm = vim.fn.executable('shfmt') == 1
4+
and lsp.start({
5+
cmd = { 'efm-langserver' },
6+
name = 'efm-formatter-shfmt',
7+
init_options = { documentFormatting = true },
8+
settings = {
9+
languages = {
10+
sh = {
11+
{
12+
formatCommand = 'shfmt --filename ${INPUT} -',
13+
formatStdin = true,
14+
},
15+
},
16+
},
17+
},
18+
})
19+
20+
lsp.start({
21+
cmd = { 'bash-language-server', 'start' },
22+
on_attach = efm and function(client)
23+
client.server_capabilities.documentFormattingProvider = false
24+
end or nil,
25+
settings = {
26+
bashIde = {
27+
globPattern = vim.env.GLOB_PATTERN or '*@(.sh|.inc|.bash|.command)',
28+
},
29+
},
30+
})

after/ftplugin/text/options.lua

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
vim.bo.cindent = false
2+
vim.bo.smartindent = false
3+
vim.bo.commentstring = '# %s'
4+
5+
vim.opt_local.wrap = true
6+
vim.opt_local.linebreak = true

after/ftplugin/text/spell.lua

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-- Spell check
2+
vim.opt_local.spell = true
3+
vim.opt_local.spellcapcheck = ''
4+
vim.opt_local.spelllang = 'en,cjk'
5+
vim.opt_local.spelloptions = 'camel'
6+
vim.opt_local.spellsuggest = 'best,9'

after/ftplugin/vim/lsp.lua

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
require('utils.lsp').start({
2+
cmd = { 'vim-language-server', '--stdio' },
3+
init_options = {
4+
isNeovim = true,
5+
iskeyword = vim.bo.iskeyword,
6+
vimruntime = '',
7+
runtimepath = '',
8+
diagnostic = { enable = true },
9+
indexes = {
10+
count = 4,
11+
gap = 100,
12+
runtimepath = true,
13+
projectRootPatterns = {
14+
'.git/',
15+
'nvim/',
16+
'plugin/',
17+
'runtime/',
18+
'autoload/',
19+
},
20+
},
21+
suggest = {
22+
fromVimruntime = true,
23+
fromRuntimepath = true,
24+
},
25+
},
26+
})

after/ftplugin/vim/options.lua

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
vim.bo.commentstring = '" %s'
2+
3+
vim.bo.buflisted = false
4+
vim.opt_local.rnu = false
5+
vim.opt_local.signcolumn = 'no'
6+
vim.opt_local.statuscolumn = ''

after/ftplugin/xml/spell.lua

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../text/spell.lua

indent/markdown.vim

+133
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
if exists('b:did_indent')
2+
finish
3+
endif
4+
let b:did_indent = 1
5+
6+
setlocal autoindent
7+
setlocal indentexpr=GetMarkdownIndent()
8+
setlocal indentkeys=!^F,o,O,0&,<Space>
9+
10+
function! s:in_mathzone(...) abort
11+
return !exists('g:loaded_vimtex') || !g:loaded_vimtex
12+
\ || call('vimtex#syntax#in_mathzone', a:000)
13+
endfunction
14+
15+
function! s:in_normalzone(...) abort
16+
return !exists('g:loaded_vimtex') || !g:loaded_vimtex
17+
\ || !call('vimtex#syntax#in_mathzone', a:000)
18+
endfunction
19+
20+
function! s:in_codeblock(...) abort
21+
let l:lnum = get(a:000, 0, v:lnum)
22+
let l:bufnr = get(a:000, 1, bufnr('%'))
23+
return luaeval(printf('require("utils.ft.markdown").in_codeblock(%d, %d)'
24+
\ , l:lnum, l:bufnr))
25+
endfunction
26+
27+
function! s:ts_active() abort
28+
return luaeval('require("utils.treesitter").is_active()')
29+
endfunction
30+
31+
" Find the first previous non-blank line that matches the given pattern if
32+
" trimmed, stops on the first line that has a larger indent than its next
33+
" non-blank line
34+
" Returns the line number, the index of the match, and the substring that
35+
" matches the pattern
36+
function! s:trimmed_prevnonblank_matches(lnum, pattern) abort
37+
let l:lnum = prevnonblank(a:lnum - 1)
38+
let l:indent = indent(l:lnum)
39+
while l:lnum >= 1
40+
let l:line = trim(getline(l:lnum))
41+
let l:match_idx = match(l:line, a:pattern)
42+
let l:match = matchstr(l:line, a:pattern)
43+
if l:match_idx >= 0
44+
return [l:lnum, l:match_idx, l:match]
45+
endif
46+
let l:lnum = prevnonblank(l:lnum - 1)
47+
let l:new_indent = indent(l:lnum)
48+
if l:new_indent <= l:indent
49+
let l:indent = l:new_indent
50+
else
51+
break
52+
endif
53+
endwhile
54+
return [0, -1, '']
55+
endfunction
56+
57+
function! GetMarkdownIndent() abort
58+
let l:line = getline(v:lnum)
59+
let l:prev_lnum = prevnonblank(v:lnum - 1)
60+
let l:prev_line = getline(l:prev_lnum)
61+
let l:sw = shiftwidth()
62+
let l:default = indent(v:lnum)
63+
if l:prev_lnum == 0
64+
return l:default
65+
endif
66+
67+
if s:ts_active() && s:in_codeblock()
68+
return nvim_treesitter#indent()
69+
endif
70+
71+
if s:in_mathzone()
72+
" Align to the first previous line that has
73+
" '='/'>'/'<'/'\le'/'\ge'/'\sim'/'\approx'/'\gg'/'\ll' or variants with
74+
" '&' at the beginning if the current line starts with one of these
75+
" patterns
76+
let align_patterns =
77+
\ '^\s*\(\(&\s*\)\?\(=\|>\|<\|\\\(le\|ge\|sim\|approx\|gg\|ll\)\>\)\|&\)'
78+
if l:line =~# align_patterns
79+
let [l:prev_eq_lnum, l:eq_pos, l:_] =
80+
\ s:trimmed_prevnonblank_matches(v:lnum, align_patterns)
81+
if l:prev_eq_lnum > 0 && s:in_mathzone(l:prev_eq_lnum, 1)
82+
return indent(l:prev_eq_lnum) + l:eq_pos
83+
endif
84+
endif
85+
return l:default
86+
endif
87+
88+
if s:in_normalzone()
89+
" Reindent unordered list bullet points
90+
if l:line =~# '^\s*[-*+]\s\+$'
91+
return l:default / l:sw * l:sw
92+
endif
93+
" Reindent ordered list items
94+
let l:order = str2nr(matchstr(l:line, '\(^\s*\)\@<=\d\+\(\.\ \)\@='))
95+
if l:order > 0
96+
let [l:prev_heading_lnum, l:_, l:_] =
97+
\ s:trimmed_prevnonblank_matches(v:lnum, '^#')
98+
let [l:prev_item_lnum, l:_, l:prev_item_order] =
99+
\ s:trimmed_prevnonblank_matches(v:lnum, '^\d\+\.\@=')
100+
if s:in_normalzone(l:prev_item_lnum, 1) &&
101+
\ l:prev_heading_lnum < l:prev_item_lnum
102+
return str2nr(l:order) > l:prev_item_order
103+
\ ? indent(l:prev_item_lnum)
104+
\ : indent(l:prev_item_lnum) + l:sw
105+
endif
106+
endif
107+
" Only align multi-line list items if adjacent previous line is non-empty
108+
" ---------------------------------------------
109+
" 1234. aaa-bbb
110+
" ccc <- should align with the 'aaa'
111+
" ---------------------------------------------
112+
" 5678. ddd
113+
"
114+
" eee <- should not align with 'ddd'
115+
" ---------------------------------------------
116+
if l:line =~# '^\s*$' && l:prev_lnum == v:lnum - 1 &&
117+
\ s:in_normalzone(l:prev_lnum, 1)
118+
" Align unordered list multi-line items
119+
let l:prev_line_char_pos = match(l:prev_line, '\(^\s*[-*+]\s\+\)\@<=\S')
120+
if l:prev_line_char_pos >= 0
121+
return l:prev_line_char_pos
122+
endif
123+
" Align ordered list multi-line items
124+
let l:ordered_list_extra_indent =
125+
\ match(l:prev_line, '\(^\s*\d\+\.\s*\)\@<=\S')
126+
if l:ordered_list_extra_indent >= 0
127+
return l:ordered_list_extra_indent
128+
endif
129+
endif
130+
endif
131+
132+
return l:default
133+
endfunction

init.lua

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
vim.loader.enable()
22

3-
vim.g.has_ui = #vim.api.nvim_list_uis() > 0
4-
vim.g.has_gui = vim.g.has_ui and (vim.env.DISPLAY ~= nil or vim.env.WAYLAND_DISPLAY ~= nil)
5-
63
_G.settings = {
74
ui = {
85
border = 'solid',
@@ -136,4 +133,11 @@ _G.icons = {
136133
},
137134
}
138135

139-
require('v')
136+
vim.g.has_ui = #vim.api.nvim_list_uis() > 0
137+
vim.g.has_gui = vim.g.has_ui and (vim.env.DISPLAY ~= nil or vim.env.WAYLAND_DISPLAY ~= nil)
138+
139+
require('core.options')
140+
require('core.keymaps')
141+
require('core.autocmds')
142+
require('core.commands')
143+
require('core.packages')
File renamed without changes.
File renamed without changes.

lua/v/packages/configs/cmp.lua lua/configs/cmp.lua

-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ cmp.setup({
116116
fields = { 'kind', 'abbr', 'menu' },
117117
format = function(entry, cmp_item)
118118
cmp_item.kind = entry.source.name == 'calc' and icons.ui.Calculator or icons.kinds[cmp_item.kind] or ' '
119-
120119
return cmp_item
121120
end,
122121
},
File renamed without changes.
File renamed without changes.

lua/v/packages/configs/dropbar.lua lua/configs/dropbar.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
local utils = require('v.utils')
1+
local utils = require('utils')
22

33
require('dropbar').setup({
44
icons = {

0 commit comments

Comments
 (0)