-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.lua
230 lines (204 loc) · 6.74 KB
/
init.lua
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
-- General Settings
vim.cmd("set guicursor=n-v-c-i:block")
vim.cmd("set expandtab")
vim.cmd("set tabstop=2")
vim.cmd("set softtabstop=2")
vim.cmd("set shiftwidth=2")
vim.g.mapleader = ','
vim.g.maplocalleader = ',' -- Set leader and local leader to ','
vim.opt.number = true -- Show line numbers
vim.opt.autoindent = true
vim.opt.autowrite = true -- Automatically save files on buffer switch
vim.opt.autoread = true -- Reload files changed outside of Neovim
vim.opt.cursorline = true -- Highlight current line
vim.opt.termguicolors = true
vim.opt.autochdir = false
vim.opt.swapfile = false
vim.opt.showmode = true
vim.opt.signcolumn = 'no'
vim.opt.clipboard = "unnamed" -- Use system clipboard
-- Keymaps
vim.keymap.set('i', '<leader>m', '<space>%>%', { silent = true }) -- R Pipe
vim.keymap.set('i', '<leader>r', function()
local code_block = "```{r}\n\n```"
vim.api.nvim_feedkeys(
vim.api.nvim_replace_termcodes(code_block .. "<Esc>ki", true, false, true),
'n',
true
)
end, { silent = true }) -- R Code Chunk
-- Prevent yank on delete
vim.keymap.set({'n', 'v'}, 'd', '"_d', { noremap = true })
vim.keymap.set({'n', 'v'}, 'D', '"_D', { noremap = true })
vim.keymap.set('n', 'dd', '"_dd', { noremap = true })
vim.keymap.set('n', 'x', '"_x', { noremap = true })
-- Lazy.nvim Setup
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
vim.fn.system({
"git", "clone", "--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable", lazypath,
})
end
vim.opt.rtp:prepend(lazypath)
-- Plugins
local plugins = {
-- Theme
{ "rose-pine/neovim", name = "rose-pine" },
-- Utilities
{ 'norcalli/nvim-colorizer.lua' },
{ 'windwp/nvim-autopairs', event = "InsertEnter", config = true },
{ "jpalardy/vim-slime", config = function() vim.g.slime_target = "tmux" end },
{ 'klafyvel/vim-slime-cells', requires = {{'jpalardy/vim-slime', opt=true}},
ft = {'r'}, config = function()
vim.g.slime_target = "tmux"
vim.g.slime_cell_delimiter = "^\\s*##"
vim.g.slime_default_config = { socket_name = "default", target_pane = "1" }
vim.g.slime_dont_ask_default = 1
vim.g.slime_bracketed_paste = 1
vim.cmd([[
nmap <leader>s <Plug>SlimeConfig
nmap <leader>cc <Plug>SlimeCellsSendAndGoToNext
nmap <leader>j <Plug>SlimeCellsNext
nmap <leader>k <Plug>SlimeCellsPrev
]])
end
},
-- Language Support
{ "lervag/vimtex", init = function() vim.g.vimtex_view_method = 'zathura' end },
{ 'kaarmu/typst.vim', ft = 'typst', lazy = false },
-- Telescope and Dependencies
{ "nvim-telescope/telescope.nvim" },
{ "nvim-treesitter/nvim-treesitter" },
{ "nvim-lua/plenary.nvim" },
-- Statusline
{ 'nvim-lualine/lualine.nvim', dependencies = { 'nvim-tree/nvim-web-devicons' } },
-- LSP and Autocompletion
{ "williamboman/mason.nvim" },
{ "williamboman/mason-lspconfig.nvim" },
{ "neovim/nvim-lspconfig" },
{ "hrsh7th/nvim-cmp" }, -- Completion plugin
{ "hrsh7th/cmp-nvim-lsp" }, -- LSP source for nvim-cmp
{ "hrsh7th/cmp-buffer" }, -- Buffer source
{ "hrsh7th/cmp-path" }, -- Path source
{ "saadparwaiz1/cmp_luasnip" }, -- Snippet completion
{ "L3MON4D3/LuaSnip" }, -- Snippet engine
{ "rafamadriz/friendly-snippets" }, -- Predefined snippets
-- Formatter
{ 'stevearc/conform.nvim', opts = {} },
-- File Explorer
{ 'nvim-tree/nvim-tree.lua' },
-- Advanced Features
{ "karb94/neoscroll.nvim" },
-- Code Quality Tools
{ "mfussenegger/nvim-lint", event = { "BufReadPre", "BufNewFile" }, config = function()
local lint = require("lint")
lint.linters_by_ft = { swift = { "swiftlint" } }
local lint_group = vim.api.nvim_create_augroup("Lint", { clear = true })
vim.api.nvim_create_autocmd({ "BufWritePost", "BufReadPost", "InsertLeave", "TextChanged" }, {
group = lint_group,
callback = function() lint.try_lint() end,
})
vim.keymap.set("n", "<leader>ml", lint.try_lint, { desc = "Lint file" })
end
}
}
require("lazy").setup(plugins, {})
-- Theme Configuration
require("rose-pine").setup({
variant = "auto",
dark_variant = "main",
styles = { bold = true, italic = true, transparency = false },
highlight_groups = { }
})
vim.cmd("colorscheme rose-pine")
-- Telescope Keymaps
local builtin = require('telescope.builtin')
vim.keymap.set('n', '<leader>ff', builtin.find_files, {})
vim.keymap.set('n', '<leader>fg', builtin.live_grep, {})
vim.keymap.set('n', '<leader>fb', builtin.buffers, {})
vim.keymap.set('n', '<leader>fh', builtin.help_tags, {})
-- Lualine Configuration
require('lualine').setup({
options = {
theme = 'auto',
section_separators = { left = '', right = '' },
component_separators = { left = '', right = '' },
},
sections = {
lualine_b = { 'branch' },
lualine_c = { 'filename' },
lualine_y = { 'progress' },
},
inactive_sections = {
lualine_c = { 'filename' },
lualine_x = { 'location' },
},
})
-- Colorizer Setup
require("colorizer").setup()
-- Mason LSP Setup
require("mason").setup()
require("mason-lspconfig").setup {
ensure_installed = { "clangd", "r_language_server", "gopls" }
}
local capabilities = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities())
-- Configure LSP Servers
require("lspconfig").r_language_server.setup {}
require("lspconfig").clangd.setup {}
require("lspconfig").gopls.setup {
capabilities = capabilities,
settings = {
gopls = {
analyses = {
unusedparams = true,
},
staticcheck = true,
},
},
}
-- Autocompletion Setup using nvim-cmp and LuaSnip
local cmp = require("cmp")
local luasnip = require("luasnip")
-- Load snippets from friendly-snippets
require("luasnip.loaders.from_vscode").lazy_load()
cmp.setup({
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
mapping = {
["<C-b>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-Space>"] = cmp.mapping.complete(),
["<C-e>"] = cmp.mapping.abort(),
["<CR>"] = cmp.mapping.confirm({ select = true }),
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
else
fallback()
end
end, { "i", "s" }),
["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { "i", "s" }),
},
sources = cmp.config.sources({
{ name = "nvim_lsp" },
{ name = "luasnip" },
}, {
{ name = "buffer" },
{ name = "path" },
}),
})