From f7ea213574583de16b7e262c5b18bfdf20a353be Mon Sep 17 00:00:00 2001 From: antonl Date: Thu, 26 Mar 2026 20:13:11 +0100 Subject: [PATCH] some nice cfg --- init.lua | 183 +++++++++++++++++++++++++++++++++++++++++-------- lazy-lock.json | 7 +- tags | 64 +++++++++++++++++ 3 files changed, 223 insertions(+), 31 deletions(-) create mode 100644 tags diff --git a/init.lua b/init.lua index 2c4c458..7353448 100644 --- a/init.lua +++ b/init.lua @@ -53,41 +53,56 @@ vim.opt.listchars = { } vim.opt.cursorline = true - --- Setup lazy.nvim require("lazy").setup({ spec = { - -- add your plugins here - "stevearc/conform.nvim", - opts = { - notify_on_error = false, - -- Odinfmt gets its configuration from odinfmt.json. It defaults - -- writing to stdout but needs to be told to read from stdin. - formatters = { - odinfmt = { - -- Change where to find the command if it isn't in your path. + { + "stevearc/conform.nvim", + opts = { + notify_on_error = false, + formatters = { + odinfmt = { command = "odinfmt", args = { "-stdin" }, stdin = true, - }, + }, + }, + formatters_by_ft = { + odin = { "odinfmt" }, + }, + format_on_save = { + timeout_ms = 500, + lsp_format = "fallback", + }, }, - -- and instruct conform to use odinfmt. - formatters_by_ft = { - odin = { "odinfmt" }, - }, - format_on_save = { - timeout_ms = 500, - lsp_format = "fallback", - }, - }, + }, + { + "nvim-treesitter/nvim-treesitter", + lazy = false, + build = ":TSUpdate", + }, + { "ludovicchabant/vim-gutentags" }, + { "ibhagwan/fzf-lua" }, }, - -- Configure any other settings here. See the documentation for more details. - -- colorscheme that will be used when installing plugins. - install = { colorscheme = { "habamax" } }, - -- automatically check for plugin updates checker = { enabled = true }, }) +-- Treesitter highlighting +vim.api.nvim_create_autocmd("FileType", { + pattern = { "c", "cpp", "lua", "odin" }, + callback = function() vim.treesitter.start() end, +}) + +-- gutentags +vim.g.gutentags_cache_dir = "C:/misc/ctags_cache" + +--- fzf +local fzf = require("fzf-lua") +vim.keymap.set("n", "f", fzf.files) +vim.keymap.set("n", "g", fzf.live_grep) +vim.keymap.set("n", "t", fzf.tags) +vim.keymap.set("n", "b", fzf.buffers) + + -- C/cpp language server vim.lsp.config.clangd = { cmd = { "clangd" }, @@ -96,11 +111,10 @@ vim.lsp.config.clangd = { ".clangd", "compile_commands.json", "compile_flags.txt", - ".git", }, } - -vim.lsp.enable("clangd") +-- This works very poorly with single translation unit builds +--vim.lsp.enable("clangd") -- Odin language server vim.lsp.config.ols = { @@ -161,6 +175,117 @@ vim.keymap.set("n", "x", function() end, { silent = true }) +-- Because we might have several build.bat in the path on windows (f. ex Odin repo), +-- we traverse upwards from the opened buffer to find the first build.bat/.sh +vim.api.nvim_create_autocmd("BufEnter", { + callback = function() + local build + + if vim.fn.has("win32") == 1 then + build = vim.fs.find("build.bat", { upward = true })[1] + else + build = vim.fs.find("build.sh", { upward = true })[1] + end + + if build then + vim.opt.makeprg = '"' .. build .. '" %' + end + end, +}) + +--vim.keymap.set("n", "b", "make", { silent = true }) +--vim.keymap.set("n", "co", "copen", { silent = true }) +--vim.keymap.set("n", "cc", "cclose", { silent = true }) +--vim.keymap.set("n", "]q", "cnext", { silent = true }) +--vim.keymap.set("n", "[q", "cprev", { silent = true }) +-- +vim.keymap.set("n", "", "cclose", { silent = true }) +--- Toggle between regular window and quickfix +vim.keymap.set("n", "", function() + local qf_open = false + for _, win in ipairs(vim.fn.getwininfo()) do + if win.quickfix == 1 then + qf_open = true + if win.winid == vim.api.nvim_get_current_win() then + -- currently in qf, jump back to last normal window + vim.cmd("wincmd p") + return + end + end + end + if qf_open then + vim.cmd("copen") + else + vim.cmd("copen") + end +end, { silent = true }) +vim.api.nvim_create_autocmd("QuickFixCmdPost", { + pattern = "make", + callback = function() + vim.cmd("cwindow") + end, +}) + +-- init.lua (recommended) +vim.opt.clipboard = "unnamedplus" + +-- init.lua +local function auto_yank_to_clipboard() + if vim.fn.mode() == 'v' or vim.fn.mode() == 'V' or vim.fn.mode() == '\22' then + vim.cmd('normal! "+y') + end +end + +-- Copy visual selection to Windows clipboard the moment you release left mouse button +vim.api.nvim_create_autocmd("ModeChanged", { + pattern = "*:*", + callback = function() + if vim.v.event.new_mode == "n" then + -- we just left visual mode → yank to clipboard + vim.schedule(auto_yank_to_clipboard) + end + end, +}) + + +-- Function to automatically format enclosing braces things +vim.keymap.set('i', '', function() + local line = vim.api.nvim_get_current_line() + local col = vim.api.nvim_win_get_cursor(0)[2] + + if col > 0 and line:sub(col, col) == '{' and line:sub(col + 1, col + 1) == '}' then + return 'O' + end + if col > 0 and line:sub(col, col) == '{' then + return '}O' + end + return '' +end, { expr = true}) + + +local function jump_comment_divider_line(buf, forward) + local current = vim.api.nvim_win_get_cursor(0)[1] + local lines = vim.api.nvim_buf_get_lines(buf, 0, -1, false) + if forward then + for i = current + 1, #lines do + if lines[i]:match("^//~") then + vim.api.nvim_win_set_cursor(0, { i, 0 }) + return + end + end + else + for i = current - 1, 1, -1 do + if lines[i]:match("^//~") then + vim.api.nvim_win_set_cursor(0, { i, 0 }) + return + end + end + end +end + +vim.keymap.set("n", "", function() jump_comment_divider_line(vim.api.nvim_get_current_buf(), true) end) +vim.keymap.set("n", "", function() jump_comment_divider_line(vim.api.nvim_get_current_buf(), false) end) +vim.keymap.set("n", "", "make", { silent = true }) -- Colortheme local function fleury_brown() @@ -345,7 +470,7 @@ local function fleury_theme() set(0, "Define", { fg = c.index_macro }) set(0, "Macro", { fg = c.index_macro }) - set(0, "Special", { fg = c.syntax_crap }) + set(0, "Special", { fg = c.text }) set(0, "Delimiter", { fg = c.text }) set(0, "SpecialChar", { fg = c.string}) set(0, "Todo", { fg = c.at_cursor, bg = c.base, bold = true }) diff --git a/lazy-lock.json b/lazy-lock.json index 8fc5aa8..c9895ab 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -1,4 +1,7 @@ { - "conform.nvim": { "branch": "master", "commit": "8314f4c9e205e7f30b62147069729f9a1227d8bf" }, - "lazy.nvim": { "branch": "main", "commit": "85c7ff3711b730b4030d03144f6db6375044ae82" } + "conform.nvim": { "branch": "master", "commit": "086a40dc7ed8242c03be9f47fbcee68699cc2395" }, + "fzf-lua": { "branch": "main", "commit": "8a79ee54d6216d10b2f153921a12b152be0c1a20" }, + "lazy.nvim": { "branch": "main", "commit": "306a05526ada86a7b30af95c5cc81ffba93fef97" }, + "nvim-treesitter": { "branch": "main", "commit": "6620ae1c44dfa8623b22d0cbf873a9e8d073b849" }, + "vim-gutentags": { "branch": "master", "commit": "aa47c5e29c37c52176c44e61c780032dfacef3dd" } } diff --git a/tags b/tags new file mode 100644 index 0000000..673a8a6 --- /dev/null +++ b/tags @@ -0,0 +1,64 @@ +!_TAG_EXTRA_DESCRIPTION anonymous /Include tags for non-named objects like lambda/ +!_TAG_EXTRA_DESCRIPTION fileScope /Include tags of file scope/ +!_TAG_EXTRA_DESCRIPTION pseudo /Include pseudo tags/ +!_TAG_EXTRA_DESCRIPTION subparser /Include tags generated by subparsers/ +!_TAG_FIELD_DESCRIPTION epoch /the last modified time of the input file (only for F\/file kind tag)/ +!_TAG_FIELD_DESCRIPTION file /File-restricted scoping/ +!_TAG_FIELD_DESCRIPTION input /input file/ +!_TAG_FIELD_DESCRIPTION name /tag name/ +!_TAG_FIELD_DESCRIPTION pattern /pattern/ +!_TAG_FIELD_DESCRIPTION typeref /Type and name of a variable or typedef/ +!_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/ +!_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/ +!_TAG_KIND_DESCRIPTION!JSON a,array /arrays/ +!_TAG_KIND_DESCRIPTION!JSON b,boolean /booleans/ +!_TAG_KIND_DESCRIPTION!JSON n,number /numbers/ +!_TAG_KIND_DESCRIPTION!JSON o,object /objects/ +!_TAG_KIND_DESCRIPTION!JSON s,string /strings/ +!_TAG_KIND_DESCRIPTION!JSON z,null /nulls/ +!_TAG_KIND_DESCRIPTION!Lua f,function /functions/ +!_TAG_KIND_DESCRIPTION!Vim C,constant /constant definitions/ +!_TAG_KIND_DESCRIPTION!Vim a,augroup /autocommand groups/ +!_TAG_KIND_DESCRIPTION!Vim c,command /user-defined commands/ +!_TAG_KIND_DESCRIPTION!Vim f,function /function definitions/ +!_TAG_KIND_DESCRIPTION!Vim k,class /vim9script classes/ +!_TAG_KIND_DESCRIPTION!Vim m,map /maps/ +!_TAG_KIND_DESCRIPTION!Vim n,filename /vimball filename/ +!_TAG_KIND_DESCRIPTION!Vim v,variable /variable definitions/ +!_TAG_OUTPUT_EXCMD mixed /number, pattern, mixed, or combineV2/ +!_TAG_OUTPUT_FILESEP slash /slash or backslash/ +!_TAG_OUTPUT_MODE u-ctags /u-ctags or e-ctags/ +!_TAG_OUTPUT_VERSION 1.1 /current.age/ +!_TAG_PARSER_VERSION!JSON 0.0 /current.age/ +!_TAG_PARSER_VERSION!Lua 0.0 /current.age/ +!_TAG_PARSER_VERSION!Vim 1.1 /current.age/ +!_TAG_PATTERN_LENGTH_LIMIT 96 /0 for no limit/ +!_TAG_PROC_CWD C:/Users/anton/AppData/Local/nvim/ // +!_TAG_PROGRAM_AUTHOR Universal Ctags Team // +!_TAG_PROGRAM_NAME Universal Ctags /Derived from Exuberant Ctags/ +!_TAG_PROGRAM_URL https://ctags.io/ /official site/ +!_TAG_PROGRAM_VERSION 6.2.0 /p6.2.20260322.0/ + ./ginit.vim /^inoremap :call GuiShowContextMenu()$/;" m + ./ginit.vim /^nnoremap :call GuiShowContextMenu()$/;" m + ./ginit.vim /^snoremap :call GuiShowContextMenu()gv$/;" m + ./ginit.vim /^xnoremap :call GuiShowContextMenu()gv$/;" m +branch ./lazy-lock.json /^ "conform.nvim": { "branch": "master", "commit": "086a40dc7ed8242c03be9f47fbcee68699cc2395" },$/;" s object:conform.nvim +branch ./lazy-lock.json /^ "fzf-lua": { "branch": "main", "commit": "8a79ee54d6216d10b2f153921a12b152be0c1a20" },$/;" s object:fzf-lua +branch ./lazy-lock.json /^ "lazy.nvim": { "branch": "main", "commit": "306a05526ada86a7b30af95c5cc81ffba93fef97" },$/;" s object:lazy.nvim +branch ./lazy-lock.json /^ "nvim-treesitter": { "branch": "main", "commit": "6620ae1c44dfa8623b22d0cbf873a9e8d073b849" },$/;" s object:nvim-treesitter +branch ./lazy-lock.json /^ "vim-gutentags": { "branch": "master", "commit": "aa47c5e29c37c52176c44e61c780032dfacef3dd" }$/;" s object:vim-gutentags +callback init.lua /^ callback = function()$/;" f +commit ./lazy-lock.json /^ "conform.nvim": { "branch": "master", "commit": "086a40dc7ed8242c03be9f47fbcee68699cc2395" },$/;" s object:conform.nvim +commit ./lazy-lock.json /^ "fzf-lua": { "branch": "main", "commit": "8a79ee54d6216d10b2f153921a12b152be0c1a20" },$/;" s object:fzf-lua +commit ./lazy-lock.json /^ "lazy.nvim": { "branch": "main", "commit": "306a05526ada86a7b30af95c5cc81ffba93fef97" },$/;" s object:lazy.nvim +commit ./lazy-lock.json /^ "nvim-treesitter": { "branch": "main", "commit": "6620ae1c44dfa8623b22d0cbf873a9e8d073b849" },$/;" s object:nvim-treesitter +commit ./lazy-lock.json /^ "vim-gutentags": { "branch": "master", "commit": "aa47c5e29c37c52176c44e61c780032dfacef3dd" }$/;" s object:vim-gutentags +config init.lua /^ config = function()$/;" f +conform.nvim ./lazy-lock.json /^ "conform.nvim": { "branch": "master", "commit": "086a40dc7ed8242c03be9f47fbcee68699cc2395" },$/;" o +fleury_brown init.lua /^local function fleury_brown()$/;" f +fleury_theme init.lua /^local function fleury_theme()$/;" f +fzf-lua ./lazy-lock.json /^ "fzf-lua": { "branch": "main", "commit": "8a79ee54d6216d10b2f153921a12b152be0c1a20" },$/;" o +lazy.nvim ./lazy-lock.json /^ "lazy.nvim": { "branch": "main", "commit": "306a05526ada86a7b30af95c5cc81ffba93fef97" },$/;" o +nvim-treesitter ./lazy-lock.json /^ "nvim-treesitter": { "branch": "main", "commit": "6620ae1c44dfa8623b22d0cbf873a9e8d073b849" },$/;" o +s:nvim_qt_shim ./ginit.vim /^let s:nvim_qt_shim = 'C:\/misc\/nvim\/share\/nvim-qt\/runtime\/plugin\/nvim_gui_shim.vim'$/;" v +vim-gutentags ./lazy-lock.json /^ "vim-gutentags": { "branch": "master", "commit": "aa47c5e29c37c52176c44e61c780032dfacef3dd" }$/;" o