aboutsummaryrefslogblamecommitdiff
path: root/.config/nvim/init.lua
blob: 640ce93db26a4419d54767c23ff2ef696368e6c3 (plain) (tree)
1
2
3
4
5
6
7
8
9


          


                                                                                           
   






























                                                                                                     
 
                     




                                                           




                                                                      




                                                                            





         



                                             
                  
















                                            
                            
                             




                                  
                                  



















                                                                            
                                             
                                                                   

                                     























                                                                            
                                  



                       
                             
                                  
















                                                       
               











                                                
                                                 

                                      

                                                                                                                    


                                             

                                                                                        














                                                                                         







                                                                                                
 










                                                                                                        





                    
                                






                                                                     
                   
          


  

                           









                                                                      


  

                                    








                                                  
                                   
                               
                                     
                              




                                           
          





                                          
                           




                                                                                     
                                           




                                                                                        
                                  


                                                                                         
                         
          
                                                    









                                                                           












                                 
                                  
 


























                                                                                                   
 




                                                       
 



                                                       
          
   





                     
                        
                                                                                    
   
                                             






                                
                                    
  
--
-- Plugins
--

-- Install lazy if not available
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", "https://github.com/folke/lazy.nvim.git", lazypath})
end
vim.opt.rtp:prepend(lazypath)

-- Set up plugins for lazy
-- (lazy gets loaded at the bottom of the file)
local plugins = {
	"https://github.com/romainl/vim-cool",
	"https://github.com/tpope/vim-commentary",
	"https://github.com/editorconfig/editorconfig-vim",
	"https://github.com/tpope/vim-fugitive",
	{"https://github.com/itchyny/lightline.vim",
		config = function() config_lightline() end,
		dependencies = {"https://github.com/itchyny/vim-gitbranch"},
	},
	{"https://github.com/thezeroalpha/vim-lf",
		config = function() config_lf() end,
		dependencies = {"https://github.com/moll/vim-bbye"},
	},
	{"https://github.com/L3MON4D3/LuaSnip",
		config = function() config_luasnip() end,
	},
	"https://github.com/tpope/vim-surround",
	"https://github.com/tpope/vim-repeat",
	"https://github.com/tpope/vim-speeddating",
	{"https://github.com/nvim-telescope/telescope.nvim",
		config = function() config_telescope() end,
		dependencies = {"https://github.com/nvim-lua/plenary.nvim"},
	},
	{"https://github.com/nvim-treesitter/nvim-treesitter",
		config = function() config_treesitter() end,
		build = function() require("nvim-treesitter.install").update({with_sync = true}) end,
	},
	"https://github.com/jdhao/whitespace.nvim",

	-- Neovim LSP
	{"https://github.com/neovim/nvim-lspconfig",
		config = function() config_lspconfig() end,
	},
	{"https://github.com/hrsh7th/nvim-cmp",
		config = function() config_cmp() end,
		dependencies = {
			"https://github.com/hrsh7th/cmp-buffer",
			"https://github.com/hrsh7th/cmp-cmdline",
			"https://github.com/hrsh7th/cmp-nvim-lsp",
			"https://github.com/saadparwaiz1/cmp_luasnip",
			"https://github.com/hrsh7th/cmp-path",
		},
	},
	{"https://github.com/jose-elias-alvarez/null-ls.nvim",
		config = function() config_null_ls() end,
		dependencies = {"https://github.com/nvim-lua/plenary.nvim"},
	},
}



--
-- Basics
--

vim.opt.clipboard = "unnamedplus"
vim.opt.completeopt = "menu,menuone,noselect"
vim.opt.guicursor = ""
vim.opt.ignorecase = true
vim.opt.inccommand = "nosplit"
vim.opt.mouse = ""
vim.opt.number = true
vim.opt.relativenumber = true
vim.opt.shiftwidth = 0
vim.opt.showmode = false
vim.opt.smartcase = true
vim.opt.tabstop = 4
vim.opt.undofile = true

-- Python paths, needed for virtualenvs
vim.g.python3_host_prog = "/usr/bin/python3"
vim.g.python_host_prog = "/usr/bin/python2"



--
-- Colour scheme
--

vim.g.colors_name = "vim"
vim.opt.background = "light"
vim.opt.termguicolors = false
local hi = vim.api.nvim_set_hl

