Created
January 27, 2025 18:14
-
-
Save aleksejkozin/3ea9cc9a4b62c234049a8ea372ed5c5f to your computer and use it in GitHub Desktop.
init.lua
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[ | |
===================================================================== | |
==================== READ THIS BEFORE CONTINUING ==================== | |
===================================================================== | |
Kickstart.nvim is *not* a distribution. | |
Kickstart.nvim is a template for your own configuration. | |
The goal is that you can read every line of code, top-to-bottom, understand | |
what your configuration is doing, and modify it to suit your needs. | |
Once you've done that, you should start exploring, configuring and tinkering to | |
explore Neovim! | |
If you don't know anything about Lua, I recommend taking some time to read through | |
a guide. One possible example: | |
- https://learnxinyminutes.com/docs/lua/ | |
And then you can explore or search through `:help lua-guide` | |
Kickstart Guide: | |
I have left several `:help X` comments throughout the init.lua | |
You should run that command and read that help section for more information. | |
In addition, I have some `NOTE:` items throughout the file. | |
These are for you, the reader to help understand what is happening. Feel free to delete | |
them once you know what you're doing, but they should serve as a guide for when you | |
are first encountering a few different constructs in your nvim config. | |
I hope you enjoy your Neovim journey, | |
- TJ | |
P.S. You can delete this when you're done too. It's your config now :) | |
--]] | |
-- Set <space> as the leader key | |
-- See `:help mapleader` | |
-- NOTE: Must happen before plugins are required (otherwise wrong leader will be used) | |
vim.g.mapleader = " " | |
vim.g.maplocalleader = " " | |
vim.o.showtabline = 0 | |
vim.o.spell = true | |
vim.o.spelllang = "ru_ru,en_us" | |
vim.o.expandtab = false | |
vim.o.tabstop = 4 -- A tab character displays as 2 spaces | |
vim.o.shiftwidth = 4 -- Indentation levels are 2 spaces wide | |
vim.o.softtabstop = 4 -- Tabs visually behave as 2 spaces | |
vim.o.spellcapcheck = '' | |
-- vim.cmd('set shell=zsh') | |
-- vim.cmd('set shellcmdflag=-ic') | |
-- vim.o.shell = "/bin/zsh" | |
-- vim.g.copilot_proxy = '104.37.66.50:3128' | |
-- vim.g.copilot_proxy_strict_ssl = true | |
-- vim.g.copilot_no_tab_map = true | |
-- vim.o.foldenable = false | |
-- vim.o.nofoldenable = true | |
-- vim.o.autoread = true | |
-- vim.o.autowrite = true | |
-- vim.o.autowriteall = true | |
-- vim.o.awa = vim.o.autowriteall | |
-- vim.cmd [[ | |
-- augroup defaults | |
-- autocmd TextChanged,TextChangedI * silent write | |
-- augroup end | |
-- ]] | |
-- fugitive diffs in full screen | |
-- vim.api.nvim_command("au User FugitiveIndex nmap <buffer> dt :Gtabedit <Plug><cfile><Bar>Gdiffsplit<CR>") | |
-- Install package manager | |
-- https://github.com/folke/lazy.nvim | |
-- `:help lazy.nvim.txt` for more info | |
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", -- latest stable release | |
lazypath, | |
}) | |
end | |
vim.opt.rtp:prepend(lazypath) | |
-- NOTE: Here is where you install your plugins. | |
-- You can configure plugins using the `config` key. | |
-- | |
-- You can also configure plugins after the setup call, | |
-- as they will be available in your neovim runtime. | |
require("lazy").setup({ | |
-- NOTE: First, some plugins that don't require any configuration | |
{ | |
"kylechui/nvim-surround", | |
version = "*", -- Use for stability; omit to use `main` branch for the latest features | |
event = "VeryLazy", | |
config = function() | |
require("nvim-surround").setup({ | |
-- Configuration here, or leave empty to use defaults | |
}) | |
end | |
}, | |
{ | |
'phaazon/hop.nvim', | |
config = function() | |
require("hop").setup() | |
end | |
}, | |
{ | |
"pocco81/auto-save.nvim", | |
config = function() | |
require('auto-save').setup({ | |
enabled = true, | |
}) | |
end | |
}, | |
{ | |
"kdheepak/lazygit.nvim", | |
dependencies = { | |
"nvim-lua/plenary.nvim", | |
}, | |
}, | |
"RRethy/vim-illuminate", | |
"godlygeek/tabular", | |
{ | |
"David-Kunz/gen.nvim", | |
opts = { | |
model = "mistral", | |
} | |
}, | |
-- { | |
-- 'windwp/nvim-autopairs', | |
-- event = "InsertEnter", | |
-- config = true | |
-- }, | |
"LudoPinelli/comment-box.nvim", | |
-- Tests | |
"mfussenegger/nvim-dap", | |
{ | |
"mfussenegger/nvim-dap-python", | |
ft="python", | |
dependencies = { | |
"mfussenegger/nvim-dap", | |
}, | |
config = function() | |
-- SETUP: pip install debugpy | |
local dap_python = require("dap-python") | |
dap_python.setup() | |
dap_python.test_runner = "pytest" | |
end, | |
}, | |
'mxsdev/nvim-dap-vscode-js', | |
{ | |
'rcarriga/nvim-dap-ui', | |
dependencies = { | |
"mfussenegger/nvim-dap", | |
}, | |
config = function() | |
require("dapui").setup({ | |
-- expand_lines = true, | |
-- icons = { expanded = "", collapsed = "", circular = "" }, | |
-- mappings = { | |
-- -- Use a table to apply multiple mappings | |
-- expand = { "<CR>", "<2-LeftMouse>" }, | |
-- open = "o", | |
-- remove = "d", | |
-- edit = "e", | |
-- repl = "r", | |
-- toggle = "t", | |
-- }, | |
layouts = { | |
{ | |
elements = { | |
{ id = "breakpoints", size = 0.2 }, | |
{ id = "stacks", size = 0.3 }, | |
{ id = "scopes", size = 0.5 }, | |
}, | |
size = 0.33, | |
position = "left", | |
}, | |
{ | |
elements = { | |
-- { id = "repl", size = 0.45 }, | |
{ id = "console", size = 1.0 }, | |
}, | |
size = 0.27, | |
position = "bottom", | |
}, | |
}, | |
-- floating = { | |
-- max_height = 0.9, | |
-- max_width = 0.5, -- Floats will be treated as percentage of your screen. | |
-- border = vim.g.border_chars, -- Border style. Can be 'single', 'double' or 'rounded' | |
-- mappings = { | |
-- close = { "q", "<Esc>" }, | |
-- }, | |
-- }, | |
}) | |
end | |
}, | |
{ | |
"microsoft/vscode-js-debug", | |
lazy = true, | |
-- build = "npm install --legacy-peer-deps && npx gulp vsDebugServerBundle && rm -rf out && mv dist out", | |
config = function() | |
end | |
}, | |
{ | |
"ray-x/go.nvim", | |
dependencies = { -- optional packages | |
"ray-x/guihua.lua", | |
"neovim/nvim-lspconfig", | |
"nvim-treesitter/nvim-treesitter", | |
}, | |
config = function() | |
require("go").setup() | |
end, | |
event = {"CmdlineEnter"}, | |
ft = {"go", 'gomod'}, | |
build = ':lua require("go.install").update_all_sync()' -- if you need to install/update all binaries | |
}, | |
{ "folke/neodev.nvim", opts = {} }, | |
-- { | |
-- "microsoft/vscode-node-debug2", | |
-- -- lazy = true, | |
-- build = "npm install && NODE_OPTIONS=--no-experimental-fetch npm run build" | |
-- }, | |
{ | |
"nvim-neotest/neotest", | |
dependencies = { | |
"nvim-neotest/nvim-nio", | |
"folke/neodev.nvim", | |
"nvim-treesitter/nvim-treesitter", | |
"rcarriga/nvim-dap-ui", | |
"nvim-lua/plenary.nvim", | |
"antoinemadec/FixCursorHold.nvim", | |
"nvim-neotest/neotest-python", | |
"haydenmeade/neotest-jest", | |
}, | |
config = function() | |
require("dap-vscode-js").setup({ | |
debugger_path = os.getenv('HOME') .. '/projects/vscode-js-debug', | |
adapters = { | |
'pwa-node', | |
'pwa-chrome', | |
'pwa-msedge', | |
'node-terminal', | |
'pwa-extensionHost', | |
} | |
}) | |
local dap = require('dap') | |
dap.adapters.lldb = { | |
type = 'executable', | |
command = '/opt/homebrew/opt/llvm/bin/lldb-dap', -- adjust as needed, must be absolute path | |
name = 'lldb' | |
} | |
for _, language in ipairs({ "typescript", "javascript" }) do | |
require("dap").configurations[language] = { | |
{ | |
type = 'pwa-node', | |
request = 'launch', | |
name = 'Launch Yarn Dev', | |
runtimeExecutable = 'yarn', | |
runtimeArgs = { 'dev' }, | |
cwd = vim.fn.getcwd(), | |
sourceMaps = true, | |
protocol = 'inspector', | |
console = 'integratedTerminal', | |
}, | |
{ | |
type = "pwa-node", | |
request = "launch", | |
name = "Launch file", | |
program = "${file}", | |
cwd = "${workspaceFolder}", | |
}, | |
{ | |
type = "lldb", | |
request = "launch", | |
name = "Launch Node.js Debug", | |
program = "/Users/akozin/projects/node/out/Debug/node", | |
args = function(_, input_args) | |
local test_file = vim.fn.expand("%:p") -- Get the current file path | |
-- Use the argument passed via :DapNew | |
-- local test_name = input_args and input_args[1] or nil | |
-- | |
-- if not test_name then | |
-- error("Test name must be provided as an argument to :DapNew") | |
-- end | |
return { | |
"--experimental-sqlite", | |
test_file, | |
-- "--test-name-pattern", | |
-- test_name, | |
} | |
end, | |
cwd = "${workspaceFolder}", | |
-- cwd = vim.fn.getcwd(), | |
stopOnEntry = false, | |
runInTerminal = false, | |
}, | |
{ | |
type = "pwa-node", | |
request = "attach", | |
name = "Attach", | |
processId = require 'dap.utils'.pick_process, | |
cwd = "${workspaceFolder}", | |
}, | |
} | |
end | |
require("neotest").setup({ | |
-- log_level = vim.log.levels.DEBUG, | |
adapters = { | |
require("neotest-python")({ | |
dap = { justMyCode = false }, | |
args = {"--log-level", "DEBUG"}, | |
runner = "pytest", | |
python = ".venv/bin/python", | |
env = { CI = true }, | |
cwd = function(path) | |
return vim.fn.getcwd() | |
end, | |
}), | |
require("neotest-jest")({ | |
jestCommand = "yarn test", | |
env = { CI = true }, | |
cwd = function(path) | |
return vim.fn.getcwd() | |
end, | |
}), | |
}, | |
}) | |
end | |
}, | |
-- 'axkirillov/hbac.nvim', | |
'jose-elias-alvarez/typescript.nvim', | |
-- { | |
-- 'jose-elias-alvarez/null-ls.nvim', | |
-- config = function() | |
-- require("null-ls").setup({ | |
-- sources = { | |
-- require("typescript.extensions.null-ls.code-actions"), | |
-- }, | |
-- }) | |
-- end | |
-- }, | |
'nvim-tree/nvim-tree.lua', | |
-- 'preservim/nerdtree', | |
'nvim-tree/nvim-web-devicons', | |
'xiyaowong/transparent.nvim', | |
-- Git related plugins | |
"tpope/vim-fugitive", | |
"tpope/vim-rhubarb", | |
"nvim-tree/nvim-web-devicons", | |
"sindrets/diffview.nvim", | |
-- 'lewis6991/gitsigns', | |
-- Detect tabstop and shiftwidth automatically | |
"tpope/vim-sleuth", | |
-- NOTE: This is where your plugins related to LSP can be installed. | |
-- The configuration is done below. Search for lspconfig to find it below. | |
{ | |
-- LSP Configuration & Plugins | |
"neovim/nvim-lspconfig", | |
dependencies = { | |
-- Automatically install LSPs to stdpath for neovim | |
{ "williamboman/mason.nvim", config = true }, | |
"williamboman/mason-lspconfig.nvim", | |
-- Useful status updates for LSP | |
-- NOTE: `opts = {}` is the same as calling `require('fidget').setup({})` | |
{ "j-hui/fidget.nvim", tag = "legacy", opts = {} }, | |
-- Additional lua configuration, makes nvim stuff amazing! | |
"folke/neodev.nvim", | |
}, | |
}, | |
{ | |
-- Autocompletion | |
"hrsh7th/nvim-cmp", | |
dependencies = { | |
-- Snippet Engine & its associated nvim-cmp source | |
"L3MON4D3/LuaSnip", | |
-- "saadparwaiz1/cmp_luasnip", | |
-- Adds LSP completion capabilities | |
"hrsh7th/cmp-nvim-lsp", | |
"hrsh7th/cmp-buffer", | |
"hrsh7th/cmp-path", | |
"hrsh7th/cmp-cmdline", | |
-- Adds a number of user-friendly snippets | |
"rafamadriz/friendly-snippets", | |
}, | |
}, | |
-- { | |
-- "epwalsh/pomo.nvim", | |
-- version = "*", -- Recommended, use latest release instead of latest commit | |
-- lazy = true, | |
-- cmd = { "TimerStart", "TimerRepeat", "TimerSession" }, | |
-- dependencies = { | |
-- -- Optional, but highly recommended if you want to use the "Default" timer | |
-- "rcarriga/nvim-notify", | |
-- }, | |
-- opts = { | |
-- -- See below for full list of options 👇 | |
-- }, | |
-- }, | |
-- 'github/copilot.vim', | |
-- Useful plugin to show you pending keybinds. | |
{ "folke/which-key.nvim", opts = {} }, | |
{ | |
-- Adds git related signs to the gutter, as well as utilities for managing changes | |
"lewis6991/gitsigns.nvim", | |
opts = { | |
-- See `:help gitsigns.txt` | |
signs = { | |
add = { text = "+" }, | |
change = { text = "~" }, | |
delete = { text = "_" }, | |
topdelete = { text = "‾" }, | |
changedelete = { text = "~" }, | |
}, | |
current_line_blame = false, | |
current_line_blame_opts = { | |
delay = 100, | |
ignore_whitespace = true, | |
}, | |
on_attach = function(bufnr) | |
local gs = package.loaded.gitsigns | |
local function map(mode, l, r, opts) | |
opts = opts or {} | |
opts.buffer = bufnr | |
vim.keymap.set(mode, l, r, opts) | |
end | |
-- Navigation | |
map('n', ']c', function() | |
if vim.wo.diff then return ']c' end | |
vim.schedule(function() gs.next_hunk() end) | |
return '<Ignore>' | |
end, { expr = true }) | |
map('n', '[c', function() | |
if vim.wo.diff then return '[c' end | |
vim.schedule(function() gs.prev_hunk() end) | |
return '<Ignore>' | |
end, { expr = true }) | |
-- Actions | |
map('n', '<leader>hs', gs.stage_hunk, { desc = "Stage hunk" }) | |
map('n', '<leader>hr', gs.reset_hunk, { desc = "Reset hunk" }) | |
map('v', '<leader>hs', function() gs.stage_hunk { vim.fn.line('.'), vim.fn.line('v') } end, | |
{ desc = "Stage hunk" }) | |
map('v', '<leader>hr', function() gs.reset_hunk { vim.fn.line('.'), vim.fn.line('v') } end, | |
{ desc = "Reset hunk" }) | |
map('n', '<leader>hS', gs.stage_buffer, { desc = "Stage buffer" }) | |
map('n', '<leader>hu', gs.undo_stage_hunk, { desc = "Undo stage hunk" }) | |
map('n', '<leader>hR', gs.reset_buffer, { desc = "Reset buffer" }) | |
map('n', '<leader>hp', gs.preview_hunk, { desc = "Preview hunk" }) | |
map('n', '<leader>hb', function() gs.blame_line { full = true } end, { desc = "Blame line" }) | |
map('n', '<leader>tb', gs.toggle_current_line_blame, { desc = "Toggle current line blame" }) | |
map('n', '<leader>hd', gs.diffthis, { desc = "Diff this" }) | |
map('n', '<leader>hD', function() gs.diffthis('~') end, { desc = "Diff this ~" }) | |
map('n', '<leader>td', gs.toggle_deleted, { desc = "Toggle Deleted" }) | |
-- Text object | |
map({ 'o', 'x' }, 'ih', ':<C-U>Gitsigns select_hunk<CR>') | |
vim.keymap.set( | |
"n", | |
"<leader>gp", | |
require("gitsigns").prev_hunk, | |
{ buffer = bufnr, desc = "[G]o to [P]revious Hunk" } | |
) | |
vim.keymap.set( | |
"n", | |
"<leader>gn", | |
require("gitsigns").next_hunk, | |
{ buffer = bufnr, desc = "[G]o to [N]ext Hunk" } | |
) | |
vim.keymap.set( | |
"n", | |
"<leader>ph", | |
require("gitsigns").preview_hunk, | |
{ buffer = bufnr, desc = "[P]review [H]unk" } | |
) | |
end, | |
}, | |
}, | |
-- { | |
-- -- Theme inspired by Atom | |
-- "navarasu/onedark.nvim", | |
-- priority = 1000, | |
-- config = function() | |
-- vim.cmd.colorscheme("onedark") | |
-- end, | |
-- }, | |
-- | |
{ | |
-- Theme inspired by Atom | |
"rebelot/kanagawa.nvim", | |
priority = 200, | |
config = function() | |
vim.cmd.colorscheme("kanagawa") | |
vim.cmd.hi('SpellBad cterm=underline gui=underline guisp=NONE') | |
end, | |
}, | |
'fcpg/vim-fahrenheit', | |
{ | |
"bluz71/vim-moonfly-colors", | |
name = "moonfly", | |
lazy = false, | |
priority = 1000, | |
}, | |
-- { | |
-- 'sainnhe/sonokai', | |
-- priority = 5000, | |
-- config = function() | |
-- vim.cmd.colorscheme("sonokai") | |
-- end, | |
-- }, | |
-- { | |
-- -- Theme inspired by Atom | |
-- "morhetz/gruvbox", | |
-- priority = 500, | |
-- config = function() | |
-- vim.cmd.colorscheme("gruvbox") | |
-- end, | |
-- }, | |
{ | |
-- Set lualine as statusline | |
"nvim-lualine/lualine.nvim", | |
-- See `:help lualine.txt` | |
opts = { | |
options = { | |
icons_enabled = true, | |
theme = "moonfly", | |
component_separators = "|", | |
section_separators = "", | |
}, | |
sections = { | |
lualine_c = { { "filename", path = 1 } }, | |
lualine_x = {}, | |
}, | |
}, | |
}, | |
-- { | |
-- -- Add indentation guides even on blank lines | |
-- "lukas-reineke/indent-blankline.nvim", | |
-- main = "ibl", | |
-- opts = { }, | |
-- config = function() | |
-- require("ibl").setup({ | |
-- indent = { char = "┊" }, | |
-- whitespace = { | |
-- remove_blankline_trail = false, | |
-- }, | |
-- scope = { enabled = false }, | |
-- }) | |
-- end, | |
-- }, | |
-- "gc" to comment visual regions/lines | |
{ "numToStr/Comment.nvim", opts = {} }, | |
-- Fuzzy Finder (files, lsp, etc) | |
{ | |
"nvim-telescope/telescope.nvim", | |
branch = "0.1.x", | |
dependencies = { | |
"nvim-lua/plenary.nvim", | |
-- Fuzzy Finder Algorithm which requires local dependencies to be built. | |
-- Only load if `make` is available. Make sure you have the system | |
-- requirements installed. | |
{ | |
"nvim-telescope/telescope-fzf-native.nvim", | |
-- NOTE: If you are having trouble with this installation, | |
-- refer to the README for telescope-fzf-native for more instructions. | |
build = "make", | |
cond = function() | |
return vim.fn.executable("make") == 1 | |
end, | |
}, | |
}, | |
}, | |
{ | |
-- Highlight, edit, and navigate code | |
"nvim-treesitter/nvim-treesitter", | |
dependencies = { | |
"nvim-treesitter/nvim-treesitter-textobjects", | |
}, | |
build = ":TSUpdate", | |
}, | |
'MunifTanjim/nui.nvim', | |
'VonHeikemen/fine-cmdline.nvim', | |
'Vigemus/iron.nvim', | |
-- 'edluffy/hologram.nvim', | |
-- { | |
-- "pwntester/codeql.nvim", | |
-- dependencies = { | |
-- "MunifTanjim/nui.nvim", | |
-- "nvim-lua/telescope.nvim", | |
-- "kyazdani42/nvim-web-devicons", | |
-- { | |
-- 's1n7ax/nvim-window-picker', | |
-- version = 'v1.*', | |
-- opts = { | |
-- autoselect_one = true, | |
-- include_current = false, | |
-- filter_rules = { | |
-- bo = { | |
-- filetype = { | |
-- "codeql_panel", | |
-- "codeql_explorer", | |
-- "qf", | |
-- "TelescopePrompt", | |
-- "TelescopeResults", | |
-- "notify", | |
-- "noice", | |
-- "NvimTree", | |
-- "neo-tree", | |
-- }, | |
-- buftype = { 'terminal' }, | |
-- }, | |
-- }, | |
-- current_win_hl_color = '#e35e4f', | |
-- other_win_hl_color = '#44cc41', | |
-- }, | |
-- } | |
-- }, | |
-- opts = {} | |
-- }, | |
-- { | |
-- "vhyrro/luarocks.nvim", | |
-- priority = 1001, -- this plugin needs to run before anything else | |
-- opts = { | |
-- rocks = { "image.nvim", "magick" }, | |
-- }, | |
-- }, | |
-- { | |
-- "3rd/image.nvim", | |
-- ft = { "markdown" }, | |
-- dependencies = { | |
-- { | |
-- "nvim-treesitter/nvim-treesitter", | |
-- build = ":TSUpdate", | |
-- config = function() | |
-- require("nvim-treesitter.configs").setup({ | |
-- ensure_installed = { "markdown" }, | |
-- highlight = { enable = true }, | |
-- }) | |
-- end, | |
-- }, | |
-- }, | |
-- config = function() | |
-- require("image").setup({ | |
-- backend = "kitty", | |
-- integrations = { | |
-- markdown = { | |
-- enabled = true, | |
-- clear_in_insert_mode = true, | |
-- download_remote_images = true, | |
-- only_render_image_at_cursor = true, | |
-- filetypes = { "markdown", "vimwiki" }, -- markdown extensions (ie. quarto) can go here | |
-- }, | |
-- neorg = { | |
-- enabled = true, | |
-- clear_in_insert_mode = false, | |
-- download_remote_images = true, | |
-- only_render_image_at_cursor = false, | |
-- filetypes = { "norg" }, | |
-- }, | |
-- }, | |
-- max_width = nil, | |
-- max_height = nil, | |
-- max_width_window_percentage = nil, | |
-- max_height_window_percentage = 50, | |
-- kitty_method = "normal", | |
-- }) | |
-- end | |
-- }, | |
-- 'nvim-lua/popup.nvim', | |
-- 'nvim-lua/plenary.nvim', | |
-- { | |
-- 'nvim-telescope/telescope-media-files.nvim', | |
-- dependencies = { | |
-- "nvim-telescope/telescope.nvim", | |
-- } | |
-- } | |
-- "huggingface/llm.nvim", | |
-- NOTE: Next Step on Your Neovim Journey: Add/Configure additional "plugins" for kickstart | |
-- These are some example plugins that I've included in the kickstart repository. | |
-- Uncomment any of the lines below to enable them. | |
-- require 'kickstart.plugins.autoformat', | |
-- require 'kickstart.plugins.debug', | |
-- NOTE: The import below can automatically add your own plugins, configuration, etc from `lua/custom/plugins/*.lua` | |
-- You can use this folder to prevent any conflicts with this init.lua if you're interested in keeping | |
-- up-to-date with whatever is in the kickstart repo. | |
-- Uncomment the following line and add your plugins to `lua/custom/plugins/*.lua` to get going. | |
-- | |
-- For additional information see: https://github.com/folke/lazy.nvim#-structuring-your-plugins | |
-- { import = 'custom.plugins' }, | |
}, {}) | |
-- [[ Setting options ]] | |
-- See `:help vim.o` | |
-- NOTE: You can change these options as you wish! | |
-- Set highlight on search | |
vim.o.hlsearch = false | |
-- Make line numbers default | |
vim.wo.number = true | |
vim.wo.relativenumber = true | |
-- Enable mouse mode | |
vim.o.mouse = "a" | |
-- Sync clipboard between OS and Neovim. | |
-- Remove this option if you want your OS clipboard to remain independent. | |
-- See `:help 'clipboard'` | |
vim.o.clipboard = "unnamedplus" | |
-- Enable break indent | |
vim.o.breakindent = true | |
-- Save undo history | |
vim.o.undofile = true | |
-- Case-insensitive searching UNLESS \C or capital in search | |
vim.o.ignorecase = true | |
vim.o.smartcase = true | |
-- Keep signcolumn on by default | |
vim.wo.signcolumn = "yes" | |
-- Decrease update time | |
vim.o.updatetime = 250 | |
vim.o.timeoutlen = 300 | |
-- Set completeopt to have a better completion experience | |
vim.o.completeopt = "menuone,noselect" | |
-- NOTE: You should make sure your terminal supports this | |
vim.o.termguicolors = true | |
-- [[ Basic Keymaps ]] | |
-- Keymaps for better default experience | |
-- See `:help vim.keymap.set()` | |
vim.keymap.set({ "n", "v" }, "<Space>", "<Nop>", { silent = true }) | |
vim.keymap.set("n", ";", ":FineCmdline<CR>") | |
-- vim.keymap.set("n", ";", ":") | |
vim.keymap.set("n", "Q", ":q<CR>") | |
-- Remap for dealing with word wrap | |
vim.keymap.set("n", "k", "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true }) | |
vim.keymap.set("n", "j", "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true }) | |
-- [[ Disable Foldable for Diff ]] | |
-- vim.api.nvim_create_autocmd( | |
-- { 'BufReadPost', 'BufNewFile', 'BufAdd', 'BufWritePost', 'BufEnter', 'BufWinEnter', 'BufNew' }, | |
-- { | |
-- pattern = "*", | |
-- command = 'set nofoldenable' | |
-- }) | |
-- [[ Highlight on yank ]] | |
-- See `:help vim.highlight.on_yank()` | |
local highlight_group = vim.api.nvim_create_augroup("YankHighlight", { clear = true }) | |
vim.api.nvim_create_autocmd("TextYankPost", { | |
callback = function() | |
vim.highlight.on_yank() | |
end, | |
group = highlight_group, | |
pattern = "*", | |
}) | |
-- require("hbac").setup({ | |
-- autoclose = true, -- set autoclose to false if you want to close manually | |
-- threshold = 10, -- hbac will start closing unedited buffers once that number is reached | |
-- close_command = function(bufnr) | |
-- vim.api.nvim_buf_delete(bufnr, {}) | |
-- end, | |
-- close_buffers_with_windows = true, -- hbac will close buffers with associated windows if this option is `true` | |
-- telescope = { | |
-- -- See #telescope-configuration below | |
-- }, | |
-- }) | |
-- netrw | |
-- vim.g.netrw_fastbrowse = 0 | |
-- vim.g.netrw_banner = 0 | |
-- vim.g.netrw_sort_by = 'time' | |
-- vim.g.netrw_sort_direction = 'reverse' | |
-- vim.g.netrw_liststyle = 1 | |
-- vim.g.netrw_hide = 1 | |
-- vim.g.netrw_list_hide = '^\\.*/' | |
vim.g.loaded_netrw = 1 | |
vim.g.loaded_netrwPlugin = 1 | |
vim.opt.termguicolors = true | |
require("nvim-web-devicons").setup() | |
require("nvim-web-devicons").get_icons() | |
require("nvim-tree").setup({ | |
auto_reload_on_write = true, | |
open_on_tab = true, | |
update_focused_file = { | |
enable = true, | |
update_cwd = false, | |
ignore_list = {}, | |
}, | |
sort = { | |
folders_first = true, | |
sorter = 'modification_time', | |
}, | |
view = { | |
width = 80, | |
float = { | |
enable = true, | |
quit_on_focus_loss = true, | |
open_win_config = { | |
relative = "editor", | |
border = "rounded", | |
width = 150, | |
height = 58, | |
row = 1, | |
col = 25, | |
}, | |
} | |
}, | |
}) | |
require("typescript").setup({ }) | |
-- require('hologram').setup({ | |
-- auto_display = true -- WIP automatic markdown image display, may be prone to breaking | |
-- }) | |
-- require('llm').setup({ | |
-- backend = "ollama", | |
-- -- model = "codellama:latest", | |
-- model = "mistral:latest", | |
-- url = "http://localhost:11434/api/generate", | |
-- request_body = { | |
-- -- Modelfile options for the model you use | |
-- options = { | |
-- temperature = 0.2, | |
-- top_p = 0.95, | |
-- } | |
-- }, | |
-- debounce_ms = 150, | |
-- enable_suggestions_on_startup = true, | |
-- enable_suggestions_on_files = "*", | |
-- }) | |
-- /Users/akozin/Documents/codeql/codeql | |
-- require("codeql").setup { | |
-- results = { | |
-- max_paths = 10, | |
-- max_path_depth = nil, | |
-- }, | |
-- panel = { | |
-- width = 50, | |
-- pos = "botright", | |
-- group_by = "sink", -- "source" | |
-- show_filename = true, | |
-- long_filename = false, | |
-- context_lines = 3, | |
-- }, | |
-- max_ram = 32000, | |
-- job_timeout = 15000, | |
-- format_on_save = true, | |
-- additional_packs = { | |
-- "/Users/akozin/Documents/codeql", | |
-- "./codeql", | |
-- }, | |
-- mappings = { | |
-- run_query = { modes = { "n" }, lhs = "<space>qr", desc = "run query" }, | |
-- quick_eval = { modes = { "x", "n" }, lhs = "<space>qe", desc = "quick evaluate" }, | |
-- quick_eval_predicate = { modes = { "n" }, lhs = "<space>qp", desc = "quick evaluate enclosing predicate" }, | |
-- }, | |
-- } | |
-- | |
require('fine-cmdline').setup({ | |
cmdline = { | |
enable_keymaps = true, | |
smart_history = true, | |
prompt = ': ' | |
}, | |
popup = { | |
position = { | |
row = '50%', | |
col = '50%', | |
}, | |
size = { | |
width = '60%', | |
}, | |
border = { | |
style = 'rounded', | |
}, | |
win_options = { | |
winhighlight = 'Normal:Normal,FloatBorder:FloatBorder', | |
}, | |
}, | |
}) | |
-- [[ Configure Telescope ]] | |
-- See `:help telescope` and `:help telescope.setup()` | |
require("telescope").setup({ | |
-- extensions = { | |
-- media_files = { | |
-- -- filetypes whitelist | |
-- -- defaults to {"png", "jpg", "mp4", "webm", "pdf"} | |
-- filetypes = {"png", "webp", "jpg", "jpeg"}, | |
-- -- find command (defaults to `fd`) | |
-- find_cmd = "rg" | |
-- } | |
-- }, | |
defaults = { | |
path_display = { | |
"truncate", | |
}, | |
-- vimgrep_arguments = { | |
-- 'rg', | |
-- '--color=never', | |
-- '--no-heading', | |
-- '--with-filename', | |
-- '--line-number', | |
-- '--column', | |
-- '--multiline', | |
-- '--multiline-dotall', | |
-- '--only-matching', | |
-- '--pcre2', | |
-- }, | |
layout_strategy = "horizontal", | |
layout_config = { | |
horizontal = { height = 0.98, width = 0.98 }, | |
}, | |
-- mappings = { | |
-- i = { | |
-- ["<C-u>"] = false, | |
-- ["<C-d>"] = false, | |
-- ["<CR>"] = require("telescope.actions").select_tab, | |
-- }, | |
-- n = { | |
-- ["<CR>"] = require("telescope.actions").select_tab, | |
-- } | |
-- }, | |
}, | |
pickers = { | |
git_bcommits = { | |
mappings = { | |
i = { | |
["<C-u>"] = false, | |
["<C-d>"] = require("telescope.actions").select_default, | |
["<CR>"] = require("telescope.actions").select_tab, | |
}, | |
n = { | |
["<C-d>"] = require("telescope.actions").select_default, | |
["<CR>"] = require("telescope.actions").select_tab, | |
} | |
}, | |
}, | |
git_branches = { | |
mappings = { | |
i = { | |
["<C-u>"] = false, | |
["<C-d>"] = require("telescope.actions").select_default, | |
["<CR>"] = require("telescope.actions").select_tab, | |
}, | |
n = { | |
["<C-d>"] = require("telescope.actions").select_default, | |
["<CR>"] = require("telescope.actions").select_tab, | |
} | |
}, | |
} | |
} | |
}) | |
-- require('telescope').load_extension('hbac') | |
-- require('telescope').load_extension('media_files') | |
-- require'nvim-web-devicons'.get_icons() | |
-- Enable telescope fzf native, if installed | |
pcall(require("telescope").load_extension, "fzf") | |
-- See `:help telescope.builtin` | |
vim.keymap.set("n", "<leader><space>", require("telescope.builtin").current_buffer_fuzzy_find, { desc = "[?] Find recently opened files" }) | |
vim.keymap.set("n", "<leader>?", require("telescope.builtin").buffers, { desc = "[ ] Find existing buffers" }) | |
vim.keymap.set( | |
"n", | |
"<leader>/", | |
require("telescope.builtin").current_buffer_fuzzy_find, | |
{ desc = "[/] Fuzzily search in current buffer" } | |
) | |
vim.keymap.set("n", "<leader>gf", require("telescope.builtin").git_files, { desc = "Search [G]it [F]iles" }) | |
vim.keymap.set("n", "<leader>sf", require("telescope.builtin").find_files, { desc = "[S]earch [F]iles" }) | |
vim.keymap.set("n", "<leader>sh", require("telescope.builtin").help_tags, { desc = "[S]earch [H]elp" }) | |
vim.keymap.set("n", "<leader>sw", require("telescope.builtin").grep_string, { desc = "[S]earch current [W]ord" }) | |
vim.keymap.set("n", "<leader>sg", require("telescope.builtin").live_grep, { desc = "[S]earch by [G]rep" }) | |
vim.keymap.set("n", "<leader>sd", require("telescope.builtin").diagnostics, { desc = "[S]earch [D]iagnostics" }) | |
-- My old configs | |
vim.keymap.set("n", "R", vim.lsp.buf.rename, { desc = "[R]ename" }) | |
-- vim.keymap.set("n", "%", function() | |
-- local current_word = vim.fn.expand('<cword>') | |
-- vim.fn.setreg('+', current_word) | |
-- local clipboard_content = vim.fn.getreg('+') | |
-- clipboard_content = clipboard_content:gsub("^%s*(.-)%s*$", "%1") | |
-- vim.api.nvim_feedkeys(':%s/' .. clipboard_content .. '/', 'n', true) | |
-- end, { desc = "[%] Start replace with clipboard", noremap = true, silent = true }) | |
vim.keymap.set("n", "<leader>5", function() | |
end, { desc = "[%] Global replace in project", noremap = true, silent = true }) | |
vim.keymap.set("n", "fa", require("telescope.builtin").command_history, { desc = "[F]ind [A]all commands history" }) | |
vim.keymap.set("n", "FG", function() | |
require("telescope.builtin").find_files({ search_dirs = {"~/Downloads", "~/projects"}, hidden = true }) | |
end, { desc = "[F]ind [F]ile across the whole filesystem" }) | |
vim.keymap.set("n", "ff", require("telescope.builtin").git_files, { desc = "[F]ind [F]ile" }) | |
vim.keymap.set("n", "FF", require("telescope.builtin").find_files, { desc = "[F]ind [F]ile" }) | |
vim.keymap.set("n", "fh", require("telescope.builtin").help_tags, { desc = "[F]ind [H]elp" }) | |
vim.keymap.set("n", "fs", require("telescope.builtin").live_grep, { desc = "[F]ind [S]tring" }) | |
vim.keymap.set("n", "fD", require("telescope.builtin").diagnostics, { desc = "[F]ind [D]iagnostics" }) | |
vim.keymap.set("n", "fr", require("telescope.builtin").oldfiles, { desc = "[F]ind [P]revious opened files" }) | |
vim.keymap.set("n", "<Tab>", ":b#<CR>", { silent = true, desc = "Jump previous opened files" }) | |
-- vim.keymap.set("n", "<S-Tab>", "<C-w>", { silent = true, desc = "Jump previous opened files" }) | |
-- vim.keymap.set("n", "<leader>b", ":Explore<CR>", { desc = "[F]iles" }) | |
vim.keymap.set("n", "<leader>b", ":NvimTreeFindFileToggle<CR>zz", { desc = "[F]iles" }) | |
-- | |
-- Function to remove the current item from the quickfix list | |
local function remove_qf_item() | |
local cur_qf_idx = vim.fn.line('.') - 1 -- Get the current line index (0-based) | |
local qf_list = vim.fn.getqflist() -- Get the current quickfix list | |
table.remove(qf_list, cur_qf_idx + 1) -- Remove the current item (1-based index) | |
vim.fn.setqflist(qf_list, 'r') -- Update the quickfix list | |
vim.cmd(cur_qf_idx + 1 .. 'cfirst') -- Move to the first item in the list after deletion | |
vim.cmd('copen') -- Open the quickfix window | |
end | |
-- Create a command to call the remove function | |
vim.api.nvim_create_user_command('RemoveQFItem', remove_qf_item, {}) | |
-- Map 'dd' in the quickfix window to call the remove function | |
vim.api.nvim_create_autocmd('FileType', { | |
pattern = 'qf', | |
callback = function() | |
vim.keymap.set('n', 'dd', ':RemoveQFItem<CR>', { buffer = 0 }) -- Map 'dd' in the quickfix buffer | |
end, | |
}) | |
-- | |
-- diagnostics | |
local diagnostics_visible = true | |
local function toggle_diagnostics() | |
diagnostics_visible = not diagnostics_visible | |
if diagnostics_visible then | |
vim.diagnostic.show() | |
else | |
vim.diagnostic.hide() | |
end | |
end | |
vim.keymap.set("n", "_", toggle_diagnostics, { noremap = true, silent = true }) | |
-- git commands | |
-- vim.keymap.set("n", "gb", require("telescope.builtin").git_branches, { desc = "[G]it [B]ranches" }) | |
vim.keymap.set("n", "gc", require("telescope.builtin").git_bcommits, { desc = "[G]it [C]ommits" }) | |
vim.keymap.set("n", "gs", ":tab G<CR>", { desc = "[G]it [S]tatus" }) | |
vim.keymap.set("n", "gd", ":DiffviewOpen<CR>", { desc = "[G]it diff [O]pen" }) | |
vim.keymap.set("n", "gp", ":G pull<CR>", { desc = "[G]it [P]ull" }) | |
vim.keymap.set("n", "gP", ":G push<CR>", { desc = "[G]it [P]ush" }) | |
vim.keymap.set("n", "gt", ":G stash --include-untracked<CR>", { desc = "[G]it S[t]ash push" }) | |
vim.keymap.set("n", "gT", ":G stash pop<CR>", { desc = "[G]it S[t]ash pop" }) | |
vim.keymap.set("n", "gl", ":G log<CR>", { desc = "[G]it [L]og" }) | |
vim.keymap.set("n", "gh", ":DiffviewFileHistory %<CR>", { desc = "[G]it file [H]istory" }) | |
vim.keymap.set("n", "gH", ":DiffviewFileHistory<CR>", { desc = "[G]it branch [H]istory" }) | |
vim.keymap.set("n", "gq", ":DiffviewClose<CR>", { desc = "[G]it dif [Q]uit" }) | |
-- vim.keymap.set("n", "1", "<C-w>") | |
vim.keymap.set("n", "<leader>w", "<C-w>") | |
vim.keymap.set("n", "\\", ":HopWord<CR>", { desc = "Hop word" }) | |
-- [[ Debug ]] | |
vim.keymap.set("n", "tt", require("neotest").summary.toggle, { desc = "[T]est [T]ests" }) | |
vim.keymap.set("n", "tU", require("dapui").toggle, { desc = "[T]oggle dubug [U]I" }) | |
vim.keymap.set("n", "tu", ':Neotest output-panel<CR>', { desc = "[T]oggle dubug [U]I" }) | |
vim.keymap.set("n", "tr", function() | |
require("neotest").run.run() | |
end, { desc = "[T]est [R]un" }) | |
vim.keymap.set("n", "td", function() | |
require("neotest").run.run({ strategy = "dap" }) | |
end, { desc = "[T]est [D]ebug" }) | |
vim.keymap.set("n", "tb", require("dap").toggle_breakpoint, { desc = "[T]oggle [B]reakpoint" }) | |
vim.keymap.set("n", "tc", require("dap").continue, { desc = "Debug [C]continue" }) | |
vim.keymap.set("n", "tq", require("dap").terminate, { desc = "Debug [Q]uit" }) | |
vim.keymap.set("n", "tj", require("dap").step_over, { desc = "Debug step over" }) | |
vim.keymap.set("n", "tJ", require("dap").step_into, { desc = "Debug step into" }) | |
vim.keymap.set("n", "tK", require("dap").step_out, { desc = "Debug step out" }) | |
-- vim.keymap.set("n", "tk", require("dap").step_back, { desc = "Debug step back" }) | |
vim.keymap.set("n", "tR", require("dap").run_to_cursor, { desc = "Debug [R]un to cursor" }) | |
vim.keymap.set("n", "tk", require("dap.ui.widgets").hover, { desc = "Debug hover" }) | |
vim.keymap.set("t", "<Esc>", "<C-\\><C-n>", { desc = "Terminal exit" }) | |
vim.keymap.set("n", "Z", "zz", { desc = "Focus" }) | |
-- Map <C-J> in insert mode to accept Copilot suggestions | |
vim.api.nvim_set_keymap('i', '<C-J>', 'copilot#Accept("<CR>")', { silent = true, expr = true }) | |
vim.keymap.set('i', '<C-K>', '<Plug>(copilot-next)') | |
-- [[ Configure Treesitter ]] | |
-- See `:help nvim-treesitter` | |
require("nvim-treesitter.configs").setup({ | |
-- Add languages to be installed here that you want installed for treesitter | |
ensure_installed = { "dockerfile", "bash", "c", "cpp", "go", "lua", "python", "rust", "tsx", "typescript", "vimdoc", "vim" }, | |
-- Autoinstall languages that are not installed. Defaults to false (but you can change for yourself!) | |
auto_install = true, | |
highlight = { enable = true }, | |
indent = { enable = true }, | |
incremental_selection = { | |
enable = true, | |
keymaps = { | |
init_selection = "<c-space>", | |
node_incremental = "<c-space>", | |
scope_incremental = "<c-s>", | |
node_decremental = "<M-space>", | |
}, | |
}, | |
textobjects = { | |
select = { | |
enable = true, | |
lookahead = true, -- Automatically jump forward to textobj, similar to targets.vim | |
keymaps = { | |
-- You can use the capture groups defined in textobjects.scm | |
["aa"] = "@parameter.outer", | |
["ia"] = "@parameter.inner", | |
["af"] = "@function.outer", | |
["if"] = "@function.inner", | |
["ac"] = "@class.outer", | |
["ic"] = "@class.inner", | |
}, | |
}, | |
move = { | |
enable = true, | |
set_jumps = true, -- whether to set jumps in the jumplist | |
goto_next_start = { | |
["]m"] = "@function.outer", | |
[")"] = "@parameter.inner", | |
-- ["]]"] = "@class.outer", | |
}, | |
goto_next_end = { | |
["]M"] = "@function.outer", | |
["]["] = "@class.outer", | |
}, | |
goto_previous_start = { | |
["[m"] = "@function.outer", | |
["("] = "@parameter.inner", | |
-- ["[["] = "@class.outer", | |
}, | |
goto_previous_end = { | |
["[M"] = "@function.outer", | |
["[]"] = "@class.outer", | |
}, | |
}, | |
swap = { | |
enable = true, | |
swap_next = { | |
["<leader>a"] = "@parameter.inner", | |
}, | |
swap_previous = { | |
["<leader>A"] = "@parameter.inner", | |
}, | |
}, | |
}, | |
}) | |
-- Diagnostic keymaps | |
vim.keymap.set("n", "[d", vim.diagnostic.goto_prev, { desc = "Go to previous diagnostic message" }) | |
vim.keymap.set("n", "]d", vim.diagnostic.goto_next, { desc = "Go to next diagnostic message" }) | |
vim.keymap.set("n", "[q", ":cp<CR>", { desc = "Go to previous quickfix" }) | |
vim.keymap.set("n", "]q", ":cn<CR>", { desc = "Go to next quickfix" }) | |
vim.keymap.set("n", "cq", ":ccl<CR>", { desc = "Close quickfix" }) | |
vim.keymap.set("n", "<leader>e", vim.diagnostic.open_float, { desc = "Open floating diagnostic message" }) | |
vim.keymap.set("n", "<leader>q", vim.diagnostic.setloclist, { desc = "Open diagnostics list" }) | |
-- vim.keymap.set("n", "<leader>f", '<cmd>lua require("typescript").actions.removeUnused()<CR><cmd>lua require("typescript").actions.addMissingImports()<CR><cmd>lua require("typescript").actions.organizeImports()<CR>', { desc = "[F]ormat imports" }) | |
vim.keymap.set("n", "<leader>f", '<cmd>lua require("typescript").actions.removeUnused()<CR><cmd>lua require("typescript").actions.addMissingImports()<CR>', { desc = "[F]ormat imports: add missing" }) | |
vim.keymap.set("n", "<leader>F", '<cmd>lua require("typescript").actions.removeUnused()<CR>', { desc = "[F]ormat imports: remove unused" }) | |
-- vim.diagnostic.config({ | |
-- underline = true, | |
-- signs = true, | |
-- virtual_text = false, | |
-- float = { | |
-- show_header = true, | |
-- source = 'if_many', | |
-- border = 'rounded', | |
-- focusable = false, | |
-- }, | |
-- update_in_insert = false, -- default to false | |
-- severity_sort = false, -- default to false | |
-- }) | |
-- [[ Configure LSP ]] | |
-- This function gets run when an LSP connects to a particular buffer. | |
local on_attach = function(_, bufnr) | |
-- NOTE: Remember that lua is a real programming language, and as such it is possible | |
-- to define small helper and utility functions so you don't have to repeat yourself | |
-- many times. | |
-- | |
-- In this case, we create a function that lets us more easily define mappings specific | |
-- for LSP related items. It sets the mode, buffer and description for us each time. | |
local nmap = function(keys, func, desc) | |
if desc then | |
desc = "LSP: " .. desc | |
end | |
vim.keymap.set("n", keys, func, { buffer = bufnr, desc = desc }) | |
end | |
nmap("<leader>rn", vim.lsp.buf.rename, "[R]e[n]ame") | |
nmap("ca", vim.lsp.buf.code_action, "[C]ode [A]ction") | |
-- vim.api.nvim_set_keymap('n', 'ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', { noremap = true, silent = true }) | |
-- vim.api.nvim_set_keymap('v', 'ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', { noremap = true, silent = true }) | |
nmap("fd", vim.lsp.buf.definition, "[F]ind [D]efinition") | |
nmap("fi", vim.lsp.buf.implementation, "[F]ind [I]mplementation") | |
nmap("fu", require("telescope.builtin").lsp_references, "[F]ind [U]se") | |
nmap("gI", vim.lsp.buf.implementation, "[G]oto [I]mplementation") | |
nmap("<leader>D", vim.lsp.buf.type_definition, "Type [D]efinition") | |
nmap("<leader>ds", require("telescope.builtin").lsp_document_symbols, "[D]ocument [S]ymbols") | |
nmap("<leader>ws", require("telescope.builtin").lsp_dynamic_workspace_symbols, "[W]orkspace [S]ymbols") | |
-- See `:help K` for why this keymap | |
nmap("K", function() | |
vim.lsp.buf.hover() | |
end, "Hover Documentation") | |
-- nmap("<C-k>", vim.lsp.buf.signature_help, "Signature Documentation") | |
-- Lesser used LSP functionality | |
nmap("gD", vim.lsp.buf.declaration, "[G]oto [D]eclaration") | |
nmap("<leader>wa", vim.lsp.buf.add_workspace_folder, "[W]orkspace [A]dd Folder") | |
nmap("<leader>wr", vim.lsp.buf.remove_workspace_folder, "[W]orkspace [R]emove Folder") | |
nmap("<leader>wl", function() | |
print(vim.inspect(vim.lsp.buf.list_workspace_folders())) | |
end, "[W]orkspace [L]ist Folders") | |
vim.keymap.set("n", "F", function() | |
local filepath = vim.fn.expand('%:p') | |
if vim.bo.filetype == 'python' then | |
vim.cmd(string.format("!black --line-length 79 %s", filepath)) | |
elseif vim.bo.filetype == 'go' then | |
vim.cmd(string.format("!gofmt -w %s", filepath)) | |
-- elseif vim.bo.filetype == 'asm' then | |
-- vim.cmd(string.format("!asmfmt -w %s", filepath)) | |
elseif vim.bo.filetype == 'c' then | |
vim.lsp.buf.format({ bufnr = bufnr, async = true }) | |
elseif vim.bo.filetype == 'cpp' then | |
vim.lsp.buf.format({ bufnr = bufnr, async = true }) | |
else | |
vim.fn.system(string.format("yarn prettier --write %s", filepath)) | |
vim.lsp.buf.format({ bufnr = bufnr }) | |
end | |
vim.cmd('edit!') | |
end, { buffer = bufnr, desc = "[lsp] format" }) | |
-- Create a command `:Format` local to the LSP buffer | |
vim.api.nvim_buf_create_user_command(bufnr, "Format", function(_) | |
vim.lsp.buf.format() | |
end, { desc = "Format current buffer with LSP" }) | |
end | |
vim.keymap.set("n", "fc", ":Tab /\\/\\/<CR>:%s/\\s\\+$//e<CR>", { desc = "Align comments" }) | |
-- Enable the following language servers | |
-- Feel free to add/remove any LSPs that you want here. They will automatically be installed. | |
-- | |
-- Add any additional override configuration in the following tables. They will be passed to | |
-- the `settings` field of the server config. You must look up that documentation yourself. | |
-- | |
-- If you want to override the default filetypes that your language server will attach to you can | |
-- define the property 'filetypes' to the map in question. | |
local servers = { | |
clangd = {}, | |
-- gopls = {}, | |
-- pyright = {}, | |
-- rust_analyzer = {}, | |
-- tsserver = {}, | |
-- html = { filetypes = { 'html', 'twig', 'hbs'} }, | |
lua_ls = { | |
Lua = { | |
workspace = { checkThirdParty = false }, | |
telemetry = { enable = false }, | |
}, | |
}, | |
} | |
-- Setup neovim lua configuration | |
require("neodev").setup({ | |
library = { plugins = { "nvim-dap-ui", "neotest" }, types = true }, | |
}) | |
require("transparent").setup({ -- Optional, you don't have to run setup. | |
groups = { -- table: default groups | |
'Normal', 'NormalNC', 'Comment', 'Constant', 'Special', 'Identifier', | |
'Statement', 'PreProc', 'Type', 'Underlined', 'Todo', 'String', 'Function', | |
'Conditional', 'Repeat', 'Operator', 'Structure', 'LineNr', 'NonText', | |
'SignColumn', 'CursorLineNr', 'EndOfBuffer', | |
}, | |
extra_groups = {}, -- table: additional groups that should be cleared | |
exclude_groups = {}, -- table: groups you don't want to clear | |
}) | |
-- require("nvim-surround").setup() | |
-- Tests | |
-- nvim-cmp supports additional completion capabilities, so broadcast that to servers | |
local capabilities = vim.lsp.protocol.make_client_capabilities() | |
capabilities = require("cmp_nvim_lsp").default_capabilities(capabilities) | |
-- Ensure the servers above are installed | |
local mason_lspconfig = require("mason-lspconfig") | |
mason_lspconfig.setup({ | |
ensure_installed = vim.tbl_keys(servers), | |
}) | |
mason_lspconfig.setup_handlers({ | |
function(server_name) | |
require("lspconfig")[server_name].setup({ | |
capabilities = capabilities, | |
on_attach = on_attach, | |
settings = servers[server_name], | |
filetypes = (servers[server_name] or {}).filetypes, | |
}) | |
end, | |
}) | |
-- [[ Configure nvim-cmp ]] | |
-- See `:help cmp` | |
local cmp = require("cmp") | |
local luasnip = require("luasnip") | |
require("luasnip.loaders.from_vscode").lazy_load() | |
require("luasnip.loaders.from_snipmate").lazy_load() | |
luasnip.config.setup({}) | |
cmp.setup({ | |
-- preselect = cmp.PreselectMode.None, | |
snippet = { | |
expand = function(args) | |
luasnip.lsp_expand(args.body) | |
end, | |
}, | |
mapping = cmp.mapping.preset.insert({ | |
["<C-n>"] = cmp.mapping.select_next_item(), | |
["<C-p>"] = cmp.mapping.select_prev_item(), | |
["<C-d>"] = cmp.mapping.scroll_docs(-4), | |
["<C-f>"] = cmp.mapping.scroll_docs(4), | |
["<C-Space>"] = cmp.mapping.complete({}), | |
["<CR>"] = cmp.mapping.confirm({ | |
behavior = cmp.ConfirmBehavior.Replace, | |
select = true, | |
}), | |
["<Tab>"] = cmp.mapping(function(fallback) | |
if cmp.visible() then | |
cmp.select_next_item() | |
elseif luasnip.expand_or_locally_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.locally_jumpable(-1) then | |
luasnip.jump(-1) | |
else | |
fallback() | |
end | |
end, { "i", "s" }), | |
}), | |
sources = { | |
-- { name = "luasnip", keyword_length = 1 }, | |
{ name = "buffer", keyword_length = 1 }, | |
{ name = "nvim_lsp", keyword_length = 1 }, | |
}, | |
experimental = { | |
ghost_text = false, | |
}, | |
}) | |
-- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore). | |
cmp.setup.cmdline({ '/', '?' }, { | |
mapping = cmp.mapping.preset.cmdline(), | |
sources = { | |
{ name = 'buffer' } | |
} | |
}) | |
-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore). | |
cmp.setup.cmdline(':', { | |
mapping = cmp.mapping.preset.cmdline(), | |
sources = cmp.config.sources({ | |
{ name = 'path' } | |
}, { | |
{ name = 'cmdline' } | |
}), | |
matching = { disallow_symbol_nonprefix_matching = false } | |
}) | |
-- The line beneath this is called `modeline`. See `:help modeline` | |
-- vim: ts=2 sts=2 sw=2 et | |
local keymap = vim.api.nvim_set_keymap | |
local opts = { noremap = true, silent = true } | |
local ls = require("luasnip") | |
vim.keymap.set({"i"}, "<C-K>", function() ls.expand() end, {silent = true}) | |
keymap("i", "\\", "<Plug>luasnip-expand-or-jump", opts) | |
keymap("i", "`", "<Plug>luasnip-expand-or-jump", opts) | |
keymap("i", "|", "<cmd>lua require'luasnip'.jump(1)<CR>", opts) | |
keymap("i", "~", "<cmd>lua require'luasnip'.jump(1)<CR>", opts) | |
keymap("i", "<c-j>", "<cmd>lua require'luasnip'.jump(1)<CR>", opts) | |
keymap("s", "<c-j>", "<cmd>lua require'luasnip'.jump(1)<CR>", opts) | |
keymap("i", "<c-k>", "<cmd>lua require'luasnip'.jump(-1)<CR>", opts) | |
keymap("s", "<c-k>", "<cmd>lua require'luasnip'.jump(-1)<CR>", opts) | |
require('iron.core').setup({ | |
config = { | |
ignore_blank_lines = true, | |
scratch_repl = true, | |
repl_definition = { | |
sh = { | |
command = {"zsh"} | |
}, | |
python = { | |
command = {"ipython"}, | |
format = require("iron.fts.common").bracketed_paste, | |
}, | |
typescript = { | |
command = {"yarn", "ts-node"}, | |
format = require("iron.fts.typescript").bracketed_paste, | |
}, | |
}, | |
-- repl_open_cmd = "horizontal botright 20 split", | |
repl_open_cmd = "vertical botright 100 split", | |
}, | |
keymaps = { | |
visual_send = "r", | |
clear = "<space>cl", | |
send_motion = "<space>sc", | |
send_file = "rf", | |
send_line = "rr", | |
send_paragraph = "rp", | |
send_until_cursor = "<space>su", | |
send_mark = "<space>sm", | |
mark_motion = "<space>mc", | |
mark_visual = "<space>mc", | |
remove_mark = "<space>md", | |
cr = "<space>s<cr>", | |
interrupt = "<space>s<space>", | |
exit = "<space>sq", | |
}, | |
ignore_blank_lines = true, | |
}) | |
vim.cmd([[ | |
augroup TermOpenNonumber | |
autocmd! | |
autocmd TermOpen * setlocal nonumber norelativenumber | |
augroup END | |
]]) | |
vim.keymap.set("n", "<leader>r", ':IronRepl<CR>', { desc = "Toggle [R]epl" }) | |
vim.keymap.set("n", "<leader>R", ':IronRestart<CR>', { desc = "Restart [R]epl" }) | |
vim.keymap.set({ "n", "v" }, "cO", ":CBllbox2<CR>", { desc = "[C]omment [O]bject" }) | |
vim.keymap.set({ "n", "v" }, "cL", ":CBllline1<CR>", { desc = "[C]omment [L]ine" }) | |
vim.keymap.set({ "n", "v" }, "cI", ":CBllbox12<CR>", { desc = "[C]omment [I]nfo" }) | |
vim.keymap.set({ "n", "v" }, "cU", ":CBd<CR>", { desc = "[C]omment rem[O]ve" }) | |
vim.keymap.set("n", "<leader>ot", "vi{:s/?*:.*/,/<CR>", { desc = "[C]lean {}}" }) | |
vim.keymap.set("n", "<leader>l", ":!pdflatex %<CR>", { desc = "[G]it file [H]istory" }) | |
vim.api.nvim_create_augroup('TexKeymap', { clear = true }) | |
vim.api.nvim_create_autocmd('FileType', { | |
group = 'TexKeymap', | |
pattern = 'tex', | |
callback = function() | |
vim.keymap.set('n', 'rr', ':!pdflatex %<CR>', { desc = '[G]it file [H]istory', buffer = true }) | |
end, | |
}) | |
-- Define the sorting function | |
local function sort_by_length() | |
-- Get the start and end positions of the visual selection | |
local start_pos = vim.fn.getpos("'<")[2] | |
local end_pos = vim.fn.getpos("'>")[2] | |
-- Get the lines in the visual selection range | |
local lines = vim.fn.getline(start_pos, end_pos) | |
-- Sort lines by decreasing length | |
table.sort(lines, function(a, b) return #a > #b end) | |
-- Replace the original lines with the sorted lines | |
vim.fn.setline(start_pos, lines) | |
end | |
vim.keymap.set({ "v" }, "<leader>s", function() sort_by_length() end, { desc = "[S]sort selection", noremap = true, silent = true}) | |
-- ────────────────────────────────────────────────────────────────────── | |
-- language | |
-- keymap("i", "-e", "export const ", opts) | |
-- keymap("i", "-c", "const ", opts) | |
-- keymap("i", "-d", "const { ", opts) | |
-- keymap("i", "-n", "Number(", opts) | |
-- keymap("i", "-s", "string", opts) | |
-- keymap("i", "-N", "Number.isNaN(", opts) | |
-- keymap("i", "-r", "new RegExp(", opts) | |
-- keymap("i", "-t", "typeof ", opts) | |
-- | |
-- keymap("i", "2m", ".map(x => ", opts) | |
-- keymap("i", "2lm", ".map(", opts) | |
-- keymap("i", "2f", ".filter(x => ", opts) | |
-- keymap("i", "2lf", ".filter(", opts) | |
-- keymap("i", "2i", ".find(x => ", opts) | |
-- keymap("i", "2li", ".find(", opts) | |
-- | |
-- keymap("i", "=a", " = await ", opts) | |
-- keymap("i", "==", " === ", opts) | |
-- keymap("i", "1=", " !== ", opts) | |
-- keymap("i", "7f", " && ", opts) | |
-- keymap("i", "\\f", " || ", opts) | |
-- | |
-- -- types | |
keymap("i", ";s", ": string", opts) | |
keymap("i", ";S", "?: string", opts) | |
keymap("i", ";n", ": number", opts) | |
keymap("i", ";N", "?: number", opts) | |
keymap("i", ";b", ": boolean", opts) | |
keymap("i", ";B", "?: boolean", opts) | |
keymap("i", ";a", ": any", opts) | |
-- | |
-- -- mongo | |
-- keymap("i", "4m", "{\n $match: {\n ", opts) | |
-- keymap("i", "4g", "{\n $group: {\n ", opts) | |
-- keymap("i", "4l", "{\n $limit: ", opts) | |
-- keymap("i", "4s", "{\n $sort: {\n ", opts) | |
-- keymap("i", "4n", "{ $ne: ", opts) | |
-- keymap("i", "4a", ".aggregate(", opts) | |
-- keymap("i", "4A", ".aggregate<{", opts) | |
-- | |
-- -- koa | |
-- keymap("i", "1r", "ctx.request.body", opts) | |
-- keymap("i", "1b", "ctx.body", opts) | |
-- keymap("i", "1q", "ctx.query", opts) | |
-- keymap("i", "1a", "ctx.assert(", opts) | |
-- keymap("i", "1g", "router.get('/", opts) | |
-- keymap("i", "1p", "router.post('", opts) | |
-- keymap("i", "1u", "router.put('", opts) | |
-- keymap("i", "1d", "router.delete('", opts) | |
-- keymap("i", "1l", "= async (ctx: ParameterizedContext) => {\n ", opts) | |
-- keymap("i", "1rl", "', async (ctx: ParameterizedContext) => {\n ", opts) | |
-- | |
-- -- ex brackets | |
-- keymap("i", "',", "',\n", opts) | |
-- keymap("i", "';", ": '", opts) | |
-- | |
-- keymap("i", "0c", "),\n", opts) | |
-- keymap("i", "0d", ")\n", opts) | |
-- keymap("i", "0q", ") ? ", opts) | |
-- keymap("i", "0e", ") = ", opts) | |
-- keymap("i", "0f", "\n])", opts) | |
-- keymap("i", "0d", "([\n ", opts) | |
-- keymap("i", "0gd", "}>([\n ", opts) | |
-- | |
-- keymap("i", "9c", "},\n\b\b", opts) | |
-- keymap("i", "9d", "}\n", opts) | |
-- keymap("i", "9q", "} ? ", opts) | |
-- keymap("i", "9e", "} = ", opts) | |
-- keymap("i", "9f", "\n})", opts) | |
-- keymap("i", "9d", "({\n ", opts) | |
-- keymap("i", "9gd", "}>({\n ", opts) | |
keymap("i", "4[", "${", opts) | |
keymap("i", "1\\", "\\", opts) | |
keymap("i", "2\\", "|", opts) | |
keymap("i", "0`", "`", opts) | |
keymap("i", "9`", "~", opts) | |
-- | |
-- ────────────────────────────────────────────────────────────────────── | |
-- ── asm ───────────────────────────────────────────────────────────── | |
-- vim.cmd([[ | |
-- autocmd BufEnter *.s set filetype=off | |
-- autocmd BufEnter *.s highlight Normal guifg=#FFBF00 guibg=black | |
-- autocmd BufEnter *.s highlight NonText guifg=#7F4F00 guibg=black | |
-- ]]) | |
keymap("n", "<leader>m", ":!make && ./bin<CR>", opts) | |
keymap("n", "<leader>M", ":!make -B && ./bin<CR>", opts) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment