Skip to content

Commit 920ee08

Browse files
committed
Merge branch 'master' of github.com:nvim-lua/kickstart.nvim
2 parents 4edc66c + 76c5b1e commit 920ee08

File tree

3 files changed

+197
-20
lines changed

3 files changed

+197
-20
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: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,27 @@ Neovim's configurations are located under the following paths, depending on your
3434
| :- | :--- |
3535
| Linux | `$XDG_CONFIG_HOME/nvim`, `~/.config/nvim` |
3636
| MacOS | `$XDG_CONFIG_HOME/nvim`, `~/.config/nvim` |
37-
| Windows | `%userprofile%\AppData\Local\nvim\` |
37+
| Windows (cmd)| `%userprofile%\AppData\Local\nvim\` |
38+
| Windows (powershell)| `$env:USERPROFILE\AppData\Local\nvim\` |
3839

3940
Clone kickstart.nvim:
4041

42+
- on Linux and Mac
4143
```sh
42-
# on Linux and Mac
4344
git clone https://github.com/nvim-lua/kickstart.nvim.git "${XDG_CONFIG_HOME:-$HOME/.config}"/nvim
4445
```
4546

46-
47+
- on Windows (cmd)
4748
```
48-
# on Windows
4949
git clone https://github.com/nvim-lua/kickstart.nvim.git %userprofile%\AppData\Local\nvim\
5050
```
5151

52+
- on Windows (powershell)
53+
```
54+
git clone https://github.com/nvim-lua/kickstart.nvim.git $env:USERPROFILE\AppData\Local\nvim\
55+
```
56+
57+
5258
### Post Installation
5359

5460
Start Neovim
@@ -149,11 +155,27 @@ Each PR, especially those which increase the line count, should have a descripti
149155
* You should back it up, then delete all files associated with it.
150156
* This includes your existing init.lua and the neovim files in `~/.local` which can be deleted with `rm -rf ~/.local/share/nvim/`
151157
* You may also want to look at the [migration guide for lazy.nvim](https://github.com/folke/lazy.nvim#-migration-guide)
158+
* Can I keep my existing configuration in parallel to kickstart?
159+
* Yes! You can use [NVIM_APPNAME](https://neovim.io/doc/user/starting.html#%24NVIM_APPNAME)`=nvim-NAME` to maintain multiple configurations. For example you can install the kickstart configuration in `~/.config/nvim-kickstart` and create an alias:
160+
```
161+
alias nvim-kickstart='NVIM_APPNAME="nvim-kickstart" nvim'
162+
```
163+
When you run Neovim using `nvim-kickstart` alias it will use the alternative config directory and the matching local directory `~/.local/share/nvim-kickstart`. You can apply this approach to any Neovim distribution that you would like to try out.
152164
* What if I want to "uninstall" this configuration:
153165
* See [lazy.nvim uninstall](https://github.com/folke/lazy.nvim#-uninstalling) information
154166
* Are there any cool videos about this plugin?
155167
* Current iteration of kickstart (coming soon)
156168
* Here is one about the previous iteration of kickstart: [video introduction to Kickstart.nvim](https://youtu.be/stqUbv-5u2s). Note the install via init.lua no longer works as specified. Please follow the install instructions in this file instead as they're up to date.
169+
* Why is the kickstart `init.lua` a single file? Wouldn't it make sense to split it into multiple files?
170+
* The main purpose of kickstart is to serve as a teaching tool and a reference
171+
configuration that someone can easily `git clone` as a basis for their own.
172+
As you progress in learning Neovim and Lua, you might consider splitting `init.lua`
173+
into smaller parts. A fork of kickstart that does this while maintaining the exact
174+
same functionality is available here:
175+
* [kickstart-modular.nvim](https://github.com/dam9000/kickstart-modular.nvim)
176+
* Discussions on this topic can be found here:
177+
* [Restructure the configuration](https://github.com/nvim-lua/kickstart.nvim/issues/218)
178+
* [Reorganize init.lua into a multi-file setup](https://github.com/nvim-lua/kickstart.nvim/pull/473)
157179
158180
### Windows Installation
159181

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
}
@@ -486,6 +619,9 @@ cmp.setup {
486619
luasnip.lsp_expand(args.body)
487620
end,
488621
},
622+
completion = {
623+
completeopt = 'menu,menuone,noinsert',
624+
},
489625
mapping = cmp.mapping.preset.insert {
490626
['<C-n>'] = cmp.mapping.select_next_item(),
491627
['<C-p>'] = cmp.mapping.select_prev_item(),
@@ -518,6 +654,7 @@ cmp.setup {
518654
sources = {
519655
{ name = 'nvim_lsp' },
520656
{ name = 'luasnip' },
657+
{ name = 'path' },
521658
},
522659
}
523660
vim.wo.relativenumber = true

0 commit comments

Comments
 (0)