Skip to content

Commit ccaa0fb

Browse files
committed
Merge branch 'master' of github.com:JoeSharp/kickstart.nvim
2 parents 16c44e2 + 920ee08 commit ccaa0fb

File tree

5 files changed

+181
-22
lines changed

5 files changed

+181
-22
lines changed

.github/workflows/stylua.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Check Lua Formatting
2+
name: Check Lua Formatting
3+
on: pull_request
4+
5+
jobs:
6+
stylua-check:
7+
name: Stylua Check
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Checkout Code
11+
uses: actions/checkout@v2
12+
- name: Stylua Check
13+
uses: JohnnyMorganz/stylua-action@v3
14+
with:
15+
token: ${{ secrets.GITHUB_TOKEN }}
16+
version: latest
17+
args: --check .
18+

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ tmux
1919

2020
## ZSH (standard with mac)
2121
https://github.com/ohmyzsh/ohmyzsh/wiki/Installing-ZSH
22+
=======
23+
| OS | PATH |
24+
| :- | :--- |
25+
| Linux | `$XDG_CONFIG_HOME/nvim`, `~/.config/nvim` |
26+
| MacOS | `$XDG_CONFIG_HOME/nvim`, `~/.config/nvim` |
27+
| Windows (cmd)| `%userprofile%\AppData\Local\nvim\` |
28+
| Windows (powershell)| `$env:USERPROFILE\AppData\Local\nvim\` |
2229

2330
## Oh-My-Zsh
2431
The plugin management for ZSH
@@ -34,7 +41,6 @@ https://github.com/romkatv/powerlevel10k#oh-my-zsh
3441
```bash
3542
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
3643
```
37-
3844
In `~/.zshrc`
3945
```
4046
ZSH_THEME="powerlevel10k/powerlevel10k"
@@ -84,10 +90,6 @@ Install neovim
8490

8591
## Plugin Management
8692

87-
Using Packer
88-
https://github.com/wbthomason/packer.nvim#bootstrapping
89-
90-
9193
# Important Config Files
9294
~/.zshrc
9395
~/.tmux.conf

init.lua

Lines changed: 153 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,50 @@
1+
--[[
2+
3+
=====================================================================
4+
==================== READ THIS BEFORE CONTINUING ====================
5+
=====================================================================
6+
7+
Kickstart.nvim is *not* a distribution.
8+
9+
Kickstart.nvim is a template for your own configuration.
10+
The goal is that you can read every line of code, top-to-bottom, understand
11+
what your configuration is doing, and modify it to suit your needs.
12+
13+
Once you've done that, you should start exploring, configuring and tinkering to
14+
explore Neovim!
15+
16+
If you don't know anything about Lua, I recommend taking some time to read through
17+
a guide. One possible example:
18+
- https://learnxinyminutes.com/docs/lua/
19+
20+
21+
And then you can explore or search through `:help lua-guide`
22+
- https://neovim.io/doc/user/lua-guide.html
23+
24+
25+
Kickstart Guide:
26+
27+
I have left several `:help X` comments throughout the init.lua
28+
You should run that command and read that help section for more information.
29+
30+
In addition, I have some `NOTE:` items throughout the file.
31+
These are for you, the reader to help understand what is happening. Feel free to delete
32+
them once you know what you're doing, but they should serve as a guide for when you
33+
are first encountering a few different constructs in your nvim config.
34+
35+
I hope you enjoy your Neovim journey,
36+
- TJ
37+
38+
P.S. You can delete this when you're done too. It's your config now :)
39+
--]]
40+
41+
-- Set <space> as the leader key
142
-- See `:help mapleader`
243
-- NOTE: Must happen before plugins are required (otherwise wrong leader will be used)
344
vim.g.mapleader = ' '
445
vim.g.maplocalleader = ' '
546

6-
-- Install package manager
47+
-- [[ Install `lazy.nvim` plugin manager ]]
748
-- https://github.com/folke/lazy.nvim
849
-- `:help lazy.nvim.txt` for more info
950
local lazypath = vim.fn.stdpath 'data' .. '/lazy/lazy.nvim'
@@ -19,6 +60,7 @@ if not vim.loop.fs_stat(lazypath) then
1960
end
2061
vim.opt.rtp:prepend(lazypath)
2162

