diff --git a/init.lua b/init.lua index 5faa983..1e2b018 100644 --- a/init.lua +++ b/init.lua @@ -13,8 +13,12 @@ if fn.empty(fn.glob(install_path)) > 0 then vim.cmd 'packadd packer.nvim' end vim.cmd [[packadd packer.nvim]] -vim.cmd 'autocmd BufWritePost plugins.lua PackerCompile' -- Auto compile when there are changes in plugins.lua - +vim.cmd([[ + augroup packer_user_config + autocmd! + autocmd BufWritePost plugins.lua source | PackerCompile + augroup end +]]) local utils = require('utils') -- Install plugins require('plugins') @@ -23,10 +27,10 @@ require('keymappings') cmd 'colorscheme gruvbox-material' -- Put your favorite colorscheme here cmd 'syntax enable' cmd 'filetype plugin indent on' ---opt.noswapfile = true --- opt.nobackup = true -opt.spelllang = 'en,de' -local indent = 4 +utils.opt('o', 'swapfile', false) +utils.opt('o', 'backup', false) +utils.opt('o', 'spelllang', 'en,de') +local indent = 2 utils.opt('b', 'expandtab', true) utils.opt('b', 'shiftwidth', indent) utils.opt('b', 'smartindent', true) @@ -62,7 +66,15 @@ local ts = require 'nvim-treesitter.configs' ts.setup {ensure_installed = 'maintained', highlight = {enable = true}} -------------------- FZF ----------------------------------- -utils.map('n', '', ':FZF') +--utils.map('n', '', ':FZF') +-------------------- TELESCOPE ----------------------------- +utils.map('n', 'f', 'Telescope find_files') +utils.map('n', '', 'Telescope find_files') +utils.map('n', 'g', 'Telescope git_files') +utils.map('n', 'o', 'Telescope oldfiles') +utils.map('n', 'h', 'Telescope command_history') +utils.map('n', '', 'Telescope commands') +utils.map('n', 'fb', 'Telescope buffers') -------------------- LSP ----------------------------------- local lsp = require 'lspconfig' @@ -82,6 +94,84 @@ utils.map('n', 'r', 'lua vim.lsp.buf.references()') utils.map('n', 's', 'lua vim.lsp.buf.document_symbol()') -------------------- GITSIGNS ------------------------------ -require('gitsigns').setup() +-- require('gitsigns').setup() -------------------- LIGHTBULB ----------------------------- require('nvim-lightbulb').update_lightbulb() +-------------------- CMP ----------------------------------- +require('cmp_plug') +-- local cmp = require'cmp' +-- cmp.setup({ +-- snippet = { +-- expand = function(args) +-- vim.fn["vsnip#anonymous"](args.body) +-- end, +-- }, +-- mapping = { +-- [''] = cmp.mapping.confirm({ select = true }), +-- }, +-- sources = { +-- { name = '...' }, +-- ... +-- } +-- }) +-- local cmp = require 'cmp' +-- local types = require('cmp.types') +-- cmp.setup { +-- completion = { +-- autocomplete = { +-- types.cmp.TriggerEvent.TextChanged, +-- }, +-- completeopt = 'menu,menuone,noselect', +-- keyword_pattern = [[\%(-\?\d\+\%(\.\d\+\)\?\|\h\w*\%(-\w*\)*\)]], +-- keyword_length = 1, +-- get_trigger_characters = function(trigger_characters) +-- return trigger_characters +-- end +-- }, +-- snippet = { +-- expand = function(args) +-- require('luasnip').lsp_expand(args.body) +-- end, +-- }, +-- mapping = { +-- [''] = cmp.mapping.select_prev_item(), +-- [''] = cmp.mapping.select_next_item(), +-- [''] = cmp.mapping.scroll_docs(-4), +-- [''] = cmp.mapping.scroll_docs(4), +-- [''] = cmp.mapping.complete(), +-- [''] = cmp.mapping.close(), +-- [''] = cmp.mapping.confirm { +-- behavior = cmp.ConfirmBehavior.Replace, +-- select = true, +-- }, +-- [''] = function(fallback) +-- if vim.fn.pumvisible() == 1 then +-- vim.fn.feedkeys(vim.api.nvim_replace_termcodes('', true, true, true), 'n') +-- elseif luasnip.expand_or_jumpable() then +-- vim.fn.feedkeys(vim.api.nvim_replace_termcodes('luasnip-expand-or-jump', true, true, true), '') +-- else +-- fallback() +-- end +-- end, +-- [''] = function(fallback) +-- if vim.fn.pumvisible() == 1 then +-- vim.fn.feedkeys(vim.api.nvim_replace_termcodes('', true, true, true), 'n') +-- elseif luasnip.jumpable(-1) then +-- vim.fn.feedkeys(vim.api.nvim_replace_termcodes('luasnip-jump-prev', true, true, true), '') +-- else +-- fallback() +-- end +-- end, +-- }, + -- sources = { + -- { name = 'nvim_lsp' }, + -- { name = 'luasnip' }, + -- }, +-- } +-------------------- NVIM-TREE ----------------------------- +g.nvim_tree_auto_open = 1 +-------------------- NVIM-COMMENT -------------------------- +require('nvim_comment').setup() +require('nvim_comment').setup({line_mapping = '', operator_mapping = ''}) +utils.map('n', '', 'gcc') +utils.map('v', '', 'gc') diff --git a/lua/cmp_plug.lua b/lua/cmp_plug.lua new file mode 100644 index 0000000..bf2d9b8 --- /dev/null +++ b/lua/cmp_plug.lua @@ -0,0 +1,93 @@ +local cmp = require('cmp') + +local t = function(str) + return vim.api.nvim_replace_termcodes(str, true, true, true) +end + +local check_back_space = function() + local col = vim.fn.col(".") - 1 + return col == 0 or vim.fn.getline("."):sub(col, col):match("%s") ~= nil +end + +cmp.setup { + + formatting = { + format = function(entry, vim_item) + -- fancy icons and a name of kind + vim_item.kind = require("lspkind").presets.default[vim_item.kind] .. + " " .. vim_item.kind + -- set a name for each source + vim_item.menu = ({ + buffer = "[Buffer]", + nvim_lsp = "[LSP]", + ultisnips = "[UltiSnips]", + nvim_lua = "[Lua]", + cmp_tabnine = "[TabNine]", + look = "[Look]", + path = "[Path]", + spell = "[Spell]", + calc = "[Calc]", + emoji = "[Emoji]" + })[entry.source.name] + return vim_item + end + }, + mapping = { + [''] = cmp.mapping.select_prev_item(), + [''] = cmp.mapping.select_next_item(), + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.close(), + [''] = cmp.mapping.confirm({ + behavior = cmp.ConfirmBehavior.Insert, + select = true + }), + [""] = cmp.mapping(function(fallback) + if vim.fn.pumvisible() == 1 then + if vim.fn["UltiSnips#CanExpandSnippet"]() == 1 or + vim.fn["UltiSnips#CanJumpForwards"]() == 1 then + return vim.fn.feedkeys(t( + "=UltiSnips#ExpandSnippetOrJump()")) + end + + vim.fn.feedkeys(t(""), "n") + elseif check_back_space() then + vim.fn.feedkeys(t(""), "n") + else + fallback() + end + end, {"i", "s"}), + [""] = cmp.mapping(function(fallback) + if vim.fn.pumvisible() == 1 then + vim.fn.feedkeys(t(""), "n") + else + fallback() + end + end, {"i", "s"}) + }, + snippet = {expand = function(args) vim.fn["UltiSnips#Anon"](args.body) end}, + sources = { + {name = 'buffer'}, {name = 'nvim_lsp'}, {name = "ultisnips"}, + {name = "nvim_lua"}, {name = "look"}, {name = "path"}, + {name = 'cmp_tabnine'}, {name = "calc"}, {name = "spell"}, + {name = "emoji"} + }, + completion = {completeopt = 'menu,menuone,noinsert'} +} + +-- Autopairs +--require("nvim-autopairs.completion.cmp").setup({ +-- map_cr = true, +-- map_complete = true, +-- auto_select = true +--}) + +-- TabNine +--local tabnine = require('cmp_tabnine.config') +--tabnine:setup({max_lines = 1000, max_num_results = 20, sort = true}) + +-- Database completion +vim.api.nvim_exec([[ +autocmd FileType sql,mysql,plsql lua require('cmp').setup.buffer({ sources = {{ name = 'vim-dadbod-completion' }} }) +]], false) diff --git a/lua/keymappings.lua b/lua/keymappings.lua index b367f5e..4a8ebc3 100644 --- a/lua/keymappings.lua +++ b/lua/keymappings.lua @@ -11,6 +11,20 @@ utils.map('v', 'y', '"+y') utils.map('n', 'Y', '"+yg_') utils.map('n', 'y', '"+y') utils.map('n', 'yy', '"+yy') --- Tabs and Split -utils.map('n', 'F2', ':tabnew .') +-- Tabs +utils.map('n', '', ':tabnew .') +utils.map('i', '', ':tabnew .') +utils.map('n', '', 'gt') +utils.map('n', '', 'gT') +-- Split movement +utils.map('n', '', ':wincmd k') +utils.map('n', '', ':wincmd j') +utils.map('n', '', ':wincmd h') +utils.map('n', '', ':wincmd l') +-- Open a new vertical split window with Ctrl - F2 +utils.map('n', '', ':vsplit .') +utils.map('i', '', ':vsplit .') +-- Open a new horizontal split window with Shift - F2 +utils.map('n', '', ':split .') +utils.map('i', '', ':split .') diff --git a/lua/plugins.lua b/lua/plugins.lua index 068bb39..4aa41a6 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -13,4 +13,19 @@ return require('packer').startup(function() use {'nvim-lua/plenary.nvim'} use {'lewis6991/gitsigns.nvim'} use {'kosayoda/nvim-lightbulb'} + use { + 'kyazdani42/nvim-tree.lua', + requires = 'kyazdani42/nvim-web-devicons' + } + use {'terrortylor/nvim-comment'} + use { + 'hrsh7th/nvim-cmp', + requires = { + 'hrsh7th/cmp-buffer', 'hrsh7th/cmp-nvim-lsp', + 'quangnguyen30192/cmp-nvim-ultisnips', 'hrsh7th/cmp-nvim-lua', + 'octaltree/cmp-look', 'hrsh7th/cmp-path', 'hrsh7th/cmp-calc', + 'f3fora/cmp-spell', 'hrsh7th/cmp-emoji' + } + } + use {'onsails/lspkind-nvim'} end)