diff options
-rw-r--r-- | after/plugin/lsp.lua | 32 | ||||
-rw-r--r-- | after/plugin/telescope.lua | 9 | ||||
-rw-r--r-- | init.lua | 23 | ||||
-rw-r--r-- | lua/talha/autocmds.lua | 2 | ||||
-rw-r--r-- | lua/talha/functions.lua | 71 | ||||
-rw-r--r-- | lua/talha/init.lua | 1 | ||||
-rw-r--r-- | lua/talha/lazy.lua | 42 | ||||
-rw-r--r-- | lua/talha/remap.lua | 25 | ||||
-rw-r--r-- | lua/talha/set.lua | 22 | ||||
-rw-r--r-- | snippets/for.c | 2 | ||||
-rw-r--r-- | snippets/ifelif.c | 4 | ||||
-rw-r--r-- | snippets/ifelse.c | 4 | ||||
-rw-r--r-- | snippets/switch.c | 6 |
13 files changed, 141 insertions, 102 deletions
diff --git a/after/plugin/lsp.lua b/after/plugin/lsp.lua index b0977c1..41e7870 100644 --- a/after/plugin/lsp.lua +++ b/after/plugin/lsp.lua @@ -45,27 +45,38 @@ lsp.on_attach(function(client, bufnr) vim.keymap.set("n", "<leader>vca", function() vim.lsp.buf.code_action() end, opts) vim.keymap.set("n", "<leader>vrr", function() vim.lsp.buf.references() end, opts) vim.keymap.set("n", "<leader>vrn", function() vim.lsp.buf.rename() end, opts) - vim.keymap.set("n", "<leader>vlf", function() + vim.keymap.set("n", "<leader>vlf", function() vim.lsp.buf.format({ async = false, timeout_ms = 10000, - filter = allow_format({'rust_analyzer', 'tsserver'}), - }) + filter = allow_format({'rust_analyzer', 'tsserver', 'gopls', 'clangd', 'html-lsp'}), + }) end, opts) vim.keymap.set("i", "<C-h>", function() vim.lsp.buf.signature_help() end, opts) end) + -- specific setup for python as it's lsp does not come with formatting require('lspconfig').pyright.setup({ single_file_support = false, - on_attach = function(client, bufnr) - local opts = {buffer = bfnr, remap = false} + on_attach = function(_, bufnr) + local opts = {buffer = bufnr, remap = false} vim.keymap.set({'n', 'x'}, '<leader>vcf', function() local filename = GetCurrFileName() vim.cmd(":silent !autopep8 -i " .. filename) vim.cmd(":silent !isort " .. filename) - end, opts) - end + end, opts) + end, +}) + +require('lspconfig').lua_ls.setup({ + settings = { + Lua = { + diagnostics = { + globals = { 'vim' } + } + } + } }) lsp.setup() @@ -105,3 +116,10 @@ cmp.setup({ end, }, }) + +cmp.setup.filetype({ 'sql' }, { + sources = { + { name = 'vim-dadbod-completion' }, + { name = 'buffer'}, + }, +}) diff --git a/after/plugin/telescope.lua b/after/plugin/telescope.lua index 4806008..5c1ec30 100644 --- a/after/plugin/telescope.lua +++ b/after/plugin/telescope.lua @@ -1,6 +1,5 @@ local builtin = require('telescope.builtin') -vim.keymap.set('n', '<leader>pf', builtin.find_files, {}) -vim.keymap.set('n', '<C-p>', builtin.git_files, {}) -vim.keymap.set('n', '<leader>ps', function() - builtin.grep_string({ search = vim.fn.input("Grep > ") }); -end) +vim.keymap.set('n', '<leader>pf', builtin.find_files) +vim.keymap.set('n', '<C-p>', builtin.git_files) +vim.keymap.set('n', '<leader>ps', builtin.live_grep) +vim.keymap.set('n', '<leader>gw', builtin.grep_string) @@ -1,19 +1,22 @@ --- setup lazy +-- Bootstrap lazy.nvim 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, - }) + local lazyrepo = "https://github.com/folke/lazy.nvim.git" + local out = vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath }) + if vim.v.shell_error ~= 0 then + vim.api.nvim_echo({ + { "Failed to clone lazy.nvim:\n", "ErrorMsg" }, + { out, "WarningMsg" }, + { "\nPress any key to exit..." }, + }, true, {}) + vim.fn.getchar() + os.exit(1) + end end vim.opt.rtp:prepend(lazypath) -- setup leader key vim.g.mapleader = " " +vim.g.maplocalleader = "\\" require("talha") - diff --git a/lua/talha/autocmds.lua b/lua/talha/autocmds.lua index 4ce8ae4..4adeb03 100644 --- a/lua/talha/autocmds.lua +++ b/lua/talha/autocmds.lua @@ -5,5 +5,3 @@ vim.api.nvim_create_autocmd({ "CursorHold" }, { command = "silent! checktime", group = autocmd_group, }) - - diff --git a/lua/talha/functions.lua b/lua/talha/functions.lua index b75185b..ff320e3 100644 --- a/lua/talha/functions.lua +++ b/lua/talha/functions.lua @@ -1,41 +1,8 @@ -local Path = require"plenary.path" - function GetCurrFileName() local filename = vim.api.nvim_buf_get_name(0) return filename end -function CreateDailyNote() - local file_path = vim.api.nvim_buf_get_name(0) - local dir_path = file_path - local path_obj = Path:new(file_path) - - if path_obj:is_file() == true then - path_obj = path_obj:parent() -- get the parent directory - dir_path = path_obj:_fs_filename() - end - - local today_date_fmt = os.date('%Y-%m-%d') - local daily_note_file_name = today_date_fmt .. '.md' - local daily_note_file_obj = path_obj:joinpath(daily_note_file_name) - - local template_file_name = '.daily-notes-template.md' - local template_file_obj = path_obj:joinpath(template_file_name) - - local status = template_file_obj:copy({destination=daily_note_file_obj}) - - -- check if operation was a success - if status[daily_note_file_obj] == false then - print('Error! failed to create daily note') - print([[Possible Causes: - 1. No `.daily-notes-template.md` found - 2. Something went wrong with copy, in which case check nvim config]]) - return - end - - vim.cmd('e ' .. daily_note_file_obj:_fs_filename()) -end - local function _ReloadConfigsInPath(path_selector) local config_paths = vim.fn.glob(path_selector, true, true) @@ -66,12 +33,6 @@ function ToggleSpellCheck() vim.opt.spelllang = 'en_us' end -function SetFocusColors(mode) - vim.o.background = "light" - vim.opt.cursorline = false - vim.cmd("colorscheme vscode") -end - function GetHomeDir() -- for linux/mac local home = os.getenv("HOME") @@ -86,17 +47,6 @@ 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) @@ -113,3 +63,24 @@ function SafeCListNav(navdir) return nil end end + +function MakeTags() + local on_exit = function(obj) + print('re-generated tags') + end + + vim.system({'ctags', '-R', '.'}, {text = true}, on_exit) +end + +function LoadSnippet(stype) + local ft = '.lua' + local buft = vim.bo.filetype + if buft == 'cpp' then + ft = '.c' + else + ft = '.' .. vim.bo.filetype + end + vim.cmd.read { + GetHomeDir() .. '/.config/nvim/snippets/' .. stype .. ft + } +end diff --git a/lua/talha/init.lua b/lua/talha/init.lua index 477c463..94a77a5 100644 --- a/lua/talha/init.lua +++ b/lua/talha/init.lua @@ -3,4 +3,3 @@ 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 index 8ac7f43..b984c54 100644 --- a/lua/talha/lazy.lua +++ b/lua/talha/lazy.lua @@ -1,3 +1,4 @@ +<<<<<<< HEAD require("lazy").setup({ { "nvim-lua/plenary.nvim" }, @@ -7,26 +8,28 @@ require("lazy").setup({ }, { "nvim-treesitter/nvim-treesitter", build = ":TSUpdate", - config = function () + config = function () local configs = require("nvim-treesitter.configs") configs.setup({ - ensure_installed = { "c", "vim", "vimdoc", "query", "javascript", "typescript", "python", "cpp"}, + ensure_installed = { + "c", "cpp", + "vim", "vimdoc", "query", + "javascript", "typescript", + "python" + }, sync_install = false, - highlight = { + highlight = { enable = true, additional_vim_regex_highlighting = false, }, - indent = { enable = true }, + 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', @@ -40,8 +43,31 @@ require("lazy").setup({ {'hrsh7th/nvim-cmp'}, -- Required {'hrsh7th/cmp-nvim-lsp'}, -- Required {'hrsh7th/cmp-buffer'}, -- Required - {'hrsh7th/cmp-nvim-lua'}, + {'hrsh7th/cmp-nvim-lua'}, + {'L3MON4D3/LuaSnip'}, -- Required + } + }, +======= + {'hrsh7th/cmp-nvim-lua'}, {'L3MON4D3/LuaSnip'}, -- Required } }, + { + "kristijanhusak/vim-dadbod-ui", + dependencies = { + { 'tpope/vim-dadbod', lazy = true }, + { 'kristijanhusak/vim-dadbod-completion', ft = { 'sql', 'mysql', 'plsql' }, lazy = true }, + }, + cmd = { + 'DBUI', + 'DBUIToggle', + 'DBUIAddConnection', + 'DBUIFindBuffer' + }, + init = function() + vim.g.db_ui_use_nerd_fonts = 1 + end, + } + --- @DISABLED + -- "mbbill/undotree", }) diff --git a/lua/talha/remap.lua b/lua/talha/remap.lua index 0569836..f2c714b 100644 --- a/lua/talha/remap.lua +++ b/lua/talha/remap.lua @@ -1,3 +1,14 @@ +-- easier navigation +vim.keymap.set("n", "<C-h>", "<C-w><C-h>") +vim.keymap.set("n", "<C-j>", "<C-w><C-j>") +vim.keymap.set("n", "<C-k>", "<C-w><C-k>") +vim.keymap.set("n", "<C-l>", "<C-w><C-l>") + +-- tab navigation +vim.keymap.set("n", "<C-t><C-n>", vim.cmd.tabnew) +vim.keymap.set("n", "<C-t><C-h>", vim.cmd.tabp) +vim.keymap.set("n", "<C-t><C-l>", vim.cmd.tabn) + -- open project view with netrw vim.keymap.set("n", "<leader>pv", vim.cmd.Ex) @@ -22,11 +33,6 @@ vim.keymap.set("n", "N", "Nzzzv") vim.keymap.set("x", "<leader>p", "\"_dP") --- Tab navigation -vim.keymap.set("n", "<C-t>n", vim.cmd.tabn) --- go to prev error -vim.keymap.set("n", "<C-t>p", vim.cmd.tabp) - ---- system clipboard -- copying vim.keymap.set("n", "<leader>y", [["+y]]) @@ -51,9 +57,8 @@ vim.keymap.set("n", "<A-n>", function() SafeCListNav(1) end) -- go to prev error vim.keymap.set("n", "<A-p>", function() SafeCListNav(-1) end) -- open error list when there are errors -vim.keymap.set("n", "<A-e>", vim.cmd.cw) +vim.keymap.set("n", "<A-w>", vim.cmd.cw) + +---- snippets +vim.keymap.set("n", "<A-s>", [[:lua LoadSnippet('')<Left><Left>]]) --- building -vim.keymap.set("n", "<F5>", function() - vim.cmd.Neomake{bang=true}; -end) diff --git a/lua/talha/set.lua b/lua/talha/set.lua index c2c578d..91129ad 100644 --- a/lua/talha/set.lua +++ b/lua/talha/set.lua @@ -3,13 +3,12 @@ local op = vim.opt op.nu = true op.relativenumber = true -op.tabstop = 2 op.softtabstop = 2 op.shiftwidth = 2 -op.expandtab = true +op.expandtab = false -op.smartindent = true -op.wrap = false +op.cindent = true +op.wrap = true op.swapfile = false op.backup = false @@ -28,11 +27,16 @@ op.autoread = true op.updatetime = 50 -op.colorcolumn = '120' +op.colorcolumn = '80' +if vim.fn.executable('rg') > 0 then + op.grepprg = 'rg --vimgrep' +end + +-- netrw settings -- required to allow mm (mark-move) command to move file vim.g.netrw_keepdir = 1 - --- building c/cpp files -vim.opt.makeprg = GetPlatformBuildCommand() - +vim.g.netrw_banner = 0 +--vim.g.netrw_browse_split = 4 +vim.g.netrw_altv = 1 +--vim.g.netrw_liststyle = 3 diff --git a/snippets/for.c b/snippets/for.c new file mode 100644 index 0000000..4cc9378 --- /dev/null +++ b/snippets/for.c @@ -0,0 +1,2 @@ +for( ; ; ) { +} diff --git a/snippets/ifelif.c b/snippets/ifelif.c new file mode 100644 index 0000000..6f37315 --- /dev/null +++ b/snippets/ifelif.c @@ -0,0 +1,4 @@ +if (_) { +} else if (_) { +} else { +} diff --git a/snippets/ifelse.c b/snippets/ifelse.c new file mode 100644 index 0000000..03f9dda --- /dev/null +++ b/snippets/ifelse.c @@ -0,0 +1,4 @@ +if (_) { +} +else { +} diff --git a/snippets/switch.c b/snippets/switch.c new file mode 100644 index 0000000..b0b527a --- /dev/null +++ b/snippets/switch.c @@ -0,0 +1,6 @@ +switch (_) { + case (_): { + } break; + default: { + } break; +} |