Skip to content

Commit 95a3fff

Browse files
committed
Add Trouble for LSP diagnostic
1 parent 9a877de commit 95a3fff

16 files changed

+764
-703
lines changed

init.lua

Lines changed: 9 additions & 702 deletions
Large diffs are not rendered by default.

lua/kickstart/plugins/neo-tree.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ return {
1111
},
1212
cmd = 'Neotree',
1313
keys = {
14-
{ '\\', ':Neotree reveal<CR>', { desc = 'NeoTree reveal' } },
14+
{ '<C-n>', ':Neotree toggle<CR>', { desc = 'NeoTree toggle' } },
15+
-- { '\\', ':Neotree reveal<CR>', { desc = 'NeoTree reveal' } },
1516
},
1617
opts = {
1718
filesystem = {

lua/my_config/install-lazy.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-- [[ Install `lazy.nvim` plugin manager ]]
2+
-- See `:help lazy.nvim.txt` or https://github.com/folke/lazy.nvim for more info
3+
local lazypath = vim.fn.stdpath 'data' .. '/lazy/lazy.nvim'
4+
if not vim.loop.fs_stat(lazypath) then
5+
local lazyrepo = 'https://github.com/folke/lazy.nvim.git'
6+
vim.fn.system { 'git', 'clone', '--filter=blob:none', '--branch=stable', lazyrepo, lazypath }
7+
end ---@diagnostic disable-next-line: undefined-field
8+
vim.opt.rtp:prepend(lazypath)

lua/my_config/keys.lua

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
-- Set <space> as the leader key
2+
-- See `:help mapleader`
3+
-- NOTE: Must happen before plugins are loaded (otherwise wrong leader will be used)
4+
vim.g.mapleader = ' '
5+
vim.g.maplocalleader = ' '
6+
7+
-- Set to true if you have a Nerd Font installed and selected in the terminal
8+
vim.g.have_nerd_font = true
9+
10+
-- [[ Setting options ]]
11+
-- See `:help vim.opt`
12+
-- NOTE: You can change these options as you wish!
13+
-- For more options, you can see `:help option-list`
14+
15+
-- Make line numbers default
16+
vim.opt.number = true
17+
-- You can also add relative line numbers, to help with jumping.
18+
-- Experiment for yourself to see if you like it!
19+
vim.opt.relativenumber = true
20+
21+
-- Enable mouse mode, can be useful for resizing splits for example!
22+
vim.opt.mouse = 'a'
23+
24+
-- Don't show the mode, since it's already in the status line
25+
vim.opt.showmode = false
26+
27+
-- Sync clipboard between OS and Neovim.
28+
-- Remove this option if you want your OS clipboard to remain independent.
29+
-- See `:help 'clipboard'`
30+
vim.opt.clipboard = 'unnamedplus'
31+
32+
-- Enable break indent
33+
vim.opt.breakindent = true
34+
35+
-- Save undo history
36+
vim.opt.undofile = true
37+
38+
-- Case-insensitive searching UNLESS \C or one or more capital letters in the search term
39+
vim.opt.ignorecase = true
40+
vim.opt.smartcase = true
41+
42+
-- Keep signcolumn on by default
43+
vim.opt.signcolumn = 'yes'
44+
45+
-- Decrease update time
46+
vim.opt.updatetime = 250
47+
48+
-- Decrease mapped sequence wait time
49+
-- Displays which-key popup sooner
50+
vim.opt.timeoutlen = 300
51+
52+
-- Configure how new splits should be opened
53+
vim.opt.splitright = true
54+
vim.opt.splitbelow = true
55+
56+
-- Sets how neovim will display certain whitespace characters in the editor.
57+
-- See `:help 'list'`
58+
-- and `:help 'listchars'`
59+
vim.opt.list = true
60+
vim.opt.listchars = { tab = '» ', trail = '·', nbsp = '' }
61+
62+
-- Preview substitutions live, as you type!
63+
vim.opt.inccommand = 'split'
64+
65+
-- Show which line your cursor is on
66+
vim.opt.cursorline = true
67+
68+
-- Minimal number of screen lines to keep above and below the cursor.
69+
vim.opt.scrolloff = 10
70+
71+
-- Disable swapfiles
72+
vim.opt.swapfile = false
73+
74+
vim.opt.termguicolors = true
75+
76+
-- [[ Basic Keymaps ]]
77+
-- See `:help vim.keymap.set()`
78+
79+
-- Set highlight on search, but clear on pressing <Esc> in normal mode
80+
vim.opt.hlsearch = true
81+
vim.keymap.set('n', '<Esc>', '<cmd>nohlsearch<CR>')
82+
83+
-- Diagnostic keymaps
84+
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = 'Go to previous [D]iagnostic message' })
85+
vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'Go to next [D]iagnostic message' })
86+
vim.keymap.set('n', '<leader>e', vim.diagnostic.open_float, { desc = 'Show diagnostic [E]rror messages' })
87+
vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist, { desc = 'Open diagnostic [Q]uickfix list' })
88+
89+
-- Exit terminal mode in the builtin terminal with a shortcut that is a bit easier
90+
-- for people to discover. Otherwise, you normally need to press <C-\><C-n>, which
91+
-- is not what someone will guess without a bit more experience.
92+
--
93+
-- NOTE: This won't work in all terminal emulators/tmux/etc. Try your own mapping
94+
-- or just use <C-\><C-n> to exit terminal mode
95+
vim.keymap.set('t', '<Esc><Esc>', '<C-\\><C-n>', { desc = 'Exit terminal mode' })
96+
97+
-- TIP: Disable arrow keys in normal mode
98+
-- vim.keymap.set('n', '<left>', '<cmd>echo "Use h to move!!"<CR>')
99+
-- vim.keymap.set('n', '<right>', '<cmd>echo "Use l to move!!"<CR>')
100+
-- vim.keymap.set('n', '<up>', '<cmd>echo "Use k to move!!"<CR>')
101+
-- vim.keymap.set('n', '<down>', '<cmd>echo "Use j to move!!"<CR>')
102+
103+
-- Keybinds to make split navigation easier.
104+
-- Use CTRL+<hjkl> to switch between windows
105+
--
106+
-- See `:help wincmd` for a list of all window commands
107+
vim.keymap.set('n', '<C-h>', '<C-w><C-h>', { desc = 'Move focus to the left window' })
108+
vim.keymap.set('n', '<C-l>', '<C-w><C-l>', { desc = 'Move focus to the right window' })
109+
vim.keymap.set('n', '<C-j>', '<C-w><C-j>', { desc = 'Move focus to the lower window' })
110+
vim.keymap.set('n', '<C-k>', '<C-w><C-k>', { desc = 'Move focus to the upper window' })
111+
112+
vim.keymap.set('n', '<leader>qq', '<cmd>qa<CR>', { desc = 'Quit all' })
113+
114+
-- Tab control; Tab buffer display in mini
115+
vim.keymap.set('n', '<Tab>', '<cmd>bnext<CR>', { desc = 'Next buffer' })
116+
vim.keymap.set('n', '<S-Tab>', '<cmd>bprev<CR>', { desc = 'Previous buffer' })
117+
vim.keymap.set('n', '<leader>x', '<cmd>bd<CR>', { desc = 'Delete current buffer' })
118+
119+
-- [[ Basic Autocommands ]]
120+
-- See `:help lua-guide-autocommands`
121+
122+
-- Highlight when yanking (copying) text
123+
-- Try it with `yap` in normal mode
124+
-- See `:help vim.highlight.on_yank()`
125+
vim.api.nvim_create_autocmd('TextYankPost', {
126+
desc = 'Highlight when yanking (copying) text',
127+
group = vim.api.nvim_create_augroup('kickstart-highlight-yank', { clear = true }),
128+
callback = function()
129+
vim.highlight.on_yank()
130+
end,
131+
})

