Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
257 changes: 214 additions & 43 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ vim.diagnostic.config {
}

vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist, { desc = 'Open diagnostic [Q]uickfix list' })
vim.diagnostic.config { virtual_text = false }

-- Exit terminal mode in the builtin terminal with a shortcut that is a bit easier
-- for people to discover. Otherwise, you normally need to press <C-\><C-n>, which
Expand Down Expand Up @@ -230,6 +231,17 @@ vim.api.nvim_create_autocmd('TextYankPost', {
callback = function() vim.hl.on_yank() end,
})

vim.api.nvim_create_autocmd('BufWritePre', {
desc = 'Remove trailing whitespace on save',
group = vim.api.nvim_create_augroup('kickstart-trim-whitespace', { clear = true }),
pattern = '*',
callback = function()
local save_cursor = vim.fn.getpos(".")
vim.cmd([[%s/\s\+$//e]])
vim.fn.setpos(".", save_cursor)
end,
})

-- [[ Install `lazy.nvim` plugin manager ]]
-- See `:help lazy.nvim.txt` or https://github.com/folke/lazy.nvim for more info
local lazypath = vim.fn.stdpath 'data' .. '/lazy/lazy.nvim'
Expand All @@ -253,22 +265,116 @@ rtp:prepend(lazypath)
-- To update plugins you can run
-- :Lazy update
--
local projectionist_config = function ()
vim.cmd [[
let g:projectionist_heuristics ={
\ "spec/*.rb": {
\ "app/*.rb": { "alternate": "spec/{}_spec.rb", "type": "source"},
\ "app/javascript/src/*.js": { "alternate": "spec/javascript/{}.test.js", "type": "source"},
\ "app/javascript/src/*.jsx": { "alternate": "spec/javascript/{}.test.js", "type": "source"},
\ "lib/*.rb": { "alternate": "spec/{}_spec.rb", "type": "source"},
\ "spec/*_spec.rb": { "alternate": ["app/{}.rb","lib/{}.rb"], "type": "test"},
\ "spec/javascript/*.test.js": { "alternate": ["app/javascript/src/{}.js", "app/javascript/src/{}.jsx"], "type": "test"},
\ },
\ "*_test.go": {
\ "*.go": { "alternate": "{}_test.go", "type": "test" },
\ "*_test.go": { "alternate": "{}.go", "type": "source" },
\ },
\ "*.erb": {
\ "*.html.erb": { "alternate": "{}.text.erb", "type": "text" },
\ "*.text.erb": { "alternate": "{}.html.erb", "type": "html" },
\ }
\}
]]
end

-- NOTE: Here is where you install your plugins.
require('lazy').setup({
-- NOTE: Plugins can be added via a link or github org/name. To run setup automatically, use `opts = {}`
{ 'NMAC427/guess-indent.nvim', opts = {} },

-- Alternatively, use `config = function() ... end` for full control over the configuration.
-- If you prefer to call `setup` explicitly, use:
-- {
-- 'lewis6991/gitsigns.nvim',
-- config = function()
-- require('gitsigns').setup({
-- -- Your gitsigns configuration here
-- })
-- end,
-- }
-- NOTE: Plugins can be added with a link (or for a github repo: 'owner/repo' link).
--
'tpope/vim-sleuth', -- Detect tabstop and shiftwidth automatically
'nvim-lua/plenary.nvim',
'nvim-pack/nvim-spectre',
{
'ruifm/gitlinker.nvim',
dependencies = 'nvim-lua/plenary.nvim',
event = 'VeryLazy',
opts = { mapping = '<leader>gl' },
},

{
-- Map tools and actions based on the project
"tpope/vim-projectionist",
config = projectionist_config,
event = "VeryLazy",
},
{
'ruanyl/vim-gh-line',
},
{
'klen/nvim-test',
config = function()
-- NOTE: Plugins can also be added by using a table,
-- with the first argument being the link and the following
-- keys can be used to configure plugin behavior/loading/etc.
--
-- Use `opts = {}` to force a plugin to be loaded.
--
-- This is equivalent to:
-- require('Comment').setup({})
require('nvim-test').setup {
run = true, -- run tests (using for debug)
commands_create = true, -- create commands (TestFile, TestLast, ...)
filename_modifier = ':.', -- modify filenames before tests run(:h filename-modifiers)
silent = false, -- less notifications
term = 'terminal', -- a terminal to run ("terminal"|"toggleterm")
termOpts = {
direction = 'vertical', -- terminal's direction ("horizontal"|"vertical"|"float")
width = 96, -- terminal's width (for vertical|float)
height = 24, -- terminal's height (for horizontal|float)
go_back = false, -- return focus to original window after executing
stopinsert = 'auto', -- exit from insert mode (true|false|"auto")
keep_one = true, -- keep only one terminal for testing
},
runners = { -- setup tests runners
cs = 'nvim-test.runners.dotnet',
go = 'nvim-test.runners.go-test',
haskell = 'nvim-test.runners.hspec',
javascriptreact = 'nvim-test.runners.jest',
javascript = 'nvim-test.runners.jest',
lua = 'nvim-test.runners.busted',
python = 'nvim-test.runners.pytest',
ruby = 'nvim-test.runners.rspec',
rust = 'nvim-test.runners.cargo-test',
typescript = 'nvim-test.runners.jest',
typescriptreact = 'nvim-test.runners.jest',
},

require('nvim-test.runners.jest'):setup {
command = '~/node_modules/.bin/jest', -- a command to run the test runner
args = { '--collectCoverage=false' }, -- default arguments
env = { CUSTOM_VAR = 'value' }, -- custom environment variables

file_pattern = '\\v(__tests__/.*|(spec|test))\\.(js|jsx|coffee|ts|tsx)$', -- determine whether a file is a testfile
find_files = { '{name}.test.{ext}', '{name}.spec.{ext}' }, -- find testfile for a file

filename_modifier = ':.', -- modify filename before tests run (:h filename-modifiers)
working_directory = nil, -- set working directory (cwd by default)
},
require('nvim-test.runners.rspec'):setup {
command = 'bundle',
},
}
end,
},
-- "gc" to comment visual regions/lines
{ 'numToStr/Comment.nvim', opts = {} },
{
'stevearc/oil.nvim',
opts = {},
-- Optional dependencies
dependencies = { 'nvim-tree/nvim-web-devicons' },
},
-- Here is a more advanced example where we pass configuration
-- options to `gitsigns.nvim`.
--
Expand Down Expand Up @@ -315,13 +421,22 @@ require('lazy').setup({
icons = { mappings = vim.g.have_nerd_font },

-- Document existing key chains
spec = {
{ '<leader>s', group = '[S]earch', mode = { 'n', 'v' } },
{ '<leader>t', group = '[T]oggle' },
{ '<leader>h', group = 'Git [H]unk', mode = { 'n', 'v' } }, -- Enable gitsigns recommended keymaps first
{ 'gr', group = 'LSP Actions', mode = { 'n' } },
},
},
require('which-key').register {
['<leader>c'] = { name = '[C]ode', _ = 'which_key_ignore' },
['<leader>d'] = { name = '[D]ocument', _ = 'which_key_ignore' },
['<leader>r'] = { name = '[R]ename', _ = 'which_key_ignore' },
['<leader>s'] = { name = '[S]earch', _ = 'which_key_ignore' },
['<leader>w'] = { name = '[W]orkspace', _ = 'which_key_ignore' },
-- ['<leader>t'] = { name = '[T]oggle', _ = 'which_key_ignore' },
['<leader>h'] = { name = 'Git [H]unk', _ = 'which_key_ignore' },
['<leader>t'] = { '<cmd>TestFile<cr>', 'TestFile' },
['<leader>T'] = { '<cmd>TestNearest<cr>', 'TestNearest' },
}
-- visual mode
require('which-key').register({
['<leader>h'] = { 'Git [H]unk' },
}, { mode = 'v' })
end,
},

-- NOTE: Plugins can specify dependencies.
Expand Down Expand Up @@ -358,7 +473,12 @@ require('lazy').setup({
cond = function() return vim.fn.executable 'make' == 1 end,
},
{ 'nvim-telescope/telescope-ui-select.nvim' },

{
"nvim-telescope/telescope-live-grep-args.nvim" ,
-- This will not install any breaking changes.
-- For major updates, this must be adjusted manually.
version = "^1.0.0",
},
-- Useful for getting pretty icons, but requires a Nerd Font.
{ 'nvim-tree/nvim-web-devicons', enabled = vim.g.have_nerd_font },
},
Expand Down Expand Up @@ -402,20 +522,34 @@ require('lazy').setup({
-- Enable Telescope extensions if they are installed
pcall(require('telescope').load_extension, 'fzf')
pcall(require('telescope').load_extension, 'ui-select')
pcall(require('telescope').load_extension "live_grep_args")

-- See `:help telescope.builtin`
local builtin = require 'telescope.builtin'
vim.keymap.set('n', '<leader>sh', builtin.help_tags, { desc = '[S]earch [H]elp' })
vim.keymap.set('n', '<leader>sk', builtin.keymaps, { desc = '[S]earch [K]eymaps' })
vim.keymap.set('n', '<leader>sf', builtin.find_files, { desc = '[S]earch [F]iles' })
vim.keymap.set('n', '<leader>f', builtin.find_files, { desc = '[S]earch [F]iles' })
vim.keymap.set('n', '<leader>ss', builtin.builtin, { desc = '[S]earch [S]elect Telescope' })
vim.keymap.set({ 'n', 'v' }, '<leader>sw', builtin.grep_string, { desc = '[S]earch current [W]ord' })
vim.keymap.set('n', '<leader>sg', builtin.live_grep, { desc = '[S]earch by [G]rep' })
vim.keymap.set('n', '<leader>sw', builtin.grep_string, { desc = '[S]earch current [W]ord' })
vim.keymap.set('n', '<leader>gd', builtin.grep_string, { desc = '[G] to [D]efinition' })
vim.keymap.set('n', '<leader>F', builtin.live_grep, { desc = '[S]earch by [G]rep' })
vim.keymap.set('n', '<leader>sd', builtin.diagnostics, { desc = '[S]earch [D]iagnostics' })
vim.keymap.set('n', '<leader>sr', builtin.resume, { desc = '[S]earch [R]esume' })
vim.keymap.set('n', '<leader>s.', builtin.oldfiles, { desc = '[S]earch Recent Files ("." for repeat)' })
vim.keymap.set('n', '<leader>sc', builtin.commands, { desc = '[S]earch [C]ommands' })
vim.keymap.set('n', '<leader><leader>', builtin.buffers, { desc = '[ ] Find existing buffers' })
vim.keymap.set('n', '<leader>S', '<cmd>lua require("spectre").toggle()<CR>', {
desc = "Toggle Spectre"
})
vim.keymap.set('n', '<leader>sw', '<cmd>lua require("spectre").open_visual({select_word=true})<CR>', {
desc = "Search current word"
})
vim.keymap.set('v', '<leader>sw', '<esc><cmd>lua require("spectre").open_visual()<CR>', {
desc = "Search current word"
})
vim.keymap.set('n', '<leader>sp', '<cmd>lua require("spectre").open_file_search({select_word=true})<CR>', {
desc = "Search on current file"
})

-- This runs on LSP attach per buffer (see main LSP attach function in 'neovim/nvim-lspconfig' config for more info,
-- it is better explained there). This allows easily switching between pickers if you prefer using something else!
Expand Down Expand Up @@ -595,23 +729,58 @@ require('lazy').setup({
end,
})

local hardmode = true
if hardmode then
-- Show an error message if a disabled key is pressed
local msg = [[<cmd>echohl Error | echo "KEY DISABLED" | echohl None<CR>]]

-- Disable arrow keys in insert mode with a styled message
vim.api.nvim_set_keymap('i', '<Up>', '<C-o>' .. msg, { noremap = true, silent = false })
vim.api.nvim_set_keymap('i', '<Down>', '<C-o>' .. msg, { noremap = true, silent = false })
vim.api.nvim_set_keymap('i', '<Left>', '<C-o>' .. msg, { noremap = true, silent = false })
vim.api.nvim_set_keymap('i', '<Right>', '<C-o>' .. msg, { noremap = true, silent = false })
vim.api.nvim_set_keymap('i', '<Del>', '<C-o>' .. msg, { noremap = true, silent = false })
vim.api.nvim_set_keymap('i', '<BS>', '<C-o>' .. msg, { noremap = true, silent = false })

-- Disable arrow keys in normal mode with a styled message
vim.api.nvim_set_keymap('n', '<Up>', msg, { noremap = true, silent = false })
vim.api.nvim_set_keymap('n', '<Down>', msg, { noremap = true, silent = false })
vim.api.nvim_set_keymap('n', '<Left>', msg, { noremap = true, silent = false })
vim.api.nvim_set_keymap('n', '<Right>', msg, { noremap = true, silent = false })
vim.api.nvim_set_keymap('n', '<BS>', msg, { noremap = true, silent = false })
end
vim.api.nvim_create_autocmd('LspDetach', {
group = vim.api.nvim_create_augroup('kickstart-lsp-detach', { clear = true }),
callback = function(event)
vim.lsp.buf.clear_references()
vim.api.nvim_clear_autocmds { group = 'kickstart-lsp-highlight', buffer = event.buf }
end,
})

-- LSP servers and clients are able to communicate to each other what features they support.
-- By default, Neovim doesn't support everything that is in the LSP specification.
-- When you add nvim-cmp, luasnip, etc. Neovim now has *more* capabilities.
-- So, we create new capabilities with nvim cmp, and then broadcast that to the servers.
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = vim.tbl_deep_extend('force', capabilities, require('cmp_nvim_lsp').default_capabilities())

-- Enable the following language servers
-- Feel free to add/remove any LSPs that you want here. They will automatically be installed.
-- See `:help lsp-config` for information about keys and how to configure
---@type table<string, vim.lsp.Config>
local servers = {
-- clangd = {},
-- gopls = {},
solargraph = {},
-- pyright = {},
-- rust_analyzer = {},
--
-- Some languages (like typescript) have entire language plugins that can be useful:
-- https://github.com/pmizio/typescript-tools.nvim
--
-- But for many setups, the LSP (`ts_ls`) will work just fine
-- ts_ls = {},

stylua = {}, -- Used to format Lua code
ts_ls = {},
--

-- Special Lua Config, as recommended by neovim help docs
lua_ls = {
Expand Down Expand Up @@ -662,10 +831,18 @@ require('lazy').setup({

require('mason-tool-installer').setup { ensure_installed = ensure_installed }

for name, server in pairs(servers) do
vim.lsp.config(name, server)
vim.lsp.enable(name)
end
require('mason-lspconfig').setup {
handlers = {
function(server_name)
local server = servers[server_name] or {}
-- This handles overriding only values explicitly passed
-- by the server configuration above. Useful when disabling
-- certain features of an LSP (for example, turning off formatting for ts_ls)
server.capabilities = vim.tbl_deep_extend('force', {}, capabilities, server.capabilities or {})
require('lspconfig')[server_name].setup(server)
end,
},
}
end,
},

Expand All @@ -686,16 +863,10 @@ require('lazy').setup({
opts = {
notify_on_error = false,
format_on_save = function(bufnr)
-- You can specify filetypes to autoformat on save here:
local enabled_filetypes = {
-- lua = true,
-- python = true,
}
if enabled_filetypes[vim.bo[bufnr].filetype] then
return { timeout_ms = 500 }
else
return nil
end
-- Disable "format_on_save lsp_fallback" for languages that don't
-- have a well standardized coding style. You can add additional
-- languages here or re-enable it for the disabled ones.
return
end,
default_format_opts = {
lsp_format = 'fallback', -- Use external formatters if configured below, otherwise use LSP formatting. Set to `false` to disable LSP formatting entirely.
Expand Down Expand Up @@ -948,9 +1119,9 @@ require('lazy').setup({
-- Uncomment any of the lines below to enable them (you will need to restart nvim).
--
-- require 'kickstart.plugins.debug',
-- require 'kickstart.plugins.indent_line',
require 'kickstart.plugins.indent_line',
-- require 'kickstart.plugins.lint',
-- require 'kickstart.plugins.autopairs',
require 'kickstart.plugins.autopairs',
-- require 'kickstart.plugins.neo-tree',
-- require 'kickstart.plugins.gitsigns', -- adds gitsigns recommended keymaps

Expand Down
Loading
Loading