63+
-- [[ Configure plugins ]]
2264
-- NOTE: Here is where you install your plugins.
2365
-- You can configure plugins using the `config` key.
2466
--
@@ -46,7 +88,7 @@ require('lazy').setup({
4688

4789
-- Useful status updates for LSP
4890
-- NOTE: `opts = {}` is the same as calling `require('fidget').setup({})`
49-
{ 'j-hui/fidget.nvim', tag = 'legacy', opts = {} },
91+
{ 'j-hui/fidget.nvim', opts = {} },
5092

5193
-- Additional lua configuration, makes nvim stuff amazing!
5294
'folke/neodev.nvim',
@@ -63,6 +105,7 @@ require('lazy').setup({
63105

64106
-- Adds LSP completion capabilities
65107
'hrsh7th/cmp-nvim-lsp',
108+
'hrsh7th/cmp-path',
66109

67110
-- Adds a number of user-friendly snippets
68111
'rafamadriz/friendly-snippets',
@@ -84,28 +127,64 @@ require('lazy').setup({
84127
changedelete = { text = '~' },
85128
},
86129
on_attach = function(bufnr)
87-
vim.keymap.set('n', '<leader>hp', require('gitsigns').preview_hunk, { buffer = bufnr, desc = 'Preview git hunk' })
88-
89-
-- don't override the built-in and fugitive keymaps
90130
local gs = package.loaded.gitsigns
91-
vim.keymap.set({ 'n', 'v' }, ']c', function()
131+
132+
local function map(mode, l, r, opts)
133+
opts = opts or {}
134+
opts.buffer = bufnr
135+
vim.keymap.set(mode, l, r, opts)
136+
end
137+
138+
-- Navigation
139+
map({ 'n', 'v' }, ']c', function()
92140
if vim.wo.diff then
93141
return ']c'
94142
end
95143
vim.schedule(function()
96144
gs.next_hunk()
97145
end)
98146
return '<Ignore>'
99-
end, { expr = true, buffer = bufnr, desc = 'Jump to next hunk' })
100-
vim.keymap.set({ 'n', 'v' }, '[c', function()
147+
end, { expr = true, desc = 'Jump to next hunk' })
148+
149+
map({ 'n', 'v' }, '[c', function()
101150
if vim.wo.diff then
102151
return '[c'
103152
end
104153
vim.schedule(function()
105154
gs.prev_hunk()
106155
end)
107156
return '<Ignore>'
108-
end, { expr = true, buffer = bufnr, desc = 'Jump to previous hunk' })
157+
end, { expr = true, desc = 'Jump to previous hunk' })
158+
159+
-- Actions
160+
-- visual mode
161+
map('v', '<leader>hs', function()
162+
gs.stage_hunk { vim.fn.line '.', vim.fn.line 'v' }
163+
end, { desc = 'stage git hunk' })
164+
map('v', '<leader>hr', function()
165+
gs.reset_hunk { vim.fn.line '.', vim.fn.line 'v' }
166+
end, { desc = 'reset git hunk' })
167+
-- normal mode
168+
map('n', '<leader>hs', gs.stage_hunk, { desc = 'git stage hunk' })
169+
map('n', '<leader>hr', gs.reset_hunk, { desc = 'git reset hunk' })
170+
map('n', '<leader>hS', gs.stage_buffer, { desc = 'git Stage buffer' })
171+
map('n', '<leader>hu', gs.undo_stage_hunk, { desc = 'undo stage hunk' })
172+
map('n', '<leader>hR', gs.reset_buffer, { desc = 'git Reset buffer' })
173+
map('n', '<leader>hp', gs.preview_hunk, { desc = 'preview git hunk' })
174+
map('n', '<leader>hb', function()
175+
gs.blame_line { full = false }
176+
end, { desc = 'git blame line' })
177+
map('n', '<leader>hd', gs.diffthis, { desc = 'git diff against index' })
178+
map('n', '<leader>hD', function()
179+
gs.diffthis '~'
180+
end, { desc = 'git diff against last commit' })
181+
182+
-- Toggles
183+
map('n', '<leader>tb', gs.toggle_current_line_blame, { desc = 'toggle git blame line' })
184+
map('n', '<leader>td', gs.toggle_deleted, { desc = 'toggle git show deleted' })
185+
186+
-- Text object
187+
map({ 'o', 'x' }, 'ih', ':<C-U>Gitsigns select_hunk<CR>', { desc = 'select git hunk' })
109188
end,
110189
},
111190
},
@@ -241,6 +320,12 @@ vim.keymap.set({ 'n', 'v' }, '<Space>', '<Nop>', { silent = true })
241320
vim.keymap.set('n', 'k', "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true })
242321
vim.keymap.set('n', 'j', "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true })
243322

323+
-- Diagnostic keymaps
324+
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = 'Go to previous diagnostic message' })
325+
vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'Go to next diagnostic message' })
326+
vim.keymap.set('n', '<leader>e', vim.diagnostic.open_float, { desc = 'Open floating diagnostic message' })
327+
vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist, { desc = 'Open diagnostics list' })
328+
244329
-- [[ Highlight on yank ]]
245330
-- See `:help vim.highlight.on_yank()`
246331
local highlight_group = vim.api.nvim_create_augroup('YankHighlight', { clear = true })
@@ -268,6 +353,42 @@ require('telescope').setup {
268353
-- Enable telescope fzf native, if installed
269354
pcall(require('telescope').load_extension, 'fzf')
270355

356+
-- Telescope live_grep in git root
357+
-- Function to find the git root directory based on the current buffer's path
358+
local function find_git_root()
359+
-- Use the current buffer's path as the starting point for the git search
360+
local current_file = vim.api.nvim_buf_get_name(0)
361+
local current_dir
362+
local cwd = vim.fn.getcwd()
363+
-- If the buffer is not associated with a file, return nil
364+
if current_file == '' then
365+
current_dir = cwd
366+
else
367+
-- Extract the directory from the current file's path
368+
current_dir = vim.fn.fnamemodify(current_file, ':h')
369+
end
370+
371+
-- Find the Git root directory from the current file's path
372+
local git_root = vim.fn.systemlist('git -C ' .. vim.fn.escape(current_dir, ' ') .. ' rev-parse --show-toplevel')[1]
373+
if vim.v.shell_error ~= 0 then
374+
print 'Not a git repository. Searching on current working directory'
375+
return cwd
376+
end
377+
return git_root
378+
end
379+
380+
-- Custom live_grep function to search in git root
381+
local function live_grep_git_root()
382+
local git_root = find_git_root()
383+
if git_root then
384+
require('telescope.builtin').live_grep {
385+
search_dirs = { git_root },
386+
}
387+
end
388+
end
389+
390+
vim.api.nvim_create_user_command('LiveGrepGitRoot', live_grep_git_root, {})
391+
271392
-- See `:help telescope.builtin`
272393
vim.keymap.set('n', '<leader>?', require('telescope.builtin').oldfiles, { desc = '[?] Find recently opened files' })
273394
vim.keymap.set('n', '<leader><space>', require('telescope.builtin').buffers, { desc = '[ ] Find existing buffers' })
@@ -279,11 +400,20 @@ vim.keymap.set('n', '<leader>/', function()
279400
})
280401
end, { desc = '[/] Fuzzily search in current buffer' })
281402

