diff --git a/lua/core.lua b/lua/core.lua index 1f9724f..acdc51c 100644 --- a/lua/core.lua +++ b/lua/core.lua @@ -1,35 +1,30 @@ -- CORE SETTINGS -local opt = vim.o +local o = vim.o local global = vim.g -- look and feel vim.opt.shortmess:append({I = true}) -- remove intro message -opt.termguicolors = true -opt.ruler = true -opt.relativenumber = true -opt.number = true -opt.showmode = false -opt.scrolloff = 10 -opt.softtabstop = 2 -opt.shiftwidth = 2 +o.termguicolors = true +o.ruler = true +o.relativenumber = true +o.number = true +o.showmode = false +o.scrolloff = 10 +o.softtabstop = 2 +o.shiftwidth = 2 -- controlling -opt.ignorecase = true -opt.smartcase = true -opt.smartindent = true -opt.mouse = "i" -opt.autoindent = true - --- completion for lua -opt.completeopt = 'noinsert' +vim.opt.completeopt = {'menu', 'menuone', 'noselect'} +o.ignorecase = true +o.smartcase = true +o.smartindent = true +o.mouse = "i" +o.autoindent = true -- neoformat settings. global.neoformat_basic_format_align = 1 global.neoformat_basic_format_trim = 1 --- glow settings -global.glow_border = "rounded" - -- leader settings global.mapleader = ' ' diff --git a/lua/mappings.lua b/lua/mappings.lua index 0f70bd8..553c7d2 100644 --- a/lua/mappings.lua +++ b/lua/mappings.lua @@ -1,52 +1,100 @@ +local map = vim.api.nvim_set_keymap + -- generic mappings -vim.api.nvim_set_keymap('v', '<', '', '>gv', {noremap = true}) -vim.api.nvim_set_keymap('n', 'Y', 'y$', {noremap = true}) -vim.api.nvim_set_keymap('n', 'n', 'nzzzv', {noremap = true}) -vim.api.nvim_set_keymap('n', 'N', 'Nzzzv', {noremap = true}) +map('v', '<', '', '>gv', {noremap = true}) +map('n', 'Y', 'y$', {noremap = true}) +map('n', 'n', 'nzzzv', {noremap = true}) +map('n', 'N', 'Nzzzv', {noremap = true}) + -- Shortcutting split navigation -vim.api.nvim_set_keymap('', '', 'h', {}) -vim.api.nvim_set_keymap('', '', 'j', {}) -vim.api.nvim_set_keymap('', '', 'k', {}) -vim.api.nvim_set_keymap('', '', 'l', {}) -vim.api.nvim_set_keymap('', '', 'H', {}) -vim.api.nvim_set_keymap('', '', 'J', {}) -vim.api.nvim_set_keymap('', '', 'K', {}) -vim.api.nvim_set_keymap('', '', 'L', {}) -vim.api.nvim_set_keymap('', '>', '>', {}) -vim.api.nvim_set_keymap('', '', '<', {}) -vim.api.nvim_set_keymap('', '', 'T', {}) +map('', '', 'h', {}) +map('', '', 'j', {}) +map('', '', 'k', {}) +map('', '', 'l', {}) +map('', '', 'H', {}) +map('', '', 'J', {}) +map('', '', 'K', {}) +map('', '', 'L', {}) +map('', '>', '>', {}) +map('', '', '<', {}) +map('', '', 'T', {}) + -- undo to the last , . or ! -vim.api.nvim_set_keymap('i', ',', ',u', {noremap = true}) -vim.api.nvim_set_keymap('i', '.', '.u', {noremap = true}) -vim.api.nvim_set_keymap('i', '!', '!u', {noremap = true}) -vim.api.nvim_set_keymap('i', '?', '?u', {noremap = true}) +map('i', ',', ',u', {noremap = true}) +map('i', '.', '.u', {noremap = true}) +map('i', '!', '!u', {noremap = true}) +map('i', '?', '?u', {noremap = true}) -- plugin mappings -- gitsigns -vim.api.nvim_set_keymap('', 'gs', ':Gitsigns toggle_signs', +map('', 'gs', ':Gitsigns toggle_signs', {silent = true}) -- lsp stuff vim.api.nvim_buf_set_keymap(0, 'n', 'K', 'lua vim.lsp.buf.hover()', {noremap = true}) -vim.api.nvim_set_keymap('', 'K', +map('', 'K', 'lua vim.diagnostic.open_float()', {noremap = true}) -vim.api.nvim_set_keymap('', 'qf', +map('', 'qf', 'lua vim.diagnostic.setqflist({open = false})Telescope quickfix', {silent = true}) + -- toggle tagbar -vim.api.nvim_set_keymap('', 'tt', ':TagbarToggle', {silent = true}) +map('', 'tt', ':TagbarToggle', {silent = true}) + -- toggle NvimTree -vim.api.nvim_set_keymap('', '', ':NvimTreeToggle', {silent = true}) +map('', '', ':NvimTreeToggle', {silent = true}) + -- toggle formatter -vim.api.nvim_set_keymap('', 'fm', ':Neoformat', {silent = true}) +map('', 'fm', ':Neoformat', {silent = true}) + -- toggle Hop -vim.api.nvim_set_keymap('', 'b', ':HopWordBC', {silent = true}) -vim.api.nvim_set_keymap('', 'w', ':HopWordAC', {silent = true}) -vim.api.nvim_set_keymap('', 'l', ':HopWordCurrentLine', +map('', 'b', ':HopWordBC', {silent = true}) +map('', 'w', ':HopWordAC', {silent = true}) +map('', 'l', ':HopWordCurrentLine', {silent = true}) + -- telescope stuff -vim.api.nvim_set_keymap('', 'fd', ':Telescope fd', {silent = true}) -vim.api.nvim_set_keymap('', 'tb', ':Telescope buffers', +map('', 'fd', ':Telescope fd', {silent = true}) +map('', 'tb', ':Telescope buffers', {silent = true}) + +-- Barbar controls +local opts = { noremap = true, silent = true } +-- Move to previous/next +map('n', '', 'BufferPrevious', opts) +map('n', '', 'BufferNext', opts) +-- Re-order to previous/next +map('n', '', 'BufferMovePrevious', opts) +map('n', '', 'BufferMoveNext', opts) +-- Goto buffer in position... +map('n', '', 'BufferGoto 1', opts) +map('n', '', 'BufferGoto 2', opts) +map('n', '', 'BufferGoto 3', opts) +map('n', '', 'BufferGoto 4', opts) +map('n', '', 'BufferGoto 5', opts) +map('n', '', 'BufferGoto 6', opts) +map('n', '', 'BufferGoto 7', opts) +map('n', '', 'BufferGoto 8', opts) +map('n', '', 'BufferGoto 9', opts) +map('n', '', 'BufferLast', opts) +-- Pin/unpin buffer +map('n', '', 'BufferPin', opts) +-- Close buffer +map('n', '', 'BufferClose', opts) +-- Wipeout buffer +-- :BufferWipeout +-- Close commands +-- :BufferCloseAllButCurrent +-- :BufferCloseAllButPinned +-- :BufferCloseAllButCurrentOrPinned +-- :BufferCloseBuffersLeft +-- :BufferCloseBuffersRight +-- Magic buffer-picking mode +map('n', '', 'BufferPick', opts) +-- Sort automatically by... +map('n', 'bb', 'BufferOrderByBufferNumber', opts) +map('n', 'bd', 'BufferOrderByDirectory', opts) +map('n', 'bl', 'BufferOrderByLanguage', opts) +map('n', 'bw', 'BufferOrderByWindowNumber', opts) diff --git a/lua/pluginList.lua b/lua/pluginList.lua index bb737ca..a7b50dd 100644 --- a/lua/pluginList.lua +++ b/lua/pluginList.lua @@ -17,12 +17,11 @@ require('packer').init { } return require('packer').startup(function(use) - use {'wbthomason/packer.nvim', event = "VimEnter"} + use {'wbthomason/packer.nvim'} -- core UI use { 'b4skyx/serenade', - after = 'packer.nvim', config = function() vim.g.serenade_enable_italic = 1 vim.g.serenade_sign_column_background = 'none' @@ -30,15 +29,22 @@ return require('packer').startup(function(use) vim.cmd("colorscheme serenade") end } - use {'kyazdani42/nvim-web-devicons', after = 'packer.nvim'} + use {'kyazdani42/nvim-web-devicons'} use { 'nvim-lualine/lualine.nvim', after = {'serenade', 'nvim-web-devicons'}, config = function() require "plugins.statusline" end } + use { + 'romgrk/barbar.nvim', + requires = {'kyazdani42/nvim-web-devicons'}, + event = 'BufAdd', + after = {'nvim-web-devicons', 'serenade'}, + config = function() require "plugins.barbar" end + } -- lsp stuff - use {'neovim/nvim-lspconfig', event = "BufEnter"} + use {'neovim/nvim-lspconfig', event = "UIEnter"} use { 'williamboman/nvim-lsp-installer', config = function() require "plugins.lspinstall" end, @@ -47,7 +53,7 @@ return require('packer').startup(function(use) use { "ray-x/lsp_signature.nvim", after = "nvim-lsp-installer", - config = function() require "plugins.lsp_signature" end + config = function() require "plugins.lsp-signature" end } -- tree sitter @@ -59,45 +65,47 @@ return require('packer').startup(function(use) } -- completer + use {'L3MON4D3/LuaSnip', event = "UIEnter"} use { - 'ms-jpq/coq_nvim', - branch = 'coq', - -- after = 'nvim-lsp-installer', - run = ':COQdeps', - config = function() require "plugins.coq" end - } - use {'ms-jpq/coq.artifacts', after = 'coq_nvim', branch = 'artifacts'} - use { - 'ms-jpq/coq.thirdparty', - branch = '3p', - after = 'coq_nvim', - config = function() - require("coq_3p") { - {src = "nvimlua", short_name = "nLUA"}, {src = "repl"}, - {src = "vimtex", short_name = "vTEX"} - } - - end + event = "InsertEnter", + after = {'nvim-lsp-installer', 'nvim-treesitter', 'LuaSnip'}, + "hrsh7th/nvim-cmp", + config = function() require "plugins.cmp" end, + requires = { + -- local + {'hrsh7th/cmp-cmdline', after = 'nvim-cmp'}, + {'hrsh7th/cmp-buffer', after = 'nvim-cmp'}, + {'hrsh7th/cmp-path', after = 'nvim-cmp'}, + {'petertriho/cmp-git', after = 'nvim-cmp'}, -- end + -- lsp + {'hrsh7th/cmp-nvim-lsp-document-symbol', after = 'nvim-cmp'}, + {'hrsh7th/cmp-nvim-lsp', after = 'nvim-cmp'}, -- end + -- TS + {'ray-x/cmp-treesitter', after = 'nvim-cmp'}, -- end + -- Snip + {'saadparwaiz1/cmp_luasnip', after = {'nvim-cmp', 'LuaSnip'}} + } } -- formating and editing + use { + "windwp/nvim-autopairs", + after = 'nvim-cmp', + config = function() require("plugins.nvim-autopairs") end + } use {"sbdchd/neoformat", cmd = "Neoformat"} use { "mattn/emmet-vim", ft = {'html', 'htmldjango', 'css', 'markdown'}, setup = function() require "plugins.emmet" end } - use {"machakann/vim-sandwich", event = "BufEnter"} + use {"machakann/vim-sandwich", event = "UIEnter"} use { 'numToStr/Comment.nvim', + event = "UIEnter", config = function() require('Comment').setup() end } - use { - "windwp/nvim-autopairs", - event = "BufEnter", - config = function() require("plugins.nvim-autopairs") end - } -- navigation use { @@ -114,7 +122,7 @@ return require('packer').startup(function(use) use { 'abecodes/tabout.nvim', config = function() require('tabout').setup {} end, - after = {'nvim-treesitter', 'nvim-autopairs', 'coq_nvim'} -- if a completion plugin is using tabs load it before + after = {'nvim-treesitter', 'nvim-autopairs', 'nvim-cmp'} -- if a completion plugin is using tabs load it before } use { 'nvim-telescope/telescope.nvim', @@ -135,8 +143,7 @@ return require('packer').startup(function(use) -- eye-candy use { "lukas-reineke/indent-blankline.nvim", - after = {"nvim-treesitter", "nvim-treesitter-context"}, - event = "UIEnter", + after = {"nvim-treesitter"}, config = function() require "plugins.indent-blankline" end } use { @@ -177,7 +184,7 @@ return require('packer').startup(function(use) } use { 'norcalli/nvim-colorizer.lua', - after = "packer.nvim", + event = "BufEnter", config = function() require "plugins.nvim-colorizer" end } @@ -186,12 +193,12 @@ return require('packer').startup(function(use) use { "mickael-menu/zk-nvim", requires = {"nvim-telescope/telescope.nvim"}, - after = {"nvim-telescope/telescope.nvim"}, + after = {"telescope.nvim"}, ft = {'markdown'}, config = function() require "plugins.zk" end } -- fixes and misc. stuff - use {"antoinemadec/FixCursorHold.nvim"} + use {"antoinemadec/FixCursorHold.nvim", event = "UIEnter"} end) -- vim:set shiftwidth=4 tabstop=4: diff --git a/lua/plugins/barbar.lua b/lua/plugins/barbar.lua new file mode 100644 index 0000000..32370e3 --- /dev/null +++ b/lua/plugins/barbar.lua @@ -0,0 +1,91 @@ +-- Set barbar's options +require'bufferline'.setup { + -- Enable/disable animations + animation = false, + + -- Enable/disable auto-hiding the tab bar when there is a single buffer + auto_hide = false, + + -- Enable/disable current/total tabpages indicator (top right corner) + tabpages = true, + + -- Enable/disable close button + closable = true, + + -- Enables/disable clickable tabs + -- - left-click: go to buffer + -- - middle-click: delete buffer + clickable = true, + + -- Enable/disable icons + -- if set to 'numbers', will show buffer index in the tabline + -- if set to 'both', will show buffer index and icons in the tabline + icons = true, + + -- If set, the icon color will follow its corresponding buffer + -- highlight group. By default, the Buffer*Icon group is linked to the + -- Buffer* group (see Highlighting below). Otherwise, it will take its + -- default value as defined by devicons. + icon_custom_colors = true, + + -- Configure icons on the bufferline. + icon_separator_active = '▎', + icon_separator_inactive = '▎', + icon_close_tab = '', + icon_close_tab_modified = '●', + icon_pinned = '車', + + -- If true, new buffers will be inserted at the start/end of the list. + -- Default is to insert after current buffer. + insert_at_end = false, + insert_at_start = false, + + -- Sets the maximum padding width with which to surround each tab + maximum_padding = 1, + + -- Sets the maximum buffer name length. + maximum_length = 30, + + -- If set, the letters for each buffer in buffer-pick mode will be + -- assigned based on their name. Otherwise or in case all letters are + -- already assigned, the behavior is to assign letters in order of + -- usability (see order below) + semantic_letters = true, + + -- New buffer letters are assigned in this order. This order is + -- optimal for the qwerty keyboard layout but might need adjustement + -- for other layouts. + letters = 'asdfjkl;ghnmxcvbziowerutyqpASDFJKLGHNMXCVBZIOWERUTYQP', + + -- Sets the name of unnamed buffers. By default format is "[Buffer X]" + -- where X is the buffer number. But only a static string is accepted here. + no_name_title = nil +} + +-- nvim-tree integration +local nvim_tree_events = require('nvim-tree.events') +local bufferline_state = require('bufferline.state') + +-- track the window id of nvim-tree +local id + +local function get_tree_size() return vim.api.nvim_win_get_width(id) end + +nvim_tree_events.on_tree_open(function() + id = vim.api.nvim_eval('win_getid()') + bufferline_state.set_offset(get_tree_size()) +end) + +nvim_tree_events.on_tree_resize(function() + if id ~= nil then + if vim.api.nvim_eval('win_gettype(' .. id .. ')') ~= 'unknown' then + bufferline_state.set_offset(get_tree_size()) + end + end +end) + +nvim_tree_events.on_tree_close(function() + id = nil + bufferline_state.set_offset(0) +end) + diff --git a/lua/plugins/cmp.lua b/lua/plugins/cmp.lua new file mode 100644 index 0000000..1a35369 --- /dev/null +++ b/lua/plugins/cmp.lua @@ -0,0 +1,79 @@ +local cmp = require 'cmp' +local luasnip = require("luasnip") + +local has_words_before = function() + local line, col = unpack(vim.api.nvim_win_get_cursor(0)) + return col ~= 0 and + vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, + col) + :match("%s") == nil +end + +cmp.setup({ + snippet = { + -- REQUIRED - you must specify a snippet engine + expand = function(args) + -- vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users. + require('luasnip').lsp_expand(args.body) -- For `luasnip` users. + -- require('snippy').expand_snippet(args.body) -- For `snippy` users. + -- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users. + end + }, + window = { + -- completion = cmp.config.window.bordered(), + -- documentation = cmp.config.window.bordered(), + }, + mapping = cmp.mapping.preset.insert({ + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.abort(), + [''] = cmp.mapping.confirm({select = true}), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + 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"}) + }), + sources = cmp.config.sources({ + {name = 'nvim_lsp'}, {name = 'treesitter'}, {name = 'luasnip'} -- For luasnip users. + }, {{name = 'buffer'}, {name = 'path'}}) +}) + +-- Use buffer source for `/` (if you enabled `native_menu`, this won't work anymore). +cmp.setup.cmdline('/', { + mapping = cmp.mapping.preset.cmdline(), + sources = {{name = 'nvim_lsp_document_symbol'}, {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'}}) +}) + +-- 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'}}) +}) + +-- Set config for neovim config file +cmp.setup.filetype('lua', { + sources = cmp.config.sources({{name = 'plugins'}}, {{name = 'buffer'}}) +}) diff --git a/lua/plugins/coq.lua b/lua/plugins/coq.lua deleted file mode 100644 index cdc4e29..0000000 --- a/lua/plugins/coq.lua +++ /dev/null @@ -1,6 +0,0 @@ -vim.g.coq_settings = { - keymap = {recommended = false}, -- pre_select = true need a way to make tab enter - auto_start = true, - display = {ghost_text = {enabled = false}, icons = {mode = "none"}, preview = {border = "rounded" }} -} -vim.cmd('COQnow -s') diff --git a/lua/plugins/lsp_signature.lua b/lua/plugins/lsp-signature.lua similarity index 100% rename from lua/plugins/lsp_signature.lua rename to lua/plugins/lsp-signature.lua diff --git a/lua/plugins/nvim-autopairs.lua b/lua/plugins/nvim-autopairs.lua index 5b0bde4..b48dd9f 100644 --- a/lua/plugins/nvim-autopairs.lua +++ b/lua/plugins/nvim-autopairs.lua @@ -1,42 +1,8 @@ -local remap = vim.api.nvim_set_keymap local npairs = require('nvim-autopairs') -npairs.setup({map_bs = true, map_cr = true}) +npairs.setup({map_bs = true, map_cr = true, map_c_w = true}) -vim.g.coq_settings = {keymap = {recommended = false}} - --- these mappings are coq recommended mappings unrelated to nvim-autopairs -remap('i', '', [[pumvisible() ? "" : ""]], - {expr = true, noremap = true}) -remap('i', '', [[pumvisible() ? "" : ""]], - {expr = true, noremap = true}) -remap('i', '', [[pumvisible() ? "" : ""]], - {expr = true, noremap = true}) -remap('i', '', [[pumvisible() ? "" : ""]], - {expr = true, noremap = true}) - --- skip it, if you use another global object -_G.MUtils = {} - -MUtils.CR = function() - if vim.fn.pumvisible() ~= 0 then - if vim.fn.complete_info({'selected'}).selected ~= -1 then - return npairs.esc('') - else - return npairs.esc('') .. npairs.autopairs_cr() - end - else - return npairs.autopairs_cr() - end -end -remap('i', '', 'v:lua.MUtils.CR()', {expr = true, noremap = true}) - -MUtils.BS = function() - if vim.fn.pumvisible() ~= 0 and vim.fn.complete_info({'mode'}).mode == - 'eval' then - return npairs.esc('') .. npairs.autopairs_bs() - else - return npairs.autopairs_bs() - end -end -remap('i', '', 'v:lua.MUtils.BS()', {expr = true, noremap = true}) +-- If you want insert `(` after select function or method item +local cmp_autopairs = require('nvim-autopairs.completion.cmp') +local cmp = require('cmp') +cmp.event:on('confirm_done', cmp_autopairs.on_confirm_done()) diff --git a/lua/plugins/nvim-tree.lua b/lua/plugins/nvim-tree.lua index 3bfdb59..5a7f7b9 100644 --- a/lua/plugins/nvim-tree.lua +++ b/lua/plugins/nvim-tree.lua @@ -1,3 +1,4 @@ +-- vim:set shiftwidth=4 tabstop=4: -- following options are the default -- each of these are documented in `:help nvim-tree.OPTION_NAME` require'nvim-tree'.setup { @@ -14,11 +15,5 @@ require'nvim-tree'.setup { icons = {hint = "", info = "", warning = "", error = ""} }, system_open = {cmd = nil, args = {}}, - view = { - width = 30, - height = 30, - hide_root_folder = false, - side = 'left', - } + view = {width = 30, height = 30, hide_root_folder = false, side = 'left'} } -