summaryrefslogtreecommitdiff
path: root/artix/home/.config/nvim/init.lua
blob: 4474fd7113b6c256a2c0eb855b08015756597424 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
vim.g.mapleader = " "

vim.o.number = true
vim.o.relativenumber = true

vim.o.undofile = true
vim.o.ignorecase = true

vim.o.expandtab = false
vim.o.shiftwidth = 8
vim.o.tabstop = 8
vim.o.softtabstop = 8
vim.o.smartindent = true
vim.o.autoindent = true

vim.o.termguicolors = true
vim.o.signcolumn = "yes"
vim.o.winborder = 'single'
vim.o.showmode = true
vim.o.guicursor = ""

vim.o.swapfile = false

vim.o.list = true
vim.o.cursorline = true

-- •⏎.·○◦
vim.o.listchars = "tab:🡪 ,trail:·,eol:⏎,space:·,multispace:·,lead:·,leadmultispace:·"

vim.o.completeopt = "fuzzy,menuone,noselect"
vim.diagnostic.config({ virtual_text = true })

-- FRENCH SPELLS

local spell_path = vim.fn.stdpath("data") .. "/site/spell"
if not (vim.uv.fs_stat(spell_path .. "/fr.utf-8.spl") and vim.uv.fs_stat(spell_path .. "/fr.utf-8.sug")) then
	print("Installing french spells")
	-- Other mirrors can be found on https://www.vim.org/mirrors.php
	local mirror = "https://vim.mirror.garr.it/pub/vim/" .. "runtime/spell/"
	local files = { "fr.utf-8.spl", "fr.utf-8.sug" }
	vim.fn.mkdir(spell_path, "p")
	for _, file in ipairs(files) do
		vim.fn.system(string.format("curl -L %s%s -o %s/%s", mirror, file, spell_path, file))
	end
end

vim.cmd [[set spelllang=en,fr]]
vim.cmd [[set spell]]

-- PLUGINS

vim.pack.add({
	{ src = "https://github.com/neovim/nvim-lspconfig" },
	{ src = "https://github.com/ibhagwan/fzf-lua" },
	{ src = "https://github.com/nvim-tree/nvim-web-devicons" },
	{ src = "https://github.com/mfussenegger/nvim-jdtls" },
	{ src = "https://github.com/mfussenegger/nvim-dap" },
	{ src = "https://github.com/nvim-treesitter/nvim-treesitter" },
	{ src = "https://github.com/folke/tokyonight.nvim" },
	{ src = "https://github.com/lewis6991/gitsigns.nvim" },
	{ src = "https://github.com/windwp/nvim-autopairs" },
	{ src = "https://github.com/saghen/blink.cmp" },
	{ src = "https://github.com/saghen/blink.lib" },
	{ src = "https://github.com/stevearc/oil.nvim" },
	{ src = "https://github.com/sphamba/smear-cursor.nvim" },
})

require("gitsigns").setup({})
require("nvim-autopairs").setup({})
require("blink.cmp").setup({
	keymap = { preset = 'enter' },
	fuzzy = { implementation = "lua" }
})
require("oil").setup({
	default_file_explorer = true,
	lsp_file_methods = {
		enabled = true,
		timeout_ms = 1000,
		autosave_changes = true,
	},
	columns = {
		"permissions",
		"size",
	},
	float = {
		max_width = 0.7,
		max_height = 0.6,
		border = vim.o.winborder,
	},
	buf_options = {
		buflisted = false,
		bufhidden = "hide",
	},
	view_options = {
		show_hidden = true,
	},
})

require("smear_cursor").setup({
	smear_insert_mode = true,
	stiffness = 0.7,
	trailing_stiffness = 0.3,
	stiffness_insert_mode = 0.7,
	trailing_stiffness_insert_mode = 0.7,
	damping = 0.67,
	damping_insert_mode = 0.67,
	distance_stop_animating = 0.4,
})

vim.cmd [[colorscheme tokyonight-night]]
vim.cmd [[Gitsigns toggle_current_line_blame]]

-- MAPPING

local map = vim.keymap.set

map("n", "<C-d>", "<C-d>zz")
map("n", "<C-u>", "<C-u>zz")
map("v", "J", ":m '>+1<CR>gv=gv")
map("v", "K", ":m '<-2<CR>gv=gv")
map("n", "n", "nzzzv")
map("n", "N", "Nzzzv")
map("n", "<leader>s", [[%s/\<<C-r><C-w>\>/<C-r><C-w>/gI<Left><Left><Left>]])
map("n", "<leader>e", [[:Oil<CR>]])

local fzf = require("fzf-lua") -- blazing fast

map("n", "<leader>F", ":FzfLua<CR>")
map("n", "<leader>f", fzf.files)
map("n", "<leader>t", fzf.treesitter)
map("n", "<leader>/", fzf.live_grep)

-- Configure lua_ls to use neovim runtime or all of lua_ls lib.
-- We put way much load on the cpu if we open both.
local lua_ls_lib = {}
local neovim_config_path = vim.fn.expand("~/code/dox/artixlinux/home/.config/nvim/init.lua")

if vim.api.nvim_buf_get_name(0) == neovim_config_path then
	lua_ls_lib = vim.api.nvim_get_runtime_file("", true)
else
	for lib in vim.fn.expand("/usr/lib/lua-language-server/meta/3rd/*/library"):gmatch("[^\n]+") do
		table.insert(lua_ls_lib, lib)
	end
end

vim.lsp.config("lua_ls", {
	settings = {
		Lua = {
			workspace = {
				library = lua_ls_lib
			}
		}
	}
})

-- do not enable jdtls here, we let the nvim-jdtls plugin do everything
vim.lsp.enable({
	"lua_ls", "cssls", "html", "jsonls", "clangd", "ts_ls",
	"tinymist", "marksman", "lemminx", "rust_analyzer", "pyright"
})

-- AUTOCMDS

vim.api.nvim_create_autocmd("TextYankPost", {
	callback = function() vim.hl.on_yank() end
})

vim.api.nvim_create_autocmd("BufWritePre", {
	callback = function() vim.lsp.buf.format() end
})

vim.api.nvim_create_autocmd("BufWritePost", {
	pattern = "*.tex",
	callback = function() vim.cmd [[! pdflatex % ]] end
})

vim.api.nvim_create_autocmd("FileType", {
	pattern = "java",
	callback = function(args)
		local project_name = vim.fn.fnamemodify(vim.fn.getcwd(), ":p:h:t")
		local workspace_dir = vim.fn.stdpath("data")
		    .. package.config:sub(1, 1)
		    .. "jdtls-workspace"
		    .. package.config:sub(1, 1)
		    .. project_name

		local config = {
			name = "jdtls",
			cmd = {
				"jdtls",
				"-data",
				workspace_dir,
			},
			root_dir = vim.fs.root(0, { ".git", "meta", "gradlew", "mvnw" }),
			settings = { java = {} },
			init_options = { bundles = {} },
		}
		require('jdtls').start_or_attach(config)
	end
})

--[[
function get_hl_groups()
	for hl_name, hl in pairs(vim.api.nvim_get_hl(0, {})) do
		print(hl_name)
	end
end

local function update_hl(group, tbl)
	local old_hl = vim.api.nvim_get_hl_by_name(group, true)
	local new_hl = vim.tbl_extend('force', old_hl, tbl)
	vim.api.nvim_set_hl(0, group, new_hl)
end
]]