lua/plugins/comment.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
return {
2+
-- "gc" to comment visual regions/lines
3+
{ 'numToStr/Comment.nvim', opts = {} },
4+
}

lua/plugins/conform.lua

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
return { -- Autoformat
2+
'stevearc/conform.nvim',
3+
lazy = false,
4+
keys = {
5+
{
6+
'<leader>f',
7+
function()
8+
require('conform').format { async = true, lsp_fallback = true }
9+
end,
10+
mode = '',
11+
desc = '[F]ormat buffer',
12+
},
13+
},
14+
opts = {
15+
notify_on_error = false,
16+
format_on_save = function(bufnr)
17+
-- Disable "format_on_save lsp_fallback" for languages that don't
18+
-- have a well standardized coding style. You can add additional
19+
-- languages here or re-enable it for the disabled ones.
20+
local disable_filetypes = { c = true, cpp = true }
21+
return {
22+
timeout_ms = 500,
23+
lsp_fallback = not disable_filetypes[vim.bo[bufnr].filetype],
24+
}
25+
end,
26+
formatters_by_ft = {
27+
lua = { 'stylua' },
28+
-- Conform can also run multiple formatters sequentially
29+
-- python = { "isort", "black" },
30+
--
31+
-- You can use a sub-list to tell conform to run *until* a formatter
32+
-- is found.
33+
-- javascript = { { "prettierd", "prettier" } },
34+
},
35+
},
36+
}

lua/plugins/git-signs.lua

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
return {
2+
-- Here is a more advanced example where we pass configuration
3+
-- options to `gitsigns.nvim`. This is equivalent to the following Lua:
4+
-- require('gitsigns').setup({ ... })
5+
--
6+
-- See `:help gitsigns` to understand what the configuration keys do
7+
-- Adds git related signs to the gutter, as well as utilities for managing changes
8+
'lewis6991/gitsigns.nvim',
9+
opts = {
10+
signs = {
11+
add = { text = '+' },
12+
change = { text = '~' },
13+
delete = { text = '_' },
14+
topdelete = { text = '' },
15+
changedelete = { text = '~' },
16+
},
17+
},
18+
}

