diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..5a22baa --- /dev/null +++ b/TODO.md @@ -0,0 +1,9 @@ +# Nvim Config Rewrite - TODO +-[ ] LSP for: + -[ ] Python + -[ ] Kotlin + -[ ] Bash/Shell scripts + -[ ] JavaScript + -[ ] Java +-[ ] Auto close neogit/nvimtree panes when they are the only thing left. +-[ ] Start with file focused instead of nvimtree. diff --git a/nvim/init.lua b/nvim/init.lua new file mode 100644 index 0000000..b7f6a85 --- /dev/null +++ b/nvim/init.lua @@ -0,0 +1,39 @@ +vim.opt.termguicolors = true +vim.opt.clipboard = 'unnamed,unnamedplus' +vim.opt.timeoutlen = 300 +vim.opt.mouse = 'a' +vim.opt.undodir = vim.fn.expand('~/.cache/vim/undo') +vim.opt.listchars = 'tab:▸ ,extends:❯,precedes:❮' + +vim.opt.relativenumber = true +vim.opt.list = true + +vim.opt.autoindent = true +vim.opt.expandtab = true +vim.opt.softtabstop = 4 +vim.opt.shiftwidth = 4 +vim.opt.tabstop = 4 +vim.opt.smartindent = true +vim.opt.modeline = true + +vim.opt.undofile = true +vim.g.mapleader = ' ' + +-- Load utilities +require('kalle.utils') + +-- Load plugins +require('kalle.plugins') + +vim.cmd('colorscheme nightfox') + +-- Load config +require('kalle.config') + +-- TODO: +-- - Terminal panel at the bottem that can be hidden / shown with a hotkey (ts [Leader Toggle Shell]?) [https://github.com/akinsho/toggleterm.nvim] +-- - Spell checker +-- - Debugger integration (gdb?, java?/kotlin?, rust?, etc) +-- - https://github.com/SmiteshP/nvim-navic +-- - https://github.com/simrat39/symbols-outline.nvim +-- - More...? diff --git a/nvim/lua/kalle/config/init.lua b/nvim/lua/kalle/config/init.lua new file mode 100644 index 0000000..19f848c --- /dev/null +++ b/nvim/lua/kalle/config/init.lua @@ -0,0 +1,2 @@ +require('kalle.config.keybinds') +require('kalle.config.plugin-config') diff --git a/nvim/lua/kalle/config/keybinds.lua b/nvim/lua/kalle/config/keybinds.lua new file mode 100644 index 0000000..b38934b --- /dev/null +++ b/nvim/lua/kalle/config/keybinds.lua @@ -0,0 +1,42 @@ +Keybind.g({ + -- [ space + h ] move cursor to left window + { 'n', 'h', 'wincmd h', { noremap = true, desc = 'Window left' } }, + -- [ space + l ] move cursor to bottom window + { 'n', 'j', 'wincmd j', { noremap = true, desc = 'Window down' } }, + -- [ space + j ] move cursor to top window + { 'n', 'k', 'wincmd k', { noremap = true, desc = 'Window up' } }, + -- [ space + k ] move cursor to right window + { 'n', 'l', 'wincmd l', { noremap = true, desc = 'Window right' } }, + -- [ space + 1 ] tab 1 + { 'n', '1', 'BufferLineGoToBuffer 1', {noremap = true, desc = 'Tab 1' } }, + -- [ space + 2 ] tab 2 + { 'n', '2', 'BufferLineGoToBuffer 2', {noremap = true, desc = 'Tab 2' } }, + -- [ space + 3 ] tab 3 + { 'n', '3', 'BufferLineGoToBuffer 3', {noremap = true, desc = 'Tab 3' } }, + -- [ space + 4 ] tab 4 + { 'n', '4', 'BufferLineGoToBuffer 4', {noremap = true, desc = 'Tab 4' } }, + -- [ space + 5 ] tab 5 + { 'n', '5', 'BufferLineGoToBuffer 5', {noremap = true, desc = 'Tab 5' } }, + -- [ space + 6 ] tab 6 + { 'n', '6', 'BufferLineGoToBuffer 6', {noremap = true, desc = 'Tab 6' } }, + -- [ space + 7 ] tab 7 + { 'n', '7', 'BufferLineGoToBuffer 7', {noremap = true, desc = 'Tab 7' } }, + -- [ space + 8 ] tab 8 + { 'n', '8', 'BufferLineGoToBuffer 8', {noremap = true, desc = 'Tab 8' } }, + -- [ space + 9 ] tab 9 + { 'n', '9', 'BufferLineGoToBuffer 9', {noremap = true, desc = 'Tab 9' } }, + + -- [ space + t ] Toggles + { 'n', 't', '', { noremap = true, desc = '+Toggle' } }, + -- [ space + t + t] Toggle file tree + { 'n', 'tt', 'NvimTreeToggle', { noremap = true, desc = 'Open file tree' } }, + -- [ space + t + g] Neogit + { 'n', 'tg', 'Neogit', { noremap = true, desc = 'Open git status' } }, + + -- [ space + o] Open + { 'n', 'o', '', { noremap = true, desc = '+Open' } }, + -- [ space + o + f] Open file + { 'n', 'of', 'Telescope git_files', { noremap = true, desc = 'Open file' } }, + + +}) diff --git a/nvim/lua/kalle/config/plugin-config.lua b/nvim/lua/kalle/config/plugin-config.lua new file mode 100644 index 0000000..c1ed09a --- /dev/null +++ b/nvim/lua/kalle/config/plugin-config.lua @@ -0,0 +1,182 @@ +require('which-key').setup {} + +require('nvim-tree').setup { + sort_by = 'case_sensitive', + view = { + adaptive_size = true, + mappings = { + custom_only = false, + list = {}, + }, + }, + renderer = { + group_empty = true, + highlight_git = true, + highlight_opened_files = "name", + indent_markers = { + enable = true, + }, + }, + filters = { + dotfiles = true, + }, +} + +require('neogit').setup {} + +require('lualine').setup {} + +require('bufferline').setup { + options = { + mode = 'buffers', + numbers = 'ordinal', + separator_style = 'slant', + show_buffer_icons = true, + show_buffer_close_icons = false, + show_close_icon = false, + always_show_bufferline = true, + right_mouse_command = function(bufnum) end, + middle_mouse_command = function(bufnum) + require('bufdelete').bufdelete(bufnum) + end, + custom_areas = { + right = function() + local result = {} + local seve = vim.diagnostic.severity + local error = #vim.diagnostic.get(0, {severity = seve.ERROR}) + local warning = #vim.diagnostic.get(0, {severity = seve.WARN}) + local info = #vim.diagnostic.get(0, {severity = seve.INFO}) + local hint = #vim.diagnostic.get(0, {severity = seve.HINT}) + + if error ~= 0 then + table.insert(result, {text = "  " .. error, fg = "#EC5241"}) + end + + if warning ~= 0 then + table.insert(result, {text = "  " .. warning, fg = "#EFB839"}) + end + + if hint ~= 0 then + table.insert(result, {text = "  " .. hint, fg = "#A3BA5E"}) + end + + if info ~= 0 then + table.insert(result, {text = "  " .. info, fg = "#7EA9A7"}) + end + return result + end, + }, + offsets = { + { + filetype = "NvimTree", + text = function() + return vim.fn.getcwd() + end, + highlight = "Directory", + text_align = "left" + } + } + } +} + +local cmp = require'cmp' + +cmp.setup({ + snippet = { + expand = function(args) + require('luasnip').lsp_expand(args.body) -- For `luasnip` users. + end, + }, + 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 }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. + }), + sources = cmp.config.sources({ + { name = 'nvim_lsp' }, + }, { + { name = 'buffer' }, + }) +}) + +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 `/` (if you enabled `native_menu`, this won't work anymore). +cmp.setup.cmdline('/', { + mapping = cmp.mapping.preset.cmdline(), + sources = { + { 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' } + }) +}) + +-- The nvim-cmp almost supports LSP's capabilities so You should advertise it to LSP servers.. +local capabilities = vim.lsp.protocol.make_client_capabilities() +capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities) + +require("mason").setup() +require("mason-lspconfig").setup() +require("mason-lspconfig").setup_handlers({ + function (server_name) -- default handler (optional) + if server_name == 'sumneko_lua' then + require("lspconfig")[server_name].setup { + capabilities = capabilities, + settings = { + Lua = { + diagnostics = { + globals = {'vim'} + }, + runtime = { + version = "LuaJIT", + path = vim.split(package.path, ";") + }, + workspace = { + library = { + [vim.fn.expand("$VIMRUNTIME/lua")] = true, + [vim.fn.expand("$VIMRUNTIME/lua/vim/lsp")] = true + } + } + } + }, + } + else + require("lspconfig")[server_name].setup { + capabilities = capabilities, + } + end + end, +}) + +require('gitsigns').setup { + current_line_blame = true, +} + +require('marks').setup {} + +require('nvim-treesitter.configs').setup { + auto_install = true, + highlight = { + enable = true, + additional_vim_regex_highlighting = false, + }, + indent = { + enable = true + }, +} diff --git a/nvim/lua/kalle/plugins.lua b/nvim/lua/kalle/plugins.lua new file mode 100644 index 0000000..aabc018 --- /dev/null +++ b/nvim/lua/kalle/plugins.lua @@ -0,0 +1,88 @@ +vim.cmd([[ + augroup packer_user_config + autocmd! + autocmd BufWritePost plugins.lua source | PackerCompile + augroup end +]]) + +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}) + vim.cmd [[packadd packer.nvim]] +end + +return require('packer').startup({function(use) + use('wbthomason/packer.nvim') + use('EdenEast/nightfox.nvim') + use('folke/which-key.nvim') + + use { + 'nvim-treesitter/nvim-treesitter', + run = function() require('nvim-treesitter.install').update({ with_sync = true }) end, + } + + use { + 'kyazdani42/nvim-tree.lua', + requires = { + 'kyazdani42/nvim-web-devicons', + }, + } + + use { + "williamboman/mason.nvim", + "williamboman/mason-lspconfig.nvim", + } + + use('chentoast/marks.nvim') + + use('neovim/nvim-lspconfig') + + use('L3MON4D3/LuaSnip') + + use { + 'hrsh7th/cmp-nvim-lsp', + 'hrsh7th/cmp-buffer', + 'hrsh7th/cmp-path', + 'hrsh7th/cmp-cmdline', + 'hrsh7th/nvim-cmp', + } + + use 'famiu/bufdelete.nvim' + + use { + 'TimUntersberger/neogit', + 'lewis6991/gitsigns.nvim', + } + use('nvim-lua/plenary.nvim') + + use('nvim-lualine/lualine.nvim') + use { + 'akinsho/bufferline.nvim', tag = "v2.*", + requires = 'kyazdani42/nvim-web-devicons' + } + + use { + 'nvim-telescope/telescope.nvim', tag = '0.1.0', + requires = { + 'nvim-lua/plenary.nvim' + }, + } + + -- Automatically set up your configuration after cloning packer.nvim + -- Put this at the end after all plugins + if packer_bootstrap then + require('packer').sync() + end +end, + config = { + auto_reload_compiled = false, -- Automatically reload the compiled file after creating it. + display = { + open_fn = function() + return require('packer.util').float({ border = 'single' }) + end + } + } +}) +-- run bootstrap: nvim --headless -c 'autocmd User PackerComplete quitall' -c 'PackerSync' + diff --git a/nvim/lua/kalle/utils/init.lua b/nvim/lua/kalle/utils/init.lua new file mode 100644 index 0000000..4ca5ba2 --- /dev/null +++ b/nvim/lua/kalle/utils/init.lua @@ -0,0 +1,5 @@ +Keybind = require('kalle.utils.keybind') + +Vim = { + Keybind = Keybind, +} diff --git a/nvim/lua/kalle/utils/keybind.lua b/nvim/lua/kalle/utils/keybind.lua new file mode 100644 index 0000000..17f0b56 --- /dev/null +++ b/nvim/lua/kalle/utils/keybind.lua @@ -0,0 +1,37 @@ +local Keybind = {} + +Keybind.add_global_keybinds = function (keybinds) + for _, keybind in pairs(keybinds) do + if(keybind[4] == nil) then + keybind[4] = {} + end + + vim.api.nvim_set_keymap( + keybind[1], + keybind[2], + keybind[3], + keybind[4] + ) + end +end + +Keybind.add_buffer_keybinds = function (keybinds) + for _, keybind in pairs(keybinds) do + if(keybind[5] == nil) then + keybind[5] = {} + end + + vim.api.nvim_buf_set_keymap( + keybind[1], + keybind[2], + keybind[3], + keybind[4], + keybind[5] + ) + end +end + +Keybind.g = Keybind.add_global_keybinds +Keybind.b = Keybind.add_buffer_keybinds + +return Keybind diff --git a/nvim/colors/dracula.vim b/nvim/old/colors/dracula.vim similarity index 100% rename from nvim/colors/dracula.vim rename to nvim/old/colors/dracula.vim diff --git a/nvim/ftdetect/paret.vim b/nvim/old/ftdetect/paret.vim similarity index 100% rename from nvim/ftdetect/paret.vim rename to nvim/old/ftdetect/paret.vim diff --git a/nvim/init.vim b/nvim/old/init.vim similarity index 100% rename from nvim/init.vim rename to nvim/old/init.vim diff --git a/nvim/syntax/paret.vim b/nvim/old/syntax/paret.vim similarity index 100% rename from nvim/syntax/paret.vim rename to nvim/old/syntax/paret.vim diff --git a/nvim/plugin/packer_compiled.lua b/nvim/plugin/packer_compiled.lua new file mode 100644 index 0000000..584a40d --- /dev/null +++ b/nvim/plugin/packer_compiled.lua @@ -0,0 +1,197 @@ +-- Automatically generated packer.nvim plugin loader code + +if vim.api.nvim_call_function('has', {'nvim-0.5'}) ~= 1 then + vim.api.nvim_command('echohl WarningMsg | echom "Invalid Neovim version for packer.nvim! | echohl None"') + return +end + +vim.api.nvim_command('packadd packer.nvim') + +local no_errors, error_msg = pcall(function() + + local time + local profile_info + local should_profile = false + if should_profile then + local hrtime = vim.loop.hrtime + profile_info = {} + time = function(chunk, start) + if start then + profile_info[chunk] = hrtime() + else + profile_info[chunk] = (hrtime() - profile_info[chunk]) / 1e6 + end + end + else + time = function(chunk, start) end + end + +local function save_profiles(threshold) + local sorted_times = {} + for chunk_name, time_taken in pairs(profile_info) do + sorted_times[#sorted_times + 1] = {chunk_name, time_taken} + end + table.sort(sorted_times, function(a, b) return a[2] > b[2] end) + local results = {} + for i, elem in ipairs(sorted_times) do + if not threshold or threshold and elem[2] > threshold then + results[i] = elem[1] .. ' took ' .. elem[2] .. 'ms' + end + end + + _G._packer = _G._packer or {} + _G._packer.profile_output = results +end + +time([[Luarocks path setup]], true) +local package_path_str = "/home/kalle/.cache/nvim/packer_hererocks/2.1.0-beta3/share/lua/5.1/?.lua;/home/kalle/.cache/nvim/packer_hererocks/2.1.0-beta3/share/lua/5.1/?/init.lua;/home/kalle/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/luarocks/rocks-5.1/?.lua;/home/kalle/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/luarocks/rocks-5.1/?/init.lua" +local install_cpath_pattern = "/home/kalle/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/lua/5.1/?.so" +if not string.find(package.path, package_path_str, 1, true) then + package.path = package.path .. ';' .. package_path_str +end + +if not string.find(package.cpath, install_cpath_pattern, 1, true) then + package.cpath = package.cpath .. ';' .. install_cpath_pattern +end + +time([[Luarocks path setup]], false) +time([[try_loadstring definition]], true) +local function try_loadstring(s, component, name) + local success, result = pcall(loadstring(s), name, _G.packer_plugins[name]) + if not success then + vim.schedule(function() + vim.api.nvim_notify('packer.nvim: Error running ' .. component .. ' for ' .. name .. ': ' .. result, vim.log.levels.ERROR, {}) + end) + end + return result +end + +time([[try_loadstring definition]], false) +time([[Defining packer_plugins]], true) +_G.packer_plugins = { + LuaSnip = { + loaded = true, + path = "/home/kalle/.local/share/nvim/site/pack/packer/start/LuaSnip", + url = "https://github.com/L3MON4D3/LuaSnip" + }, + ["bufdelete.nvim"] = { + loaded = true, + path = "/home/kalle/.local/share/nvim/site/pack/packer/start/bufdelete.nvim", + url = "https://github.com/famiu/bufdelete.nvim" + }, + ["bufferline.nvim"] = { + loaded = true, + path = "/home/kalle/.local/share/nvim/site/pack/packer/start/bufferline.nvim", + url = "https://github.com/akinsho/bufferline.nvim" + }, + ["cmp-buffer"] = { + loaded = true, + path = "/home/kalle/.local/share/nvim/site/pack/packer/start/cmp-buffer", + url = "https://github.com/hrsh7th/cmp-buffer" + }, + ["cmp-cmdline"] = { + loaded = true, + path = "/home/kalle/.local/share/nvim/site/pack/packer/start/cmp-cmdline", + url = "https://github.com/hrsh7th/cmp-cmdline" + }, + ["cmp-nvim-lsp"] = { + loaded = true, + path = "/home/kalle/.local/share/nvim/site/pack/packer/start/cmp-nvim-lsp", + url = "https://github.com/hrsh7th/cmp-nvim-lsp" + }, + ["cmp-path"] = { + loaded = true, + path = "/home/kalle/.local/share/nvim/site/pack/packer/start/cmp-path", + url = "https://github.com/hrsh7th/cmp-path" + }, + ["gitsigns.nvim"] = { + loaded = true, + path = "/home/kalle/.local/share/nvim/site/pack/packer/start/gitsigns.nvim", + url = "https://github.com/lewis6991/gitsigns.nvim" + }, + ["lualine.nvim"] = { + loaded = true, + path = "/home/kalle/.local/share/nvim/site/pack/packer/start/lualine.nvim", + url = "https://github.com/nvim-lualine/lualine.nvim" + }, + ["marks.nvim"] = { + loaded = true, + path = "/home/kalle/.local/share/nvim/site/pack/packer/start/marks.nvim", + url = "https://github.com/chentoast/marks.nvim" + }, + ["mason-lspconfig.nvim"] = { + loaded = true, + path = "/home/kalle/.local/share/nvim/site/pack/packer/start/mason-lspconfig.nvim", + url = "https://github.com/williamboman/mason-lspconfig.nvim" + }, + ["mason.nvim"] = { + loaded = true, + path = "/home/kalle/.local/share/nvim/site/pack/packer/start/mason.nvim", + url = "https://github.com/williamboman/mason.nvim" + }, + neogit = { + loaded = true, + path = "/home/kalle/.local/share/nvim/site/pack/packer/start/neogit", + url = "https://github.com/TimUntersberger/neogit" + }, + ["nightfox.nvim"] = { + loaded = true, + path = "/home/kalle/.local/share/nvim/site/pack/packer/start/nightfox.nvim", + url = "https://github.com/EdenEast/nightfox.nvim" + }, + ["nvim-cmp"] = { + loaded = true, + path = "/home/kalle/.local/share/nvim/site/pack/packer/start/nvim-cmp", + url = "https://github.com/hrsh7th/nvim-cmp" + }, + ["nvim-lspconfig"] = { + loaded = true, + path = "/home/kalle/.local/share/nvim/site/pack/packer/start/nvim-lspconfig", + url = "https://github.com/neovim/nvim-lspconfig" + }, + ["nvim-tree.lua"] = { + loaded = true, + path = "/home/kalle/.local/share/nvim/site/pack/packer/start/nvim-tree.lua", + url = "https://github.com/kyazdani42/nvim-tree.lua" + }, + ["nvim-treesitter"] = { + loaded = true, + path = "/home/kalle/.local/share/nvim/site/pack/packer/start/nvim-treesitter", + url = "https://github.com/nvim-treesitter/nvim-treesitter" + }, + ["nvim-web-devicons"] = { + loaded = true, + path = "/home/kalle/.local/share/nvim/site/pack/packer/start/nvim-web-devicons", + url = "https://github.com/kyazdani42/nvim-web-devicons" + }, + ["packer.nvim"] = { + loaded = true, + path = "/home/kalle/.local/share/nvim/site/pack/packer/start/packer.nvim", + url = "https://github.com/wbthomason/packer.nvim" + }, + ["plenary.nvim"] = { + loaded = true, + path = "/home/kalle/.local/share/nvim/site/pack/packer/start/plenary.nvim", + url = "https://github.com/nvim-lua/plenary.nvim" + }, + ["telescope.nvim"] = { + loaded = true, + path = "/home/kalle/.local/share/nvim/site/pack/packer/start/telescope.nvim", + url = "https://github.com/nvim-telescope/telescope.nvim" + }, + ["which-key.nvim"] = { + loaded = true, + path = "/home/kalle/.local/share/nvim/site/pack/packer/start/which-key.nvim", + url = "https://github.com/folke/which-key.nvim" + } +} + +time([[Defining packer_plugins]], false) +if should_profile then save_profiles() end + +end) + +if not no_errors then + error_msg = error_msg:gsub('"', '\\"') + vim.api.nvim_command('echohl ErrorMsg | echom "Error in packer_compiled: '..error_msg..'" | echom "Please check your config for correctness" | echohl None') +end diff --git a/setup.sh b/setup.sh index 0716b34..7e9a3d2 100755 --- a/setup.sh +++ b/setup.sh @@ -13,10 +13,8 @@ else # Symlink the config. ln -s $DOTS_DIR/nvim $NVIM_DIR - # Install dein.vim - curl https://raw.githubusercontent.com/Shougo/dein.vim/master/bin/installer.sh > /tmp/dein_installer.sh - chmod +x /tmp/dein_installer.sh - /tmp/dein_installer.sh ~/.local/share/dein + # Bootstrap the plugins + nvim --headless -c 'autocmd User PackerComplete quitall' -c 'PackerSync' fi # i3-gaps