-- General
hi(0, "ColorColumn",  {ctermbg=8})
hi(0, "CursorLineNr", {ctermfg=3})
hi(0, "LineNr",       {ctermfg=3})
hi(0, "NormalFloat",  {ctermbg=8})
hi(0, "Search",       {ctermfg=0, ctermbg=3})
hi(0, "Statement",    {ctermfg=3})
hi(0, "Visual",       {ctermfg=0, ctermbg=3})
-- Completion
hi(0, "Pmenu",        {ctermfg=5})
hi(0, "PmenuSel",     {ctermfg=6, ctermbg=8, cterm={bold=true}})
hi(0, "PmenuSbar",    {})
-- Diffs
hi(0, "DiffAdd",      {ctermfg=6, ctermbg=8, cterm={bold=true,italic=true}})
hi(0, "DiffChange",   {})
hi(0, "DiffDelete",   {ctermfg=5, ctermbg=8, cterm={bold=true,italic=true}})
hi(0, "DiffText",     {ctermfg=6, ctermbg=8, cterm={bold=true,italic=true}})
hi(0, "FoldColumn",   {ctermbg=8})
hi(0, "Folded",       {ctermbg=8})
hi(0, "SignColumn",   {ctermfg=7, ctermbg=0})
-- Spelling
hi(0, "SpellBad",     {ctermfg=0, ctermbg=1, cterm={underline=true}})
hi(0, "SpellCap",     {ctermfg=0, ctermbg=2, cterm={underline=true}})
hi(0, "SpellRare",    {ctermfg=0, ctermbg=3, cterm={underline=true}})
hi(0, "SpellLocal",   {ctermfg=0, ctermbg=5, cterm={underline=true}})
-- Window splits
hi(0, "StatusLine",   {ctermfg=5, ctermbg=8})
hi(0, "StatusLineNC", {ctermfg=8, ctermbg=5, cterm={reverse=true}})
hi(0, "WinSeparator", {ctermfg=5, ctermbg=8})
-- Telescope
hi(0, "TelescopeNormal", {ctermbg=0})
hi(0, "TelescopeBorder", {ctermbg=0})
-- Neovim LSP
hi(0, "DiagnosticError",          {ctermfg=0, ctermbg=1, cterm={bold=true}})
hi(0, "DiagnosticInfo",           {ctermfg=0, ctermbg=4, cterm={bold=true}})
hi(0, "DiagnosticWarn",           {ctermfg=0, ctermbg=3, cterm={bold=true}})
hi(0, "DiagnosticFloatingError",  {ctermfg=1, cterm={bold=true}})
hi(0, "DiagnosticFloatingInfo",   {ctermfg=4, cterm={bold=true}})
hi(0, "DiagnosticFloatingWarn",   {ctermfg=3, cterm={bold=true}})
hi(0, "DiagnosticUnderlineError", {cterm={underline=false}})
hi(0, "DiagnosticUnderlineHint",  {cterm={underline=false}})
hi(0, "DiagnosticUnderlineInfo",  {cterm={underline=false}})
hi(0, "DiagnosticUnderlineWarn",  {cterm={underline=false}})



--
-- Language-specific
--

vim.api.nvim_create_autocmd("Filetype", {
	pattern = {
		"css",
		"gitolite",
		"html",
		"htmldjango",
		"javascript",
		"javascriptreact",
		"json",
		"jst",
		"less",
		"php",
		"scss",
		"typescript",
		"typescriptreact",
		"yaml",
	},
	callback = function()
		vim.bo.expandtab = true
		vim.bo.tabstop = 2
	end
})
vim.api.nvim_create_autocmd("Filetype", {
	pattern = "markdown",
	callback = function() vim.bo.textwidth = 72 end
})

vim.g.html_indent_script1 = "inc"
vim.g.html_indent_style1 = "inc"



--
-- Key bindings
--

vim.g.mapleader = " "

-- Move between visual lines when text overflows
vim.keymap.set("n", "j", "gj")
vim.keymap.set("n", "k", "gk")

-- Indent without having to redo your selection
vim.keymap.set("x", "<", "<gv")
vim.keymap.set("x", ">", ">gv")

-- Tab management
vim.keymap.set("n", "<Leader>o", ":tabnew<CR>")
vim.keymap.set("n", "<Leader>c", ":tabclose<CR>")
vim.keymap.set("n", "<Leader>j", "gt")
vim.keymap.set("n", "<Leader>k", "gT")

-- Formatting
vim.keymap.set("n", "<Leader>f", function() vim.cmd("StripTrailingWhitespace") vim.lsp.buf.format({async=true}) end)
vim.keymap.set("n", "<Leader>F", ":StripTrailingWhitespace<CR>")

-- lf - file manager
vim.keymap.set("n", "<C-\\>", "<Plug>LfEdit")

-- Telescope - fuzzy finder
vim.keymap.set("n", "<C-p>", function() require("telescope.builtin").find_files({}) end)
vim.keymap.set("n", "<C-g>", function() require("telescope.builtin").live_grep({}) end)

-- Neovim LSP - completion and diagnostics
vim.keymap.set("n", "<C-k>", function() vim.diagnostic.open_float({focusable=false}) end)
vim.keymap.set("n", "<C-l>", function() vim.lsp.buf.hover() end)
vim.keymap.set("n", "gd",    function() vim.lsp.buf.definition() end)

-- Spell check
vim.keymap.set("n", "<F9>",  ":setlocal spell! spelllang=en_gb<CR>")
vim.keymap.set("n", "<F10>", ":setlocal spell! spelllang=pl<CR>")



--
-- Lightline - statusline
--

