From f4431f6d75baa71aa23318ea50bea3848f946ab1 Mon Sep 17 00:00:00 2001 From: talha Date: Tue, 23 Apr 2024 00:43:02 +0500 Subject: Migrated to lazy.nvim, added neomake, a few remaps --- after/plugin/harpoon.lua | 8 ++++---- after/plugin/lsp.lua | 6 +----- after/plugin/telescope.lua | 4 ++-- after/plugin/treesitter.lua | 21 --------------------- init.lua | 18 ++++++++++++++++++ lazy-lock.json | 19 +++++++++++++++++++ lua/talha/functions.lua | 27 +++++++++++++++++++++++++++ lua/talha/init.lua | 3 +-- lua/talha/lazy.lua | 45 +++++++++++++++++++++++++++++++++++++++++++++ lua/talha/packer.lua | 45 --------------------------------------------- lua/talha/remap.lua | 23 +++++++++++++++++------ lua/talha/set.lua | 4 ++++ 12 files changed, 138 insertions(+), 85 deletions(-) delete mode 100644 after/plugin/treesitter.lua create mode 100644 lazy-lock.json create mode 100644 lua/talha/lazy.lua delete mode 100644 lua/talha/packer.lua diff --git a/after/plugin/harpoon.lua b/after/plugin/harpoon.lua index 7d2a7a6..a24b20d 100644 --- a/after/plugin/harpoon.lua +++ b/after/plugin/harpoon.lua @@ -4,7 +4,7 @@ local ui = require("harpoon.ui") vim.keymap.set("n", "a", mark.add_file) vim.keymap.set("n", "", ui.toggle_quick_menu) -vim.keymap.set("n", "y", function() ui.nav_file(1) end) -vim.keymap.set("n", "u", function() ui.nav_file(2) end) -vim.keymap.set("n", "i", function() ui.nav_file(3) end) -vim.keymap.set("n", "o", function() ui.nav_file(4) end) +vim.keymap.set("n", "1", function() ui.nav_file(1) end) +vim.keymap.set("n", "2", function() ui.nav_file(2) end) +vim.keymap.set("n", "3", function() ui.nav_file(3) end) +vim.keymap.set("n", "4", function() ui.nav_file(4) end) diff --git a/after/plugin/lsp.lua b/after/plugin/lsp.lua index f8dae3c..7d8e3ab 100644 --- a/after/plugin/lsp.lua +++ b/after/plugin/lsp.lua @@ -1,10 +1,5 @@ local lsp = require('lsp-zero').preset({}) -local function allow_format(servers) - return function(client) return vim.tbl_contains(servers, client.name) end -end - - -- TODO: add bindings to work when no lsp available, to allow normal functionality lsp.on_attach(function(client, bufnr) -- see :help lsp-zero-keybindings @@ -23,3 +18,4 @@ lsp.on_attach(function(client, bufnr) end) lsp.setup() + diff --git a/after/plugin/telescope.lua b/after/plugin/telescope.lua index 4806008..b007673 100644 --- a/after/plugin/telescope.lua +++ b/after/plugin/telescope.lua @@ -1,6 +1,6 @@ local builtin = require('telescope.builtin') -vim.keymap.set('n', 'pf', builtin.find_files, {}) +vim.keymap.set('n', 'ff', builtin.find_files, {}) vim.keymap.set('n', '', builtin.git_files, {}) -vim.keymap.set('n', 'ps', function() +vim.keymap.set('n', 'fs', function() builtin.grep_string({ search = vim.fn.input("Grep > ") }); end) diff --git a/after/plugin/treesitter.lua b/after/plugin/treesitter.lua deleted file mode 100644 index d0ee3dc..0000000 --- a/after/plugin/treesitter.lua +++ /dev/null @@ -1,21 +0,0 @@ -require'nvim-treesitter.configs'.setup { - -- A list of parser names, or "all" (the five listed parsers should always be installed) - ensure_installed = { "c", "lua", "vim", "vimdoc", "query", "javascript", "typescript", "python", "cpp"}, - - -- Install parsers synchronously (only applied to `ensure_installed`) - sync_install = false, - - -- Automatically install missing parsers when entering buffer - -- Recommendation: set to false if you don't have `tree-sitter` CLI installed locally - auto_install = true, - - highlight = { - enable = true, - - -- Setting this to true will run `:h syntax` and tree-sitter at the same time. - -- Set this to `true` if you depend on 'syntax' being enabled (like for indentation). - -- Using this option may slow down your editor, and you may see some duplicate highlights. - -- Instead of true it can also be a list of languages - additional_vim_regex_highlighting = false, - }, -} diff --git a/init.lua b/init.lua index 1105fe8..4a33ff0 100644 --- a/init.lua +++ b/init.lua @@ -1 +1,19 @@ +-- setup lazy +local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" +if not (vim.uv or 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) + +-- setup leader key +vim.g.mapleader = " " + require("talha") + diff --git a/lazy-lock.json b/lazy-lock.json new file mode 100644 index 0000000..270621b --- /dev/null +++ b/lazy-lock.json @@ -0,0 +1,19 @@ +{ + "LuaSnip": { "branch": "master", "commit": "72eea98b1900013e0cb214f29b898c8d91564930" }, + "cmp-nvim-lsp": { "branch": "main", "commit": "5af77f54de1b16c34b23cba810150689a3a90312" }, + "harpoon": { "branch": "master", "commit": "ccae1b9bec717ae284906b0bf83d720e59d12b91" }, + "lazy.nvim": { "branch": "main", "commit": "3f13f080434ac942b150679223d54f5ca91e0d52" }, + "lsp-zero.nvim": { "branch": "v2.x", "commit": "9a686513eaaa13d737d0fec8956a18268ead8b29" }, + "mason-lspconfig.nvim": { "branch": "main", "commit": "f3658bfc667df6a0340194a015ac2f31c1e675e0" }, + "mason.nvim": { "branch": "main", "commit": "751b1fcbf3d3b783fcf8d48865264a9bcd8f9b10" }, + "neomake": { "branch": "master", "commit": "584f882b9f991245374e7e7d7d1f78bae90b7a35" }, + "nvim-cmp": { "branch": "main", "commit": "ce16de5665c766f39c271705b17fff06f7bcb84f" }, + "nvim-lspconfig": { "branch": "master", "commit": "ed8b8a15acc441aec669f97d75f2c1f2ac8c8aa5" }, + "nvim-treesitter": { "branch": "master", "commit": "c1d1b4084ef5239e2671f64d35962d184251aea4" }, + "plenary.nvim": { "branch": "master", "commit": "5129a3693c482fcbc5ab99a7706ffc4360b995a0" }, + "telescope.nvim": { "branch": "master", "commit": "776b509f80dd49d8205b9b0d94485568236d1192" }, + "undotree": { "branch": "master", "commit": "56c684a805fe948936cda0d1b19505b84ad7e065" }, + "vim-fugitive": { "branch": "master", "commit": "dac8e5c2d85926df92672bf2afb4fc48656d96c7" }, + "vim-gutentags": { "branch": "master", "commit": "aa47c5e29c37c52176c44e61c780032dfacef3dd" }, + "vscode.nvim": { "branch": "main", "commit": "d47aab1fbe423bf14275745684205dca08366277" } +} \ No newline at end of file diff --git a/lua/talha/functions.lua b/lua/talha/functions.lua index e27e1a2..fdad26c 100644 --- a/lua/talha/functions.lua +++ b/lua/talha/functions.lua @@ -87,3 +87,30 @@ function GetHomeDir() return nil end +function GetPlatformBuildCommand() + os_ver = vim.loop.os_uname().sysname + local build_command = '' + if os_ver == 'Linux' then + build_command = [[./build.sh]] + elseif os_ver == 'Windows' then + build_command = [[build.bat]] + end + return build_command +end + +function SafeCListNav(navdir) + -- dir: + -- 1 is cnext (forwards) + -- -1 is cprev (backwards) + local dircmd = '' + if navdir == 1 then + dircmd = 'cnext' + elseif navdir == -1 then + dircmd = 'cprev' + end + local status, result = pcall(vim.cmd, dircmd) + + if status == false then + return nil + end +end diff --git a/lua/talha/init.lua b/lua/talha/init.lua index 43f9548..477c463 100644 --- a/lua/talha/init.lua +++ b/lua/talha/init.lua @@ -1,7 +1,6 @@ +require("talha.lazy") require("talha.functions") require("talha.remap") require("talha.set") require("talha.autocmds") require("talha.neovide") - - diff --git a/lua/talha/lazy.lua b/lua/talha/lazy.lua new file mode 100644 index 0000000..089f254 --- /dev/null +++ b/lua/talha/lazy.lua @@ -0,0 +1,45 @@ + +require("lazy").setup({ + { "nvim-lua/plenary.nvim" }, + { + "nvim-telescope/telescope.nvim", version = "0.1.2", + dependencies = { "nvim-lua/plenary.nvim" } + }, + { "nvim-treesitter/nvim-treesitter", + build = ":TSUpdate", + config = function () + local configs = require("nvim-treesitter.configs") + + configs.setup({ + ensure_installed = { "c", "vim", "vimdoc", "query", "javascript", "typescript", "python", "cpp"}, + sync_install = false, + highlight = { + enable = true, + additional_vim_regex_highlighting = false, + }, + indent = { enable = true }, + }) + end + }, + "Mofiqul/vscode.nvim", + "theprimeagen/harpoon", + "mbbill/undotree", + "tpope/vim-fugitive", + "neomake/neomake", + "ludovicchabant/vim-gutentags", + { + "VonHeikemen/lsp-zero.nvim", + branch = 'v2.x', + dependencies = { + -- LSP Support + {'neovim/nvim-lspconfig'}, -- Required + {'williamboman/mason.nvim'}, -- Optional + {'williamboman/mason-lspconfig.nvim'}, -- Optional + + -- Autocompletion + {'hrsh7th/nvim-cmp'}, -- Required + {'hrsh7th/cmp-nvim-lsp'}, -- Required + {'L3MON4D3/LuaSnip'}, -- Required + } + }, +}) diff --git a/lua/talha/packer.lua b/lua/talha/packer.lua deleted file mode 100644 index e226f93..0000000 --- a/lua/talha/packer.lua +++ /dev/null @@ -1,45 +0,0 @@ -vim.cmd [[packadd packer.nvim]] - -return require('packer').startup(function(use) - -- Packer can manage itself - use 'wbthomason/packer.nvim' - - use { - 'nvim-telescope/telescope.nvim', tag = '0.1.2', - -- or , branch = '0.1.x', - requires = { {'nvim-lua/plenary.nvim'} } - } - - - use({ 'nvim-treesitter/nvim-treesitter', run = ':TSUpdate' }) - - -- colorschemes - use {'Mofiqul/vscode.nvim'} - - use { "theprimeagen/harpoon" } - - use('mbbill/undotree') - - use('tpope/vim-fugitive') - - use({ - 'ludovicchabant/vim-gutentags', - ft={'h', 'hpp', 'c', 'cpp'} - }) - - use { - 'VonHeikemen/lsp-zero.nvim', - branch = 'v2.x', - requires = { - -- LSP Support - {'neovim/nvim-lspconfig'}, -- Required - {'williamboman/mason.nvim'}, -- Optional - {'williamboman/mason-lspconfig.nvim'}, -- Optional - - -- Autocompletion - {'hrsh7th/nvim-cmp'}, -- Required - {'hrsh7th/cmp-nvim-lsp'}, -- Required - {'L3MON4D3/LuaSnip'}, -- Required - } - } -end) diff --git a/lua/talha/remap.lua b/lua/talha/remap.lua index 882d651..cfd6624 100644 --- a/lua/talha/remap.lua +++ b/lua/talha/remap.lua @@ -1,5 +1,3 @@ -vim.g.mapleader = " " - -- open project view with netrw vim.keymap.set("n", "pv", vim.cmd.Ex) @@ -24,10 +22,16 @@ vim.keymap.set("n", "N", "Nzzzv") vim.keymap.set("x", "p", "\"_dP") --- copying to system clipboard +---- system clipboard +-- copying vim.keymap.set("n", "y", [["+y]]) vim.keymap.set("v", "y", [["+y]]) vim.keymap.set("n", "Y", [["+Y]]) +-- pasting +-- @note: for posting in insert mode use: + +vim.keymap.set("n", "p", [["+p]]) +vim.keymap.set("n", "P", [["+P]]) +vim.keymap.set("v", "p", [["+p]]) -- deleting without polluting vim clipboard vim.keymap.set({"n", "x"}, "x", [["_x]]) @@ -36,6 +40,13 @@ vim.keymap.set({"n", "x"}, "X", [["_d]]) -- global substitute the word cursor is on in current file vim.keymap.set("n", "s", [[:%s/\<\>//gI]]) --- remapping quickfix list navigation -vim.keymap.set("n", "l", vim.cmd.cnext) -vim.keymap.set("n", "h", vim.cmd.cprev) +---- remapping quickfix list navigation +-- go to next error +vim.keymap.set("n", "", function() SafeCListNav(1) end) +-- go to prev error +vim.keymap.set("n", "", function() SafeCListNav(-1) end) +-- open error list when there are errors +vim.keymap.set("n", "", vim.cmd.cw) + +-- building +-- vim.keymap.set("n", "", vim.cmd.Neomake{bang=true}) diff --git a/lua/talha/set.lua b/lua/talha/set.lua index 68b6ee6..c2c578d 100644 --- a/lua/talha/set.lua +++ b/lua/talha/set.lua @@ -32,3 +32,7 @@ op.colorcolumn = '120' -- required to allow mm (mark-move) command to move file vim.g.netrw_keepdir = 1 + +-- building c/cpp files +vim.opt.makeprg = GetPlatformBuildCommand() + -- cgit v1.2.3