lua/plugins/nvim-cmp.lua

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
return { -- Autocompletion
2+
'hrsh7th/nvim-cmp',
3+
event = 'InsertEnter',
4+
dependencies = {
5+
-- Snippet Engine & its associated nvim-cmp source
6+
{
7+
'L3MON4D3/LuaSnip',
8+
build = (function()
9+
-- Build Step is needed for regex support in snippets.
10+
-- This step is not supported in many windows environments.
11+
-- Remove the below condition to re-enable on windows.
12+
if vim.fn.has 'win32' == 1 or vim.fn.executable 'make' == 0 then
13+
return
14+
end
15+
return 'make install_jsregexp'
16+
end)(),
17+
dependencies = {
18+
-- `friendly-snippets` contains a variety of premade snippets.
19+
-- See the README about individual language/framework/plugin snippets:
20+
-- https://github.com/rafamadriz/friendly-snippets
21+
-- {
22+
-- 'rafamadriz/friendly-snippets',
23+
-- config = function()
24+
-- require('luasnip.loaders.from_vscode').lazy_load()
25+
-- end,
26+
-- },
27+
},
28+
},
29+
'saadparwaiz1/cmp_luasnip',
30+
31+
-- Adds other completion capabilities.
32+
-- nvim-cmp does not ship with all sources by default. They are split
33+
-- into multiple repos for maintenance purposes.
34+
'hrsh7th/cmp-nvim-lsp',
35+
'hrsh7th/cmp-path',
36+
},
37+
config = function()
38+
-- See `:help cmp`
39+
local cmp = require 'cmp'
40+
local luasnip = require 'luasnip'
41+
luasnip.config.setup {}
42+
43+
cmp.setup {
44+
snippet = {
45+
expand = function(args)
46+
luasnip.lsp_expand(args.body)
47+
end,
48+
},
49+
completion = { completeopt = 'menu,menuone,noinsert' },
50+
51+
-- For an understanding of why these mappings were
52+
-- chosen, you will need to read `:help ins-completion`
53+
--
54+
-- No, but seriously. Please read `:help ins-completion`, it is really good!
55+
mapping = cmp.mapping.preset.insert {
56+
-- Select the [n]ext item
57+
['<C-n>'] = cmp.mapping.select_next_item(),
58+
-- Select the [p]revious item
59+
['<C-p>'] = cmp.mapping.select_prev_item(),
60+
61+
-- Scroll the documentation window [b]ack / [f]orward
62+
['<C-b>'] = cmp.mapping.scroll_docs(-4),
63+
['<C-f>'] = cmp.mapping.scroll_docs(4),
64+
65+
-- Accept ([y]es) the completion.
66+
-- This will auto-import if your LSP supports it.
67+
-- This will expand snippets if the LSP sent a snippet.
68+
['<C-y>'] = cmp.mapping.confirm { select = true },
69+
70+
-- If you prefer more traditional completion keymaps,
71+
-- you can uncomment the following lines
72+
--['<CR>'] = cmp.mapping.confirm { select = true },
73+
--['<Tab>'] = cmp.mapping.select_next_item(),
74+
--['<S-Tab>'] = cmp.mapping.select_prev_item(),
75+
76+
-- Manually trigger a completion from nvim-cmp.
77+
-- Generally you don't need this, because nvim-cmp will display
78+
-- completions whenever it has completion options available.
79+
['<C-Space>'] = cmp.mapping.complete {},
80+
81+
-- Think of <c-l> as moving to the right of your snippet expansion.
82+
-- So if you have a snippet that's like:
83+
-- function $name($args)
84+
-- $body
85+
-- end
86+
--
87+
-- <c-l> will move you to the right of each of the expansion locations.
88+
-- <c-h> is similar, except moving you backwards.
89+
['<C-l>'] = cmp.mapping(function()
90+
if luasnip.expand_or_locally_jumpable() then
91+
luasnip.expand_or_jump()
92+
end
93+
end, { 'i', 's' }),
94+
['<C-h>'] = cmp.mapping(function()
95+
if luasnip.locally_jumpable(-1) then
96+
luasnip.jump(-1)
97+
end
98+
end, { 'i', 's' }),
99+
100+
-- For more advanced Luasnip keymaps (e.g. selecting choice nodes, expansion) see:
101+
-- https://github.com/L3MON4D3/LuaSnip?tab=readme-ov-file#keymaps
102+
},
103+
sources = {
104+
{ name = 'nvim_lsp' },
105+
{ name = 'luasnip' },
106+
{ name = 'path' },
107+
},
108+
}
109+
end,
110+
}

0 commit comments

Comments
 (0)