- commit
- 97d8012
- parent
- 30639ff
- author
- Eric Bower
- date
- 2025-02-17 14:04:48 -0500 EST
refactor: simplify nvim config
6 files changed,
+232,
-256
+0,
-1
1@@ -1 +0,0 @@
2-vim.treesitter.start()
+0,
-3
1@@ -4,7 +4,4 @@ set rtp+=/usr/local/opt/fzf
2 let $FZF_DEFAULT_COMMAND = 'rg --files --hidden --glob "!.git/"'
3 let $NVIM_TUI_ENABLE_TRUE_COLOR=1
4
5-" source our 'init.lua'
6-" https://github.com/nanotee/nvim-lua-guide#sourcing-a-lua-file-vs-calling-require
7-" luafile $XDG_CONFIG_HOME/nvim/lua/init.lua
8 lua require'init'
+0,
-48
1@@ -1,48 +0,0 @@
2-local api = vim.api
3-
4--- Taken from https://github.com/norcalli/nvim_utils
5-local function nvim_create_augroups(definitions)
6- for group_name, definition in pairs(definitions) do
7- api.nvim_command('augroup '..group_name)
8- api.nvim_command('autocmd!')
9- for _, def in ipairs(definition) do
10- local command = table.concat(vim.tbl_flatten{'autocmd', def}, ' ')
11- api.nvim_command(command)
12- end
13- api.nvim_command('augroup END')
14- end
15-end
16-
17-local autocmds = {
18- language_spacing = {
19- {
20- 'BufRead,BufNewFile,BufEnter',
21- 'make',
22- 'setlocal tabstop=4 shiftwidth=4 softtabstop=4',
23- },
24- },
25- golang = {
26- {
27- 'BufRead,BufNewFile,BufEnter',
28- '*.go',
29- 'setlocal noexpandtab copyindent preserveindent softtabstop=0 shiftwidth=4 tabstop=4',
30- },
31- },
32- typescript = {
33- { 'BufNewFile,BufRead', '*.ts,*.mts', 'setlocal filetype=typescript' },
34- },
35- markdown = {
36- { 'BufNewFile,BufRead', '*.md,*.mdx', 'setlocal filetype=markdown' },
37- },
38- quickfix = {
39- { 'FileType', 'qf', 'setlocal wrap' }
40- },
41- wrapmdfiles = {
42- { 'FileType', 'markdown', 'setlocal wrap tw=79 formatoptions+=t tabstop=2 shiftwidth=2 softtabstop=2' },
43- },
44- wraptextfiles = {
45- { 'FileType', 'text', 'setlocal wrap tw=79 formatoptions+=t tabstop=2 shiftwidth=2 softtabstop=2' },
46- },
47-}
48-
49-nvim_create_augroups(autocmds)
+72,
-26
1@@ -1,30 +1,29 @@
2 local o = vim.o
3-o.termguicolors = true -- enable 24bit colors
4-o.background = 'dark'
5-o.encoding = 'utf-8'
6-o.fileencoding = 'utf-8'
7-o.number = true -- show absolute line no. at the cursor pos
8-o.tabstop = 2 -- Tab indentation levels every two columns
9-o.shiftwidth = 2 -- Indent/outdent by two columns
10-o.softtabstop = 2 -- Tab indentation when mixing tabs & spaces
11-o.expandtab = true -- Convert all tabs that are typed into spaces
12-o.colorcolumn = '72' -- Vertical column at 80 characters
13-o.laststatus = 2 -- always show status line
14-o.wrap = false -- wrap long lines
15-o.cursorline = false -- Show a line where the current cursor is
16-o.autoread = true -- auto read file if changed outside of vim
17-o.updatetime = 250 -- decrease update time
18-o.cursorline = false -- disable highlighting the current line
19-o.backspace = 'indent,eol,start'
20-o.completeopt = 'menuone,noselect'
21-o.signcolumn = 'yes'
22-o.shell = '/bin/bash'
23+o.termguicolors = true
24+o.background = 'dark'
25+o.encoding = 'utf-8'
26+o.fileencoding = 'utf-8'
27+o.number = true
28+o.tabstop = 2
29+o.shiftwidth = 2
30+o.softtabstop = 2
31+o.expandtab = true
32+o.colorcolumn = '80'
33+o.laststatus = 2
34+o.wrap = false
35+o.cursorline = false
36+o.autoread = true
37+o.updatetime = 250
38+o.cursorline = false
39+o.backspace = 'indent,eol,start'
40+o.completeopt = 'menuone,noselect'
41+o.signcolumn = 'yes'
42+o.shell = '/bin/bash'
43+o.list = true
44
45 local g = vim.g
46-g.mapleader = ','
47-g.maplocalleader = ','
48-g.loaded_netrw = 1 -- disable netrw (nvim-tree)
49-g.loaded_netrwPlugin = 1
50+g.mapleader = ','
51+g.maplocalleader = ','
52
53 local opts = { noremap=true, silent=true }
54 local set_keymap = vim.keymap.set
55@@ -32,7 +31,54 @@ set_keymap('n', '<leader>b', '<C-O>', opts)
56 set_keymap('n', 'Q', '<nop>', opts)
57 set_keymap('n', '<leader>w', ':!make fmt<CR>', opts)
58 set_keymap('n', '<Esc>', [[<C-\><C-n>]], opts)
59--- vim.keymap.del('n', '<C-\>')
60+
61+local api = vim.api
62+
63+-- Taken from https://github.com/norcalli/nvim_utils
64+local function nvim_create_augroups(definitions)
65+ for group_name, definition in pairs(definitions) do
66+ api.nvim_command('augroup '..group_name)
67+ api.nvim_command('autocmd!')
68+ for _, def in ipairs(definition) do
69+ local command = table.concat(vim.tbl_flatten{'autocmd', def}, ' ')
70+ api.nvim_command(command)
71+ end
72+ api.nvim_command('augroup END')
73+ end
74+end
75+
76+local autocmds = {
77+ language_spacing = {
78+ {
79+ 'BufRead,BufNewFile,BufEnter',
80+ 'make',
81+ 'setlocal tabstop=4 shiftwidth=4 softtabstop=4',
82+ },
83+ },
84+ golang = {
85+ {
86+ 'BufRead,BufNewFile,BufEnter',
87+ '*.go',
88+ 'setlocal noexpandtab copyindent preserveindent softtabstop=0 shiftwidth=4 tabstop=4',
89+ },
90+ },
91+ typescript = {
92+ { 'BufNewFile,BufRead', '*.ts,*.mts', 'setlocal filetype=typescript' },
93+ },
94+ markdown = {
95+ { 'BufNewFile,BufRead', '*.md,*.mdx', 'setlocal filetype=markdown' },
96+ },
97+ quickfix = {
98+ { 'FileType', 'qf', 'setlocal wrap' }
99+ },
100+ wrapmdfiles = {
101+ { 'FileType', 'markdown', 'setlocal wrap tw=79 formatoptions+=t tabstop=2 shiftwidth=2 softtabstop=2' },
102+ },
103+ wraptextfiles = {
104+ { 'FileType', 'text', 'setlocal wrap tw=79 formatoptions+=t tabstop=2 shiftwidth=2 softtabstop=2' },
105+ },
106+}
107+
108+nvim_create_augroups(autocmds)
109
110 require 'plugins'
111-require 'autocmd'
+0,
-166
1@@ -1,166 +0,0 @@
2-function setup_treesitter()
3- require'nvim-treesitter.configs'.setup {
4- ensure_installed = {
5- "bash",
6- "c",
7- "cmake",
8- "dockerfile",
9- "fish",
10- "git_config",
11- "git_rebase",
12- "gitattributes",
13- "gitcommit",
14- "gitignore",
15- "glimmer",
16- "go",
17- "gomod",
18- "gosum",
19- "html",
20- "javascript",
21- "jq",
22- "json",
23- "json5",
24- "lua",
25- "make",
26- "markdown",
27- "nix",
28- "python",
29- "query",
30- "r",
31- "ruby",
32- "rust",
33- "sql",
34- "terraform",
35- "toml",
36- "tsx",
37- "typescript",
38- "vim",
39- "vimdoc",
40- "yaml",
41- "zig",
42- },
43- highlight = {
44- enable = true,
45- },
46- indent = {
47- enable = true
48- }
49- }
50-end
51-
52-function setup_comp()
53- local cmp = require'cmp'
54- cmp.setup({
55- snippet = {
56- expand = function(args)
57- vim.fn["vsnip#anonymous"](args.body)
58- end,
59- },
60- mapping = {
61- ['<C-p>'] = cmp.mapping.select_prev_item(),
62- ['<C-n>'] = cmp.mapping.select_next_item(),
63- ['<Tab>'] = function(fallback)
64- if cmp.visible() then
65- cmp.select_next_item()
66- else
67- fallback()
68- end
69- end,
70- ['<S-Tab>'] = function(fallback)
71- if cmp.visible() then
72- cmp.select_prev_item()
73- else
74- fallback()
75- end
76- end,
77- ['<C-Space>'] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }),
78- ['<CR>'] = cmp.mapping.confirm({ select = true }),
79- },
80- sources = {
81- { name = 'nvim_lsp' },
82- },
83- performance = {
84- -- It is recommended to increase the timeout duration due to
85- -- the typically slower response speed of LLMs compared to
86- -- other completion sources. This is not needed when you only
87- -- need manual completion.
88- fetching_timeout = 2000,
89- },
90- })
91-end
92-
93-function setup_lsp()
94- local opts = { noremap=true, silent=true }
95- vim.keymap.set('n', '<leader>e', vim.diagnostic.open_float, opts)
96- vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts)
97- vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts)
98- vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist, opts)
99- -- Use an on_attach function to only map the following keysk
100- -- after the language server attaches to the current buffer
101- local on_attach = function(client, bufnr)
102- local bufopts = { noremap=true, silent=true, buffer=bufnr }
103-
104- --Enable completion triggered by <c-x><c-o>
105- vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
106-
107- -- Mappings.
108-
109- -- See `:help vim.lsp.*` for documentation on any of the below functions
110- vim.keymap.set('n', '<leader>d', vim.lsp.buf.definition, bufopts)
111- vim.keymap.set('n', '<leader>D', vim.lsp.buf.type_definition, bufopts)
112- vim.keymap.set('n', '<leader>h', vim.lsp.buf.hover, bufopts)
113- vim.keymap.set('n', '<leader>r', vim.lsp.buf.references, bufopts)
114- vim.keymap.set('n', '<leader>k', vim.lsp.buf.signature_help, bufopts)
115- vim.keymap.set('n', '<leader>i', vim.lsp.buf.implementation, bufopts)
116- end
117-
118- local nvim_lsp = require('lspconfig')
119- local capabilities = vim.lsp.protocol.make_client_capabilities()
120- capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities)
121- capabilities.textDocument.foldingRange = {
122- dynamicRegistration = false,
123- lineFoldingOnly = true
124- }
125-
126- function handler(server_name)
127- local opts = {
128- capabilities = capabilities,
129- on_attach = on_attach,
130- }
131- if server_name == "denols" then
132- opts.root_dir = nvim_lsp.util.root_pattern("deno.json", "deno.jsonc")
133- elseif server_name == "ts_ls" then
134- opts.root_dir = nvim_lsp.util.root_pattern("package.json")
135- -- https://github.com/neovim/nvim-lspconfig/issues/2507#issuecomment-1471438640
136- opts.single_file_support = false
137- end
138- nvim_lsp[server_name].setup(opts)
139- end
140-
141- -- npm i -g typescript typescript-language-server
142- handler("ts_ls")
143- handler("denols")
144- handler("gopls")
145- handler("zls")
146- handler("pyright")
147- -- npm i -g vscode-langservers-extracted
148- handler("cssls")
149- handler("html")
150- handler("jsonls")
151- -- setup_folding()
152-end
153-
154-function setup_tmux_nav()
155- local nvim_tmux_nav = require('nvim-tmux-navigation')
156-
157- nvim_tmux_nav.setup {
158- disable_when_zoomed = true -- defaults to false
159- }
160-
161- vim.keymap.set('n', "<C-h>", nvim_tmux_nav.NvimTmuxNavigateLeft)
162- vim.keymap.set('n', "<C-j>", nvim_tmux_nav.NvimTmuxNavigateDown)
163- vim.keymap.set('n', "<C-k>", nvim_tmux_nav.NvimTmuxNavigateUp)
164- vim.keymap.set('n', "<C-l>", nvim_tmux_nav.NvimTmuxNavigateRight)
165- vim.keymap.set('n', "<C-\\>", nvim_tmux_nav.NvimTmuxNavigateLastActive)
166- vim.keymap.set('n', "<C-Space>", nvim_tmux_nav.NvimTmuxNavigateNext)
167-end
+160,
-12
1@@ -14,9 +14,6 @@ if not (vim.uv or vim.loop).fs_stat(lazypath) then
2 end
3 vim.opt.rtp:prepend(lazypath)
4
5--- require functions used to configure plugins
6-require 'plugin_config'
7-
8 require("lazy").setup({
9 rocks = {
10 enabled = false,
11@@ -41,12 +38,6 @@ require("lazy").setup({
12 config = setup_comp,
13 },
14 "hrsh7th/cmp-nvim-lsp",
15- -- {
16- -- 'lewis6991/gitsigns.nvim',
17- -- config = function()
18- -- require('gitsigns').setup({})
19- -- end,
20- -- },
21 {
22 'lukas-reineke/indent-blankline.nvim',
23 config = function()
24@@ -83,8 +74,6 @@ require("lazy").setup({
25 },
26 {
27 "ibhagwan/fzf-lua",
28- -- optional for icon support
29- -- dependencies = { "nvim-tree/nvim-web-devicons" },
30 config = function()
31 local fzf = require('fzf-lua')
32 local fzfFiles = function()
33@@ -103,7 +92,9 @@ require("lazy").setup({
34 {
35 "nvim-treesitter/nvim-treesitter-context",
36 config = function()
37- require'treesitter-context'.setup({})
38+ require'treesitter-context'.setup({
39+ max_lines = 1,
40+ })
41 end,
42 },
43 {
44@@ -122,3 +113,160 @@ require("lazy").setup({
45 'rhysd/git-messenger.vim'
46 },
47 })
48+
49+function setup_treesitter()
50+ require'nvim-treesitter.configs'.setup {
51+ ensure_installed = {
52+ "bash",
53+ "c",
54+ "cmake",
55+ "dockerfile",
56+ "fish",
57+ "git_config",
58+ "git_rebase",
59+ "gitattributes",
60+ "gitcommit",
61+ "gitignore",
62+ "glimmer",
63+ "go",
64+ "gomod",
65+ "gosum",
66+ "html",
67+ "javascript",
68+ "jq",
69+ "json",
70+ "json5",
71+ "lua",
72+ "make",
73+ "markdown",
74+ "nix",
75+ "python",
76+ "query",
77+ "r",
78+ "ruby",
79+ "rust",
80+ "sql",
81+ "terraform",
82+ "toml",
83+ "tsx",
84+ "typescript",
85+ "vim",
86+ "vimdoc",
87+ "yaml",
88+ "zig",
89+ },
90+ highlight = {
91+ enable = true,
92+ },
93+ indent = {
94+ enable = true
95+ }
96+ }
97+end
98+
99+function setup_comp()
100+ local cmp = require'cmp'
101+ cmp.setup({
102+ snippet = {
103+ expand = function(args)
104+ vim.fn["vsnip#anonymous"](args.body)
105+ end,
106+ },
107+ mapping = {
108+ ['<C-p>'] = cmp.mapping.select_prev_item(),
109+ ['<C-n>'] = cmp.mapping.select_next_item(),
110+ ['<Tab>'] = function(fallback)
111+ if cmp.visible() then
112+ cmp.select_next_item()
113+ else
114+ fallback()
115+ end
116+ end,
117+ ['<S-Tab>'] = function(fallback)
118+ if cmp.visible() then
119+ cmp.select_prev_item()
120+ else
121+ fallback()
122+ end
123+ end,
124+ ['<C-Space>'] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }),
125+ ['<CR>'] = cmp.mapping.confirm({ select = true }),
126+ },
127+ sources = {
128+ { name = 'nvim_lsp' },
129+ },
130+ })
131+end
132+
133+function setup_lsp()
134+ local opts = { noremap=true, silent=true }
135+ vim.keymap.set('n', '<leader>e', vim.diagnostic.open_float, opts)
136+ vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist, opts)
137+ -- Use an on_attach function to only map the following keys
138+ -- after the language server attaches to the current buffer
139+ local on_attach = function(client, bufnr)
140+ local bufopts = { noremap=true, silent=true, buffer=bufnr }
141+
142+ --Enable completion triggered by <c-x><c-o>
143+ vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
144+
145+ -- Mappings.
146+
147+ -- See `:help vim.lsp.*` for documentation on any of the below functions
148+ vim.keymap.set('n', '<leader>d', vim.lsp.buf.definition, bufopts)
149+ vim.keymap.set('n', '<leader>D', vim.lsp.buf.type_definition, bufopts)
150+ vim.keymap.set('n', '<leader>h', vim.lsp.buf.hover, bufopts)
151+ vim.keymap.set('n', '<leader>r', vim.lsp.buf.references, bufopts)
152+ vim.keymap.set('n', '<leader>k', vim.lsp.buf.signature_help, bufopts)
153+ vim.keymap.set('n', '<leader>i', vim.lsp.buf.implementation, bufopts)
154+ end
155+
156+ local nvim_lsp = require('lspconfig')
157+ local capabilities = vim.lsp.protocol.make_client_capabilities()
158+ capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities)
159+ capabilities.textDocument.foldingRange = {
160+ dynamicRegistration = false,
161+ lineFoldingOnly = true
162+ }
163+
164+ function handler(server_name)
165+ local opts = {
166+ capabilities = capabilities,
167+ on_attach = on_attach,
168+ }
169+ if server_name == "denols" then
170+ opts.root_dir = nvim_lsp.util.root_pattern("deno.json", "deno.jsonc")
171+ elseif server_name == "ts_ls" then
172+ opts.root_dir = nvim_lsp.util.root_pattern("package.json")
173+ -- https://github.com/neovim/nvim-lspconfig/issues/2507#issuecomment-1471438640
174+ opts.single_file_support = false
175+ end
176+ nvim_lsp[server_name].setup(opts)
177+ end
178+
179+ -- npm i -g vscode-langservers-extracted
180+ handler("cssls")
181+ handler("denols")
182+ handler("gopls")
183+ handler("html")
184+ handler("jsonls")
185+ handler("pyright")
186+ -- npm i -g typescript typescript-language-server
187+ handler("ts_ls")
188+ handler("zls")
189+end
190+
191+function setup_tmux_nav()
192+ local nvim_tmux_nav = require('nvim-tmux-navigation')
193+
194+ nvim_tmux_nav.setup {
195+ disable_when_zoomed = true -- defaults to false
196+ }
197+
198+ vim.keymap.set('n', "<C-h>", nvim_tmux_nav.NvimTmuxNavigateLeft)
199+ vim.keymap.set('n', "<C-j>", nvim_tmux_nav.NvimTmuxNavigateDown)
200+ vim.keymap.set('n', "<C-k>", nvim_tmux_nav.NvimTmuxNavigateUp)
201+ vim.keymap.set('n', "<C-l>", nvim_tmux_nav.NvimTmuxNavigateRight)
202+ vim.keymap.set('n', "<C-\\>", nvim_tmux_nav.NvimTmuxNavigateLastActive)
203+ vim.keymap.set('n', "<C-Space>", nvim_tmux_nav.NvimTmuxNavigateNext)
204+end