function config_lightline()
	vim.g.lightline = {
		colorscheme = "biual",
		active = {
			left  = {{"mode"}, {"readonly", "filename", "gitbranch"}, {"modified"}},
			right = {{"filetype", "fileencoding"}, {"percent"}}
		},
		component_function = {gitbranch = "gitbranch#name"},
	}

	local ll_theme = {base = {}, normal = {}, tabline = {}}
	ll_theme.base.norm = {{{"#ad7ac4", 5}, {"#15181e", 0}}}
	ll_theme.base.sel  = {{{"#ad7ac4", 5}, {"#343442", 8}}}
	ll_theme.normal.left    = ll_theme.base.sel
	ll_theme.normal.middle  = ll_theme.base.norm
	ll_theme.normal.right   = ll_theme.base.sel
	ll_theme.tabline.left   = ll_theme.base.norm
	ll_theme.tabline.middle = ll_theme.base.norm
	ll_theme.tabline.right  = ll_theme.base.norm
	ll_theme.tabline.tabsel = ll_theme.base.sel
	vim.g["lightline#colorscheme#biual#palette"] = vim.fn["lightline#colorscheme#flatten"](ll_theme)
end



--
-- lf - file manager
--

function config_lf()
	-- Replace netrw with lf
	vim.api.nvim_create_autocmd("BufEnter", {
		pattern = "*",
		callback = function()
			local buf_path = vim.fn.expand("%")
			if (vim.fn.isdirectory(buf_path) == 1) then
				vim.cmd("bdelete")
				vim.fn["lf#LF"](buf_path, "edit", {})
			end
		end
	})
end



--
-- Telescope - fuzzy finder
--

function config_telescope()
	require("telescope").setup({
	  defaults = {
		mappings = {
		  i = {
			["<esc>"] = require("telescope.actions").close
		  },
		},
	  }
	})
end



--
-- Tree-sitter - syntax highlighting
--

function config_treesitter()
	require("nvim-treesitter.configs").setup({
		ensure_installed = {
			"c",
			"cpp",
			"css",
			"go",
			"javascript",
			"latex",
			"lua",
			"markdown",
			"scss",
			"tsx",
			"typescript",
			"zig",
		},
		highlight = {
			enable = true,
			disable = {
				"markdown",
			}
		},
	})
end



--
-- Neovim LSP - completion and diagnostics
--

function config_lspconfig()
	require("lspconfig").gopls.setup({
		on_attach = function(client)
			client.server_capabilities.documentFormattingProvider = false
		end
	})
	require("lspconfig").gdscript.setup({})
	require("lspconfig").lua_ls.setup({
		settings = {
			Lua = {
				runtime = {version = "LuaJIT"},
				diagnostics = {
					globals = {"vim"},
					disable = {"lowercase-global", "need-check-nil"}
				},
				workspace = {
					checkThirdParty = false,
					library = vim.api.nvim_get_runtime_file("", true)
				}
			}
		}
	})
	require("lspconfig").pylsp.setup({})
	require("lspconfig").rust_analyzer.setup({})
	require("lspconfig").tsserver.setup({})
end

function config_null_ls()
	require("null-ls").setup({
		sources = {
			require("null-ls").builtins.diagnostics.shellcheck,
			require("null-ls").builtins.formatting.goimports,
		},
	})
end

vim.diagnostic.config({
	signs = true,
	underline = true,
	update_in_insert = false,
	virtual_text = false,
})



--
-- nvim-cmp - autocompletion
--

function config_cmp()
	local cmp = require("cmp")

	cmp.setup({
		snippet = {
			expand = function(args)
				require("luasnip").lsp_expand(args.body)
			end,
		},
		preselect = cmp.PreselectMode.None,
		mapping = {
			["<Tab>"] = cmp.mapping(cmp.mapping.select_next_item()),
			["<S-Tab>"] = cmp.mapping(cmp.mapping.select_prev_item()),
			["<C-Space>"] = cmp.mapping(cmp.mapping.complete()),
			["<C-e>"] = cmp.mapping({
				i = cmp.mapping.abort(),
				c = cmp.mapping.close(),
			}),
			["<C-u>"] = cmp.mapping.scroll_docs(-6),
			["<C-d>"] = cmp.mapping.scroll_docs(6),
			["<C-a>"] = cmp.mapping(function()
				cmp.confirm({behavior = cmp.ConfirmBehavior.Insert, select = true})
			end),
		},
		sources = {
			{name = "luasnip"},
			{name = "nvim_lsp"},
			{name = "buffer"},
			{name = "path"},
		}
	})

	cmp.setup.cmdline("/", {
		mapping = cmp.mapping.preset.cmdline(),
		sources = {
			{name = "buffer"},
		}
	})

	cmp.setup.cmdline(":", {
		mapping = cmp.mapping.preset.cmdline(),
		sources = cmp.config.sources({
			{name = "cmdline"}
		})
	})
end



--
-- LuaSnip - snippets
--

function load_snippets()
	require("luasnip.loaders.from_snipmate").lazy_load({paths = {"./snippets"}})
end
function config_luasnip() load_snippets() end



--
-- lazy - plugin manager
--

require("lazy").setup(plugins, {
  install = {colorscheme = {"vim"}},
})