403+
local function telescope_live_grep_open_files()
404+
require('telescope.builtin').live_grep {
405+
grep_open_files = true,
406+
prompt_title = 'Live Grep in Open Files',
407+
}
408+
end
409+
vim.keymap.set('n', '<leader>s/', telescope_live_grep_open_files, { desc = '[S]earch [/] in Open Files' })
410+
vim.keymap.set('n', '<leader>ss', require('telescope.builtin').builtin, { desc = '[S]earch [S]elect Telescope' })
282411
vim.keymap.set('n', '<leader>gf', require('telescope.builtin').git_files, { desc = 'Search [G]it [F]iles' })
283412
vim.keymap.set('n', '<leader>sf', require('telescope.builtin').find_files, { desc = '[S]earch [F]iles' })
284413
vim.keymap.set('n', '<leader>sh', require('telescope.builtin').help_tags, { desc = '[S]earch [H]elp' })
285414
vim.keymap.set('n', '<leader>sw', require('telescope.builtin').grep_string, { desc = '[S]earch current [W]ord' })
286415
vim.keymap.set('n', '<leader>sg', require('telescope.builtin').live_grep, { desc = '[S]earch by [G]rep' })
416+
vim.keymap.set('n', '<leader>sG', ':LiveGrepGitRoot<cr>', { desc = '[S]earch by [G]rep on Git Root' })
287417
vim.keymap.set('n', '<leader>sd', require('telescope.builtin').diagnostics, { desc = '[S]earch [D]iagnostics' })
288418
vim.keymap.set('n', '<leader>sr', require('telescope.builtin').resume, { desc = '[S]earch [R]esume' })
289419

