diff --git a/nvim/.config/nvim/init.lua b/nvim/.config/nvim/init.lua index b1d6fe8..4281267 100644 --- a/nvim/.config/nvim/init.lua +++ b/nvim/.config/nvim/init.lua @@ -1,30 +1,9 @@ require('plugins') +require('options') +require('keymapping') +require('colorscheme') - -vim.cmd([[ - augroup packer_user_config - autocmd! - autocmd BufWritePost plugins.lua source | PackerCompile - augroup end -]]) -------------- --- Options -- --- ---------- - -vim.opt.completeopt = {'menuone', 'noinsert', 'noselect'} -- Completion options (for deoplete) -vim.opt.ignorecase = true -vim.opt.number = true -vim.opt.smartcase = true -vim.opt.mouse = 'a' -vim.opt.background = 'dark' -vim.opt.tabstop= 2 -vim.opt.softtabstop = 2 vim.opt.shiftwidth= 2 vim.opt.expandtab = true -vim.opt.autoindent = true -vim.opt.copyindent= true -vim.opt.termguicolors = true -vim.cmd([[colorscheme gruvbox]]) - - +require('plugins.lsp.mason') --------------------- --Global Varialbles-- --------------------- @@ -35,25 +14,3 @@ vim.g.easyescape_chars = { k = 1 } vim.g.easyescape_timeout = 100 -vim.g.python3_host_prog='/usr/bin/python3' -vim.g.python_host_prog='/usr/bin/python' - ------------- ---Mappings-- ------------- - -vim.g.mapleader= ' ' - --- Copy and paste with system clipboard - -vim.api.nvim_set_keymap('v', '', '"+y', {noremap = true}) -vim.api.nvim_set_keymap('i', '', '+', {noremap = true}) - -vim.api.nvim_set_keymap('i', 'jk','', {noremap = true}) -vim.api.nvim_set_keymap('i', 'kj','', {noremap = true}) - -vim.api.nvim_set_keymap('n', '',':NvimTreeToggle', {noremap = true}) -vim.api.nvim_set_keymap('n', 'r',':NvimTreeRefresh', {noremap = true}) -vim.api.nvim_set_keymap('n', 'n',':NvimTreeFindFile', {noremap = true}) ---vim.api.nvim_set_keymap('n', '',':BufferLinePick', {noremap = true}) -vim.api.nvim_set_keymap('c', 'w!!','w !sudo tee > /dev/null %', {noremap = true}) diff --git a/nvim/.config/nvim/lua/colorscheme.lua b/nvim/.config/nvim/lua/colorscheme.lua new file mode 100644 index 0000000..83efe1a --- /dev/null +++ b/nvim/.config/nvim/lua/colorscheme.lua @@ -0,0 +1,2 @@ + +vim.cmd([[colorscheme gruvbox]]) diff --git a/nvim/.config/nvim/lua/keymapping.lua b/nvim/.config/nvim/lua/keymapping.lua new file mode 100644 index 0000000..6367f27 --- /dev/null +++ b/nvim/.config/nvim/lua/keymapping.lua @@ -0,0 +1,35 @@ +----------- +--Mappings-- +------------ +local keymap = vim.keymap.set +local opts = { silent = true } + +vim.g.mapleader= ' ' + +-- Copy and paste with system clipboard + +keymap('v', '', '"+y', opts) +keymap('i', '', '+', opts) + +keymap('i', 'jk','', opts) +keymap('i', 'kj','', opts) + + +-- Normal -- +-- -- Save and quit +keymap("n", "", ":write", opts) +keymap("n", "", ":quit", opts) +keymap('n', '',':NvimTreeToggle', opts) +keymap('n', 'r',':NvimTreeRefresh', opts) +keymap('n', 'n',':NvimTreeFindFile', opts) +keymap("n", "e", ":NvimTreeToggle", opts) +-- Navigate buffers +keymap("n", "", ":bnext", opts) +keymap("n", "", ":bprevious", opts) + + +--keymap('n', '',':BufferLinePick', opts) +--force sudo save +keymap('c', 'w!!','w !sudo tee > /dev/null %', opts) + +require('plugins.markdown-preview') diff --git a/nvim/.config/nvim/lua/options.lua b/nvim/.config/nvim/lua/options.lua new file mode 100644 index 0000000..50eb3cc --- /dev/null +++ b/nvim/.config/nvim/lua/options.lua @@ -0,0 +1,43 @@ +------------- +-- Options -- +-- ---------- +vim.opt.backup = false -- creates a backup file +vim.opt.cmdheight = 1 -- more space in the neovim command line for displaying messages +vim.opt.completeopt = { "menuone", "noselect" } -- mostly just for cmp +vim.opt.conceallevel = 0 -- so that `` is visible in markdown files +vim.opt.fileencoding = "utf-8" -- the encoding written to a file +vim.opt.hlsearch = true -- highlight all matches on previous search pattern +vim.opt.ignorecase = true -- ignore case in search patterns +vim.opt.mouse = "a" -- allow the mouse to be used in neovim +vim.opt.pumheight = 10 -- pop up menu height +vim.opt.showmode = false -- we don't need to see things like -- INSERT -- anymore +vim.opt.showtabline = 0 -- always show tabs +vim.opt.smartcase = true -- smart case +vim.opt.smartindent = true -- make indenting smarter again +vim.opt.splitbelow = true -- force all horizontal splits to go below current window +vim.opt.splitright = true -- force all vertical splits to go to the right of current window +vim.opt.swapfile = false -- creates a swapfile +vim.opt.termguicolors = true -- set term gui colors (most terminals support this) +vim.opt.timeoutlen = 1000 -- time to wait for a mapped sequence to complete (in milliseconds) +vim.opt.undofile = true -- enable persistent undo +vim.opt.updatetime = 100 -- faster completion (4000ms default) +vim.opt.writebackup = false -- if a file is being edited by another program (or was written to file while editing with another program), it is not allowed to be edited +vim.opt.expandtab = true -- convert tabs to spaces +vim.opt.shiftwidth = 4 -- the number of spaces inserted for each indentation +vim.opt.tabstop = 4 -- insert 2 spaces for a tab +vim.opt.cursorline = true -- highlight the current line +vim.opt.number = true -- set numbered lines +vim.opt.relativenumber = true -- show relative line number +vim.opt.laststatus = 3 -- only the last window will always have a status line +vim.opt.showcmd = false -- hide (partial) command in the last line of the screen (for performance) +vim.opt.ruler = false -- hide the line and column number of the cursor position +vim.opt.numberwidth = 4 -- minimal number of columns to use for the line number {default 4} +vim.opt.signcolumn = "yes" -- always show the sign column, otherwise it would shift the text each time +vim.opt.wrap = false -- display lines as one long line +vim.opt.scrolloff = 3 -- minimal number of screen lines to keep above and below the cursor +vim.opt.sidescrolloff = 3 -- minimal number of screen columns to keep to the left and right of the cursor if wrap is `false` +vim.opt.shortmess:append("c") -- hide all the completion messages, e.g. "-- XXX completion (YYY)", "match 1 of 2", "The only match", "Pattern not found" +vim.opt.whichwrap:append("<,>,[,],h,l") -- keys allowed to move to the previous/next line when the beginning/end of line is reached + + + diff --git a/nvim/.config/nvim/lua/plugins.lua b/nvim/.config/nvim/lua/plugins.lua index 6cbe060..77342ee 100644 --- a/nvim/.config/nvim/lua/plugins.lua +++ b/nvim/.config/nvim/lua/plugins.lua @@ -2,425 +2,174 @@ ------------- -- Plugins -- ------------- +-- Autocommand that reloads neovim whenever you save the plugins.lua file +vim.cmd([[ + augroup packer_user_config + autocmd! + autocmd BufWritePost plugins.lua source | PackerCompile + augroup end +]]) -- Auto install plugin manager local fn = vim.fn -local install_path = fn.stdpath('data')..'/site/pack/packer/start/packer.nvim' -if fn.empty(fn.glob(install_path)) > 0 then - packer_bootstrap = fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path}) + +local ensure_packer = function() + local fn = vim.fn + local install_path = fn.stdpath('data')..'/site/pack/packer/start/packer.nvim' + if fn.empty(fn.glob(install_path)) > 0 then + fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path}) + vim.cmd [[packadd packer.nvim]] + return true + end + return false end +local packer_bootstrap = ensure_packer() + + + return require('packer').startup { function(use) - use { - 'nvim-telescope/telescope.nvim', - requires = { {'nvim-lua/plenary.nvim'} } - } - use { - 'nvim-telescope/telescope-fzf-native.nvim', - run = 'make', - config = function() - require('telescope').setup { - defaults = { - }, - } - require('telescope').load_extension('fzf') - require'telescope.themes'.get_ivy() - - vim.api.nvim_set_keymap("n", "", ":Telescope find_files theme=get_ivy", { noremap = true }) - - vim.api.nvim_set_keymap("n", "/", ":Telescope live_grep theme=get_ivy", { noremap = true }) - - vim.api.nvim_set_keymap("n", ",", ":Telescope buffers theme=get_ivy", { noremap = true }) - - vim.api.nvim_set_keymap("n", "?", ":Telescope current_buffer_fuzzy_find theme=get_ivy", { noremap = true }) - end - } - use 'wbthomason/packer.nvim' use { 'lewis6991/gitsigns.nvim', - requires = { - 'nvim-lua/plenary.nvim' - }, config = function() - require('gitsigns').setup({ - }) + require('plugins.gitsign') end } - use 'ellisonleao/gruvbox.nvim' - - - use 'zhou13/vim-easyescape' - - - use { - 'iamcco/markdown-preview.nvim', - run = function() - vim.fn['mkdp#util#install'](0) - end, - ft = { - 'markdown' - }, - config = function() - vim.api.nvim_set_keymap('n', 'mp', ':MarkdownPreviewToggle', {noremap = true, silent = true}) - end - } - - -- Fuzzy search --- use { --- 'junegunn/fzf.vim', --- requires = { --- 'junegunn/fzf' --- }, --- config = function() --- vim.g.fzf_buffers_jump = 1 --- vim.api.nvim_set_keymap('n', '', ':Buffers!', {noremap = true}) --- vim.api.nvim_set_keymap('n', 'ff', ':Files!\'', {noremap = true}) --- vim.api.nvim_set_keymap('n', 'f.', ':Files! '..vim.fn.expand('%:p:h'), {noremap = true}) --- vim.api.nvim_set_keymap('n', 'f/', ':Rg!', {noremap = true}) --- vim.api.nvim_set_keymap('n', 'fg', ':GFiles!', {noremap = true}) --- end --- } - - -- Show indent line - use { - "lukas-reineke/indent-blankline.nvim", - config = function() - require("indent_blankline").setup { - char = "▏", - show_first_indent_level = false, - show_trailing_blankline_indent = false, - } - end - } - -- Language server protocol - use { - 'williamboman/nvim-lsp-installer', - requires = { - 'neovim/nvim-lspconfig', - }, - run = function() - local required_servers = { - "ansiblels", - "bashls", - "diagnosticls", - "dockerls", - "jsonls", - "pylsp", - "pyright", - "sqls", - "yamlls", - } - - require "nvim-lsp-installer.ui.status-win"().open() - local lsp_installer_servers = require'nvim-lsp-installer.servers' - for _, required_server in pairs(required_servers) do - local _, server = lsp_installer_servers.get_server(required_server) - if not server:is_installed() then - server:install() - end - end - end, - config = function() - local lsp_installer = require("nvim-lsp-installer") - local enhance_server_opts = { - -- Provide settings that should only apply to the "eslintls" server - ["ansiblels"] = function(opts) - opts.filetypes = { - "yaml.ansible" - } - - end, - } - lsp_installer.on_server_ready(function(server) - local on_attach = function(client, bufnr) - local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end - local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end - - --Enable completion triggered by - buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc') - - -- Mappings. - local opts = { noremap=true, silent=true } - - -- See `:help vim.lsp.*` for documentation on any of the below functions - buf_set_keymap('n', 'gD', 'lua vim.lsp.buf.declaration()', opts) - buf_set_keymap('n', 'gd', 'lua vim.lsp.buf.definition()', opts) - buf_set_keymap('n', 'K', 'lua vim.lsp.buf.hover()', opts) - buf_set_keymap('n', 'gi', 'lua vim.lsp.buf.implementation()', opts) - buf_set_keymap('n', '', 'lua vim.lsp.buf.signature_help()', opts) - buf_set_keymap('n', 'wa', 'lua vim.lsp.buf.add_workspace_folder()', opts) - buf_set_keymap('n', 'wr', 'lua vim.lsp.buf.remove_workspace_folder()', opts) - buf_set_keymap('n', 'wl', 'lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))', opts) - buf_set_keymap('n', 'lD', 'lua vim.lsp.buf.type_definition()', opts) - buf_set_keymap('n', 'ln', 'lua vim.lsp.buf.rename()', opts) - buf_set_keymap('n', 'la', 'lua vim.lsp.buf.code_action()', opts) - buf_set_keymap('n', 'gr', 'lua vim.lsp.buf.references()', opts) - buf_set_keymap('n', 'le', 'lua vim.lsp.diagnostic.show_line_diagnostics()', opts) - buf_set_keymap('n', '[d', 'lua vim.lsp.diagnostic.goto_prev()', opts) - buf_set_keymap('n', ']d', 'lua vim.lsp.diagnostic.goto_next()', opts) - buf_set_keymap('n', 'lq', 'lua vim.lsp.diagnostic.set_loclist()', opts) - buf_set_keymap('n', 'f', 'lua vim.lsp.buf.formatting()', opts) - end - local opts = { - on_attach = on_attach - } - if enhance_server_opts[server.name] then - -- Enhance the default opts with the server-specific ones - enhance_server_opts[server.name](opts) - end - - server:setup(opts) - - vim.cmd [[ do User LspAttachBuffers ]] - end) - end - } - -- Autocomplete - use { - 'hrsh7th/nvim-cmp', - requires = { - -- sources - 'neovim/nvim-lspconfig', - 'hrsh7th/cmp-nvim-lsp', - 'hrsh7th/cmp-buffer', - 'hrsh7th/cmp-cmdline', - 'hrsh7th/cmp-nvim-lsp', - 'hrsh7th/cmp-path', - 'hrsh7th/cmp-calc', - 'hrsh7th/cmp-git', - - -- snippets - 'SirVer/ultisnips', - 'honza/vim-snippets', - 'quangnguyen30192/cmp-nvim-ultisnips', - config = function() - require("cmp_nvim_ultisnips").setup{} - end, - -- pictograms - 'onsails/lspkind-nvim' - }, - config= function() - - local cmp = require'cmp' - local cmp_ultisnips_mappings = require("cmp_nvim_ultisnips.mappings") - cmp.setup { - formatting = { - format = require'lspkind'.cmp_format(), - with_text = true, - }, - snippet = { - expand = function(args) - vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users. - end, - }, - mapping = { - [''] = cmp.mapping( - function(fallback) - cmp_ultisnips_mappings.expand_or_jump_forwards(fallback) - end, - { 'i', 's', 'c' } - ), - [''] = cmp.mapping( - function(fallback) - cmp_ultisnips_mappings.jump_backwards(fallback) - end, - { 'i', 's', 'c' } - ), - [''] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }), - [''] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }), - [''] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }), - [''] = cmp.config.disable, - [''] = cmp.mapping({ - i = cmp.mapping.abort(), - c = cmp.mapping.close(), - }), - [''] = cmp.mapping.confirm({ select = false }), - }, - sources = cmp.config.sources( - { - { name = 'path' }, - { name = 'calc' }, - { name = 'nvim_lsp' }, - { name = 'ultisnips' }, - }, - { - { name = 'buffer' }, - } - ) - } - - -- Set configuration for specific filetype. - cmp.setup.filetype('gitcommit', { - sources = cmp.config.sources({ - { name = 'cmp_git' }, -- You can specify the `cmp_git` source if you were installed it. - }, { - { name = 'buffer' }, - }) - }) - - -- Use buffer source for `/` - cmp.setup.cmdline('/', { - sources = { - { name = 'buffer' } - } - }) - - -- Use cmdline & path source for ':' - cmp.setup.cmdline(':', { - sources = cmp.config.sources({ - { name = 'path' } - }, { - { name = 'cmdline' } - }) - }) - end - } - --- use({'jose-elias-alvarez/null-ls.nvim', --- config= function() --- local lsp_formatting = function(bufnr) --- vim.lsp.buf.format({ --- filter = function(clients) --- -- filter out clients that you don't want to use --- return vim.tbl_filter(function(client) --- return client.name ~= "gopls" --- end, clients) --- end, --- bufnr = bufnr, --- }) --- end --- --- -- if you want to set up formatting on save, you can use this as a callback --- local augroup = vim.api.nvim_create_augroup("LspFormatting", {}) --- --- require("null-ls").setup({ --- on_attach = function(client,bufnr) --- if client.supports_method("textDocument/formatting") then --- vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr }) --- vim.api.nvim_create_autocmd("BufWritePre", { --- group = augroup, --- buffer = bufnr, --- callback = function() --- lsp_formatting(bufnr) --- end, --- }) --- end --- end, --- sources = { --- require("null-ls").builtins.formatting.prettier, --- require("null-ls").builtins.formatting.trim_whitespace, --- require("null-ls").builtins.formatting.trim_newlines, --- require("null-ls").builtins.formatting.black, --- require("null-ls").builtins.diagnostics.eslint, --- }, --- }) --- end}) --- - -- File manager - use({ - "kyazdani42/nvim-tree.lua", - requires = "kyazdani42/nvim-web-devicons", - config = function() - vim.api.nvim_set_keymap("n", "t", "NvimTreeToggle", {}) - require("nvim-tree").setup({ - update_focused_file = { - enable = true, - }, - view = { - width = 40, - }, - }) - end, - }) - - use({ - "folke/which-key.nvim", - config = function() - vim.api.nvim_set_option("timeoutlen", 300) - require("which-key").setup({}) - end, - }) - - use 'AckslD/nvim-whichkey-setup.lua' - - use 'yamatsum/nvim-cursorline' - use 'freitass/todo.txt-vim' - + use 'ellisonleao/gruvbox.nvim' + -- Show indent line use { - 'TimUntersberger/neogit', - requires = { - 'nvim-lua/plenary.nvim' - }, - keys = { - 'gs' - }, - cmd = { - 'Neogit' - }, + "lukas-reineke/indent-blankline.nvim", config = function() - require('neogit').setup { - disable_commit_confirmation = true, - disable_context_highlighting = true - } + require('plugins.indent-blankline') - vim.api.nvim_set_keymap('n', 'gs', ':Neogit kind=split', {noremap = true}) - end - } - use ({ - 'windwp/nvim-autopairs', - config = function() - require('nvim-autopairs').setup{ - fast_wrap= {}, - } end -}) + } - use({ - 'nvim-treesitter/nvim-treesitter', - run = ':TSUpdate', - config = function() - require'nvim-treesitter.configs'.setup { - ensure_installed = "all", - highlight = { - enable = true - } - } + --LSP + use({ "https://github.com/neovim/nvim-lspconfig"}) + use({ "https://github.com/williamboman/mason-lspconfig.nvim"}) + use({ "https://github.com/williamboman/mason.nvim", + config= function() + end + }) + use({ "https://github.com/jose-elias-alvarez/null-ls.nvim", + config= function() + require('plugins.lsp.null-ls') end }) use { - 'akinsho/bufferline.nvim', - requires = { - 'kyazdani42/nvim-web-devicons' - }, + 'iamcco/markdown-preview.nvim', + run = function() + vim.fn['mkdp#util#install'](0) + end, + config = function() + end, + } + + + + -- telescope + use { + 'nvim-telescope/telescope.nvim', + } + use { + 'nvim-telescope/telescope-fzf-native.nvim', + run = 'make', + config = function() + require ('plugins.telescope') + end + } + + + use { + 'zhou13/vim-easyescape', config = function() - require('bufferline').setup{ - options = { - offsets = { - { - filetype = 'NvimTree', - text = 'File Explorer', - highlight = 'Directory', - text_align = 'left' - } - } - } - } - vim.api.nvim_set_keymap('n', '', ':BufferLineCycleNext', {noremap = true}) - vim.api.nvim_set_keymap('n', '', ':BufferLineCyclePrev', {noremap = true}) + require('plugins.vim-easyescape') + end + } + + + + -- Autocomplete + use 'hrsh7th/cmp-nvim-lsp' + use 'hrsh7th/cmp-buffer' + use 'hrsh7th/cmp-cmdline' + use 'hrsh7th/cmp-path' + use 'hrsh7th/cmp-calc' + use 'hrsh7th/cmp-git' + use 'hrsh7th/cmp-nvim-lua' + use 'L3MON4D3/LuaSnip' + use 'rafamadriz/friendly-snippets' + use 'onsails/lspkind-nvim' + + + use({ + 'hrsh7th/nvim-cmp', + config= function() + require('plugins.cmp') + end + }) + + -- UI + use 'kyazdani42/nvim-web-devicons' + use { + 'akinsho/bufferline.nvim', + config = function() + require('plugins.bufferline') + end + } + use({ + "kyazdani42/nvim-tree.lua", + config = function() + require('plugins.nvim-tree') + end, + }) + + use 'AckslD/nvim-whichkey-setup.lua' + use({ + "folke/which-key.nvim", + config = function() + require('plugins.which-key') + end, + }) + + + --use 'freitass/todo.txt-vim' + use 'nvim-lua/plenary.nvim' + use { + 'TimUntersberger/neogit', + config = function() + require('plugins.neogit') end } + use ({ + 'windwp/nvim-autopairs', + config = function() + require('plugins.autopairs') + end + }) + + --treesitter + use 'RRethy/nvim-treesitter-endwise' + use({ + 'nvim-treesitter/nvim-treesitter', + config = function() + require('plugins.treesitter') + end + }) + + use {'feline-nvim/feline.nvim', config = function() require('feline').setup({}) end } - use {'sheerun/vim-polyglot'} if packer_bootstrap then require('packer').sync() end diff --git a/nvim/.config/nvim/lua/plugins/autopairs.lua b/nvim/.config/nvim/lua/plugins/autopairs.lua new file mode 100644 index 0000000..b3f4b2a --- /dev/null +++ b/nvim/.config/nvim/lua/plugins/autopairs.lua @@ -0,0 +1,33 @@ +local status_ok, autopairs = pcall(require, "nvim-autopairs") +if not status_ok then + return +end +autopairs.setup({ + check_ts = true, -- treesitter integration + disable_filetype = { "TelescopePrompt" }, + ts_config = { + lua = { "string", "source" }, + javascript = { "string", "template_string" }, + java = false, + }, + + fast_wrap = { + map = "", + chars = { "{", "[", "(", '"', "'" }, + pattern = string.gsub([[ [%'%"%)%>%]%)%}%,] ]], "%s+", ""), + offset = 0, -- Offset from pattern match + end_key = "$", + keys = "qwertyuiopzxcvbnmasdfghjkl", + check_comma = true, + highlight = "PmenuSel", + highlight_grey = "LineNr", + }, +}) + + +local cmp_autopairs = require("nvim-autopairs.completion.cmp") +local cmp_status_ok, cmp = pcall(require, "cmp") +if not cmp_status_ok then + return +end +cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done({})) diff --git a/nvim/.config/nvim/lua/plugins/bufferline.lua b/nvim/.config/nvim/lua/plugins/bufferline.lua new file mode 100644 index 0000000..b93e806 --- /dev/null +++ b/nvim/.config/nvim/lua/plugins/bufferline.lua @@ -0,0 +1,23 @@ + +local status_ok, bufferline = pcall(require, "bufferline") +if not status_ok then + return +end + + +bufferline.setup({ + options = { + close_command = "Bdelete! %d", -- can be a string | function, see "Mouse actions" + right_mouse_command = "Bdelete! %d", -- can be a string | function, see "Mouse actions" + offsets = { { filetype = "NvimTree", text = "", padding = 1 } }, + separator_style = "thin", -- | "thick" | "thin" | { 'any', 'any' }, + offsets = { + { + filetype = 'NvimTree', + text = 'File Explorer', + highlight = 'Directory', + text_align = 'left' + } + } + }, +}) diff --git a/nvim/.config/nvim/lua/plugins/cmp.lua b/nvim/.config/nvim/lua/plugins/cmp.lua new file mode 100644 index 0000000..02af4dd --- /dev/null +++ b/nvim/.config/nvim/lua/plugins/cmp.lua @@ -0,0 +1,129 @@ + +local cmp_status_ok, cmp = pcall(require, "cmp") +if not cmp_status_ok then + return +end + +local snip_status_ok, luasnip = pcall(require, "luasnip") +if not snip_status_ok then + return +end +require("luasnip/loaders/from_vscode").lazy_load() + +local check_backspace = function() + local col = vim.fn.col(".") - 1 + return col == 0 or vim.fn.getline("."):sub(col, col):match("%s") +end +local kind_icons = { + Text = "", + Method = "", + Function = "", + Constructor = "", + Field = "", + Variable = "", + Class = "", + Interface = "", + Module = "", + Property = "", + Unit = "", + Value = "", + Enum = "", + Keyword = "", + Snippet = "", + Color = "", + File = "", + Reference = "", + Folder = "", + EnumMember = "", + Constant = "", + Struct = "", + Event = "", + Operator = "", + TypeParameter = "", +} + +cmp.setup({ + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) -- For `luasnip` users. + end, + }, + + mapping = cmp.mapping.preset.insert({ + [""] = cmp.mapping.select_prev_item(), + [""] = cmp.mapping.select_next_item(), + [""] = cmp.mapping(cmp.mapping.scroll_docs(-1), { "i", "c" }), + [""] = cmp.mapping(cmp.mapping.scroll_docs(1), { "i", "c" }), + [""] = cmp.mapping(cmp.mapping.complete(), { "i", "c" }), + [""] = cmp.mapping({ + i = cmp.mapping.abort(), + c = cmp.mapping.close(), + }), + -- Accept currently selected item. If none selected, `select` first item. + -- Set `select` to `false` to only confirm explicitly selected items. + [""] = cmp.mapping.confirm({ select = false }), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expandable() then + luasnip.expand() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + elseif check_backspace() then + fallback() + else + fallback() + end + end, { + "i", + "s", + }), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, { + "i", + "s", + }), + }), + formatting = { + fields = { "kind", "abbr", "menu" }, + format = function(entry, vim_item) + vim_item.kind = kind_icons[vim_item.kind] + vim_item.menu = ({ + nvim_lsp = "", + nvim_lua = "", + luasnip = "", + buffer = "", + path = "", + emoji = "", + })[entry.source.name] + return vim_item + end, + }, + sources = { + { name = "nvim_lsp" }, + { name = "nvim_lua" }, + { name = "luasnip" }, + { name = "buffer" }, + { name = "path" }, + { name = 'calc' }, + + }, + confirm_opts = { + behavior = cmp.ConfirmBehavior.Replace, + select = false, + }, + window = { + completion = cmp.config.window.bordered(), + documentation = cmp.config.window.bordered(), + }, + experimental = { + ghost_text = true, + }, +}) diff --git a/nvim/.config/nvim/lua/plugins/gitsign.lua b/nvim/.config/nvim/lua/plugins/gitsign.lua new file mode 100644 index 0000000..21a5010 --- /dev/null +++ b/nvim/.config/nvim/lua/plugins/gitsign.lua @@ -0,0 +1,7 @@ +local status_ok, gitsigns = pcall(require, "gitsigns") +if not status_ok then + return +end +gitsigns.setup({ + +}) diff --git a/nvim/.config/nvim/lua/plugins/indent-blankline.lua b/nvim/.config/nvim/lua/plugins/indent-blankline.lua new file mode 100644 index 0000000..0a29935 --- /dev/null +++ b/nvim/.config/nvim/lua/plugins/indent-blankline.lua @@ -0,0 +1,12 @@ +local status_ok, indent_blankline = pcall(require, "indent_blankline") +if not status_ok then + return +end + +indent_blankline.setup { + char = "▏", + show_first_indent_level = false, + show_trailing_blankline_indent = false, + use_treesitter = true, + show_current_context = true, +} diff --git a/nvim/.config/nvim/lua/plugins/lsp/handlers.lua b/nvim/.config/nvim/lua/plugins/lsp/handlers.lua new file mode 100644 index 0000000..09fe281 --- /dev/null +++ b/nvim/.config/nvim/lua/plugins/lsp/handlers.lua @@ -0,0 +1,88 @@ +local M = {} + +local status_cmp_ok, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp") +if not status_cmp_ok then + return +end + +M.capabilities = vim.lsp.protocol.make_client_capabilities() +M.capabilities.textDocument.completion.completionItem.snippetSupport = true +M.capabilities = cmp_nvim_lsp.default_capabilities(M.capabilities) + +M.setup = function() + local signs = { + + { name = "DiagnosticSignError", text = "" }, + { name = "DiagnosticSignWarn", text = "" }, + { name = "DiagnosticSignHint", text = "" }, + { name = "DiagnosticSignInfo", text = "" }, + } + + for _, sign in ipairs(signs) do + vim.fn.sign_define(sign.name, { texthl = sign.name, text = sign.text, numhl = "" }) + end + + local config = { + virtual_text = false, -- disable virtual text + signs = { + active = signs, -- show signs + }, + update_in_insert = true, + underline = true, + severity_sort = true, + float = { + focusable = true, + style = "minimal", + border = "rounded", + source = "always", + header = "", + prefix = "", + }, + } + + vim.diagnostic.config(config) + + vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { + border = "rounded", + }) + + vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, { + border = "rounded", + }) +end + +local function lsp_keymaps(bufnr) + local opts = { noremap = true, silent = true } + local keymap = vim.api.nvim_buf_set_keymap + keymap(bufnr, "n", "gD", "lua vim.lsp.buf.declaration()", opts) + keymap(bufnr, "n", "gd", "lua vim.lsp.buf.definition()", opts) + keymap(bufnr, "n", "K", "lua vim.lsp.buf.hover()", opts) + keymap(bufnr, "n", "gI", "lua vim.lsp.buf.implementation()", opts) + keymap(bufnr, "n", "gr", "lua vim.lsp.buf.references()", opts) + keymap(bufnr, "n", "gl", "lua vim.diagnostic.open_float()", opts) + keymap(bufnr, "n", "lf", "lua vim.lsp.buf.format{async=true}", opts) + keymap(bufnr, "n", "li", "LspInfo", opts) + + keymap(bufnr, "n", "lI", "LspInstallInfo", opts) + keymap(bufnr, "n", "la", "lua vim.lsp.buf.code_action()", opts) + keymap(bufnr, "n", "lj", "lua vim.diagnostic.goto_next({buffer=0})", opts) + keymap(bufnr, "n", "lk", "lua vim.diagnostic.goto_prev({buffer=0})", opts) + keymap(bufnr, "n", "lr", "lua vim.lsp.buf.rename()", opts) + keymap(bufnr, "n", "ls", "lua vim.lsp.buf.signature_help()", opts) + keymap(bufnr, "n", "lq", "lua vim.diagnostic.setloclist()", opts) +end + +M.on_attach = function(client, bufnr) + if client.name == "tsserver" then + client.server_capabilities.document_formatting = false + end + + + lsp_keymaps(bufnr) + local status_ok, illuminate = pcall(require, "illuminate") + if not status_ok then + return + end + illuminate.on_attach(client) +end +return M diff --git a/nvim/.config/nvim/lua/plugins/lsp/mason.lua b/nvim/.config/nvim/lua/plugins/lsp/mason.lua new file mode 100644 index 0000000..2c2488c --- /dev/null +++ b/nvim/.config/nvim/lua/plugins/lsp/mason.lua @@ -0,0 +1,60 @@ +require("plugins.lsp.handlers").setup() +local servers = { + "ansiblels", + "bashls", + "cssls", + "dockerls", + "gopls", + "html", + "jsonls", + "pyright", + "pylsp", + "rnix", + "sumneko_lua", + "marksman", + "sqls", + "terraformls", + "tflint", + "tsserver", + "yamlls", +} +local settings = { + ui = { + border = "none", + icons = { + package_installed = "◍", + package_pending = "◍", + package_uninstalled = "◍", + }, + }, + log_level = vim.log.levels.INFO, + max_concurrent_installers = 4, +} +require("mason").setup(settings) +require("mason-lspconfig").setup({ + ensure_installed = servers, + automatic_installation = true, +}) + + +local lspconfig_status_ok, lspconfig = pcall(require, "lspconfig") +if not lspconfig_status_ok then + return +end + + +for _, server in pairs(servers) do + opts = { + on_attach = require("plugins.lsp.handlers").on_attach, + capabilities = require("plugins.lsp.handlers").capabilities, + } + + server = vim.split(server, "@")[1] + + local require_ok, conf_opts = pcall(require, "plugins.lsp.settings." .. server) + if require_ok then + opts = vim.tbl_deep_extend("force", conf_opts, opts) + end + + lspconfig[server].setup(opts) +end diff --git a/nvim/.config/nvim/lua/plugins/lsp/null-ls.lua b/nvim/.config/nvim/lua/plugins/lsp/null-ls.lua new file mode 100644 index 0000000..c182e15 --- /dev/null +++ b/nvim/.config/nvim/lua/plugins/lsp/null-ls.lua @@ -0,0 +1,27 @@ + +local null_ls_status_ok, null_ls = pcall(require, "null-ls") +if not null_ls_status_ok then + return +end + +-- https://github.com/jose-elias-alvarez/null-ls.nvim/tree/main/lua/null-ls/builtins/formatting +local formatting = null_ls.builtins.formatting +-- https://github.com/jose-elias-alvarez/null-ls.nvim/tree/main/lua/null-ls/builtins/diagnostics +local diagnostics = null_ls.builtins.diagnostics + +-- https://github.com/prettier-solidity/prettier-plugin-solidity +null_ls.setup({ + debug = false, + sources = { + formatting.prettier.with({ + extra_filetypes = { "toml" }, + extra_args = { "--no-semi", "--single-quote", "--jsx-single-quote" }, + }), + formatting.black.with({ extra_args = { "--fast" } }), + formatting.stylua, + formatting.google_java_format, + diagnostics.flake8, + diagnostics.eslint, + diagnostics.markdownlint, + }, +}) diff --git a/nvim/.config/nvim/lua/plugins/lsp/settings/ansiblels.lua b/nvim/.config/nvim/lua/plugins/lsp/settings/ansiblels.lua new file mode 100644 index 0000000..d1b5a82 --- /dev/null +++ b/nvim/.config/nvim/lua/plugins/lsp/settings/ansiblels.lua @@ -0,0 +1,5 @@ +return{ + filetype= { + "yaml.ansible" +} +} diff --git a/nvim/.config/nvim/lua/plugins/markdown-preview.lua b/nvim/.config/nvim/lua/plugins/markdown-preview.lua new file mode 100644 index 0000000..9907439 --- /dev/null +++ b/nvim/.config/nvim/lua/plugins/markdown-preview.lua @@ -0,0 +1 @@ +vim.keymap.set("n", "mp", ":MarkdownPreviewToggle", { silent = true }) diff --git a/nvim/.config/nvim/lua/plugins/neogit.lua b/nvim/.config/nvim/lua/plugins/neogit.lua new file mode 100644 index 0000000..7aa1220 --- /dev/null +++ b/nvim/.config/nvim/lua/plugins/neogit.lua @@ -0,0 +1,11 @@ +local status_ok, neogit = pcall(require, "neogit") +if not status_ok then + return +end + +neogit.setup{ + disable_commit_confirmation = true, + disable_context_highlighting = true +} + +vim.keymap.set('n', 'gs', ':Neogit kind=split', {silent = true}) diff --git a/nvim/.config/nvim/lua/plugins/nvim-tree.lua b/nvim/.config/nvim/lua/plugins/nvim-tree.lua new file mode 100644 index 0000000..9963733 --- /dev/null +++ b/nvim/.config/nvim/lua/plugins/nvim-tree.lua @@ -0,0 +1,38 @@ + +local status_ok, nvim_tree = pcall(require, "nvim-tree") +if not status_ok then + return +end + +local config_status_ok, nvim_tree_config = pcall(require, "nvim-tree.config") +if not config_status_ok then + return +end +local tree_cb = nvim_tree_config.nvim_tree_callback +nvim_tree.setup({ + update_focused_file = { + enable = true, + update_cwd = true, + }, + diagnostics = { + enable = true, + show_on_dirs = true, + icons = { + hint = "", + info = "", + warning = "", + error = "", + }, + }, + view = { + width = 30, + side = "left", + mappings = { + list = { + { key = { "l", "", "o" }, cb = tree_cb("edit") }, + { key = "h", cb = tree_cb("close_node") }, + { key = "v", cb = tree_cb("vsplit") }, + }, + }, + }, +}) diff --git a/nvim/.config/nvim/lua/plugins/telescope.lua b/nvim/.config/nvim/lua/plugins/telescope.lua new file mode 100644 index 0000000..fd6684b --- /dev/null +++ b/nvim/.config/nvim/lua/plugins/telescope.lua @@ -0,0 +1,51 @@ +local status_ok, telescope = pcall(require, "telescope") +if not status_ok then + return +end + +local actions = require("telescope.actions") +local utils = require("telescope.utils") +telescope.setup { + defaults = { + path_display = { "absolute" }, + file_ignore_patterns = { ".git/", "node_modules" }, + mappings = { + i = { + [""] = actions.cycle_history_next, + [""] = actions.cycle_history_prev, + [""] = actions.cycle_history_next, + [""] = actions.cycle_history_prev, + [""] = actions.move_selection_next, + [""] = actions.move_selection_previous, + }, + }, + }, + extensions = { + fzf = { + fuzzy = true, -- false will only do exact matching + override_generic_sorter = true, -- override the generic sorter + override_file_sorter = true, -- override the file sorter + case_mode = "smart_case", -- or "ignore_case" or "respect_case" + -- the default case_mode is "smart_case" + }, + }, + pickers = { + find_files = { + no_ignore = true, + no_ignore_parent = true, + }, + }, +} + +telescope.load_extension('fzf') +require'telescope.themes'.get_ivy() + +local keymap = vim.keymap.set +local opts = { silent = true } + +keymap("n", "", ":Telescope git_files", opts) +keymap("n", "ff", ":Telescope find_files", opts) +keymap("n", "fF", function () builtin.find_files({ cwd = utils.buffer_dir() }) end, opts) +keymap("n", "/", ":Telescope live_grep", opts) +keymap("n", "pp", ":Telescope projects", opts) +keymap("n", ",", ":Telescope buffers", opts) diff --git a/nvim/.config/nvim/lua/plugins/treesitter.lua b/nvim/.config/nvim/lua/plugins/treesitter.lua new file mode 100644 index 0000000..0a169c6 --- /dev/null +++ b/nvim/.config/nvim/lua/plugins/treesitter.lua @@ -0,0 +1,33 @@ +local status_ok, treesitter = pcall(require, "nvim-treesitter") +if not status_ok then + return +end + +local status_ok, configs = pcall(require, "nvim-treesitter.configs") +if not status_ok then + return +end + +configs.setup({ + ensure_installed = { + all + }, + highlight = { + enable = true, + }, + autopairs = { + enable = true, + }, + indent = { + enable = true, + }, + + context_commentstring = { + enable = true, + enable_autocmd = false, + }, + + endwise = { + enable = true, + }, +}) diff --git a/nvim/.config/nvim/lua/plugins/vim-easyescape.lua b/nvim/.config/nvim/lua/plugins/vim-easyescape.lua new file mode 100644 index 0000000..97e94f7 --- /dev/null +++ b/nvim/.config/nvim/lua/plugins/vim-easyescape.lua @@ -0,0 +1,5 @@ +vim.g.easyescape_chars = { + j = 0, + k = 0 +} +vim.g.easyescape_timeout = 99 diff --git a/nvim/.config/nvim/lua/plugins/which-key.lua b/nvim/.config/nvim/lua/plugins/which-key.lua new file mode 100644 index 0000000..46b9b6d --- /dev/null +++ b/nvim/.config/nvim/lua/plugins/which-key.lua @@ -0,0 +1,2 @@ +vim.api.nvim_set_option("timeoutlen", 300) +require("which-key").setup({})