@@ -356,12 +486,6 @@ vim.defer_fn(function()
356486
}
357487
end, 0)
358488

359-
-- Diagnostic keymaps
360-
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = 'Go to previous diagnostic message' })
361-
vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'Go to next diagnostic message' })
362-
vim.keymap.set('n', '<leader>e', vim.diagnostic.open_float, { desc = 'Open floating diagnostic message' })
363-
vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist, { desc = 'Open diagnostics list' })
364-
365489
-- [[ Configure LSP ]]
366490
-- This function gets run when an LSP connects to a particular buffer.
367491
local on_attach = function(_, bufnr)
@@ -412,11 +536,18 @@ require('which-key').register {
412536
['<leader>c'] = { name = '[C]ode', _ = 'which_key_ignore' },
413537
['<leader>d'] = { name = '[D]ocument', _ = 'which_key_ignore' },
414538
['<leader>g'] = { name = '[G]it', _ = 'which_key_ignore' },
415-
['<leader>h'] = { name = 'More git', _ = 'which_key_ignore' },
539+
['<leader>h'] = { name = 'Git [H]unk', _ = 'which_key_ignore' },
416540
['<leader>r'] = { name = '[R]ename', _ = 'which_key_ignore' },
417541
['<leader>s'] = { name = '[S]earch', _ = 'which_key_ignore' },
542+
['<leader>t'] = { name = '[T]oggle', _ = 'which_key_ignore' },
418543
['<leader>w'] = { name = '[W]orkspace', _ = 'which_key_ignore' },
419544
}
545+
-- register which-key VISUAL mode
546+
-- required for visual <leader>hs (hunk stage) to work
547+
require('which-key').register({
548+
['<leader>'] = { name = 'VISUAL <leader>' },
549+
['<leader>h'] = { 'Git [H]unk' },
550+
}, { mode = 'v' })
420551

421552
-- mason-lspconfig requires that these setup functions are called in this order
422553
-- before setting up the servers.
@@ -443,6 +574,8 @@ local servers = {
443574
Lua = {
444575
workspace = { checkThirdParty = false },
445576
telemetry = { enable = false },
577+
-- NOTE: toggle below to ignore Lua_LS's noisy `missing-fields` warnings
578+
-- diagnostics = { disable = { 'missing-fields' } },
446579
},
447580
},
448581
jdtls = {
@@ -493,6 +626,9 @@ cmp.setup {
493626
luasnip.lsp_expand(args.body)
494627
end,
495628
},
629+
completion = {
630+
completeopt = 'menu,menuone,noinsert',
631+
},
496632
mapping = cmp.mapping.preset.insert {
497633
['<C-n>'] = cmp.mapping.select_next_item(),
498634
['<C-p>'] = cmp.mapping.select_prev_item(),
@@ -525,6 +661,7 @@ cmp.setup {
525661
sources = {
526662
{ name = 'nvim_lsp' },
527663
{ name = 'luasnip' },
664+
{ name = 'path' },
528665
},
529666
}
530667
vim.wo.relativenumber = true

lazy-lock.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"Comment.nvim": { "branch": "master", "commit": "0236521ea582747b58869cb72f70ccfa967d2e89" },
33
"LuaSnip": { "branch": "master", "commit": "a4de64570b9620875c8ea04175cd07ed8e32ac99" },
44
"cmp-nvim-lsp": { "branch": "main", "commit": "44b16d11215dce86f253ce0c30949813c0a90765" },
5+
"cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" },
56
"cmp_luasnip": { "branch": "master", "commit": "05a9ab28b53f71d1aece421ef32fee2cb857a843" },
67
"fidget.nvim": { "branch": "main", "commit": "0ba1e16d07627532b6cae915cc992ecac249fb97" },
78
"friendly-snippets": { "branch": "main", "commit": "43727c2ff84240e55d4069ec3e6158d74cb534b6" },

tmux.conf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ set -g @plugin 'tmux-plugins/tmux-resurrect'
3535

3636
set -g @dracula-show-powerline true
3737
set -g @dracula-fixed-location "Gloucester"
38-
set -g @dracula-plugins "weather"
38+
set -g @dracula-plugins "time"
3939
set -g @dracula-show-flags true
40+
set -g @dracula-show-timezone true
4041
set -g @dracula-show-left-icon session
4142
set -g status-position top
4243

0 commit comments

Comments
 (0)