From: Georgios Atheridis Date: Sun, 5 Jun 2022 19:37:09 +0000 (+0300) Subject: added lualine and toggleterm; format on save, jinja html support X-Git-Url: https://git.atheridis.org/?a=commitdiff_plain;h=c0d5f730e373732d4e562335167c77facc153c69;p=configs%2Fneovim.git added lualine and toggleterm; format on save, jinja html support --- diff --git a/nvim/init.lua b/nvim/init.lua index d15f094..324d39e 100644 --- a/nvim/init.lua +++ b/nvim/init.lua @@ -11,6 +11,8 @@ require("nvim.gitsigns") require("nvim.comment") require("nvim.nvim-tree") require("nvim.bufferline") -require("nvim.null-ls") +require("nvim.lsp.null-ls") require("nvim.leap") require("nvim.colorizer") +require("nvim.lualine") +require("nvim.toggleterm") diff --git a/nvim/lua/nvim/bufferline.lua b/nvim/lua/nvim/bufferline.lua index b23f016..73e2934 100644 --- a/nvim/lua/nvim/bufferline.lua +++ b/nvim/lua/nvim/bufferline.lua @@ -24,4 +24,97 @@ bufferline.setup({ enforce_regular_tabs = true, always_show_bufferline = true, }, + highlights = { + fill = { + guifg = { attribute = "fg", highlight = "#ff0000" }, + guibg = { attribute = "bg", highlight = "TabLine" }, + }, + background = { + guifg = { attribute = "fg", highlight = "TabLine" }, + guibg = { attribute = "bg", highlight = "TabLine" }, + }, + + -- buffer_selected = { + -- guifg = {attribute='fg',highlight='#ff0000'}, + -- guibg = {attribute='bg',highlight='#0000ff'}, + -- gui = 'none' + -- }, + buffer_visible = { + guifg = { attribute = "fg", highlight = "TabLine" }, + guibg = { attribute = "bg", highlight = "TabLine" }, + }, + + close_button = { + guifg = { attribute = "fg", highlight = "TabLine" }, + guibg = { attribute = "bg", highlight = "TabLine" }, + }, + close_button_visible = { + guifg = { attribute = "fg", highlight = "TabLine" }, + guibg = { attribute = "bg", highlight = "TabLine" }, + }, + -- close_button_selected = { + -- guifg = {attribute='fg',highlight='TabLineSel'}, + -- guibg ={attribute='bg',highlight='TabLineSel'} + -- }, + + tab_selected = { + guifg = { attribute = "fg", highlight = "Normal" }, + guibg = { attribute = "bg", highlight = "Normal" }, + }, + tab = { + guifg = { attribute = "fg", highlight = "TabLine" }, + guibg = { attribute = "bg", highlight = "TabLine" }, + }, + tab_close = { + -- guifg = {attribute='fg',highlight='LspDiagnosticsDefaultError'}, + guifg = { attribute = "fg", highlight = "TabLineSel" }, + guibg = { attribute = "bg", highlight = "Normal" }, + }, + + duplicate_selected = { + guifg = { attribute = "fg", highlight = "TabLineSel" }, + guibg = { attribute = "bg", highlight = "TabLineSel" }, + gui = "italic", + }, + duplicate_visible = { + guifg = { attribute = "fg", highlight = "TabLine" }, + guibg = { attribute = "bg", highlight = "TabLine" }, + gui = "italic", + }, + duplicate = { + guifg = { attribute = "fg", highlight = "TabLine" }, + guibg = { attribute = "bg", highlight = "TabLine" }, + gui = "italic", + }, + + modified = { + guifg = { attribute = "fg", highlight = "TabLine" }, + guibg = { attribute = "bg", highlight = "TabLine" }, + }, + modified_selected = { + guifg = { attribute = "fg", highlight = "Normal" }, + guibg = { attribute = "bg", highlight = "Normal" }, + }, + modified_visible = { + guifg = { attribute = "fg", highlight = "TabLine" }, + guibg = { attribute = "bg", highlight = "TabLine" }, + }, + + separator = { + guifg = { attribute = "bg", highlight = "TabLine" }, + guibg = { attribute = "bg", highlight = "TabLine" }, + }, + separator_selected = { + guifg = { attribute = "bg", highlight = "Normal" }, + guibg = { attribute = "bg", highlight = "Normal" }, + }, + -- separator_visible = { + -- guifg = {attribute='bg',highlight='TabLine'}, + -- guibg = {attribute='bg',highlight='TabLine'} + -- }, + indicator_selected = { + guifg = { attribute = "fg", highlight = "LspDiagnosticsDefaultHint" }, + guibg = { attribute = "bg", highlight = "Normal" }, + }, + }, }) diff --git a/nvim/lua/nvim/lsp/null-ls.lua b/nvim/lua/nvim/lsp/null-ls.lua new file mode 100644 index 0000000..8695f6f --- /dev/null +++ b/nvim/lua/nvim/lsp/null-ls.lua @@ -0,0 +1,34 @@ +local null_ls_status_ok, null_ls = pcall(require, "null-ls") +if not null_ls_status_ok then + return +end + +local formatting = null_ls.builtins.formatting +local diagnostics = null_ls.builtins.diagnostics + +null_ls.setup({ + debug = false, + sources = { + formatting.black, + formatting.stylua, + diagnostics.flake8, + }, +}) + +local augroup = vim.api.nvim_create_augroup("LspFormatting", {}) +null_ls.setup({ + -- you can reuse a shared lspconfig on_attach callback here + 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() + -- on 0.8, you should use vim.lsp.buf.format({ bufnr = bufnr }) instead + vim.lsp.buf.formatting_sync() + end, + }) + end + end, +}) diff --git a/nvim/lua/nvim/lualine.lua b/nvim/lua/nvim/lualine.lua new file mode 100644 index 0000000..e9647e7 --- /dev/null +++ b/nvim/lua/nvim/lualine.lua @@ -0,0 +1,93 @@ +local status_ok, lualine = pcall(require, "lualine") +if not status_ok then + return +end + +local hide_in_width = function() + return vim.fn.winwidth(0) > 80 +end + +local diagnostics = { + "diagnostics", + sources = { "nvim_diagnostic" }, + sections = { "error", "warn" }, + symbols = { error = " ", warn = " " }, + colored = false, + update_in_insert = false, + always_visible = true, +} + +local diff = { + "diff", + colored = false, + symbols = { added = " ", modified = " ", removed = " " }, -- changes diff symbols + cond = hide_in_width, +} + +local mode = { + "mode", + fmt = function(str) + return "-- " .. str .. " --" + end, +} + +local filetype = { + "filetype", + icons_enabled = false, + icon = nil, +} + +local branch = { + "branch", + icons_enabled = true, + icon = "", +} + +local location = { + "location", + padding = 0, +} + +-- cool function for progress +local progress = function() + local current_line = vim.fn.line(".") + local total_lines = vim.fn.line("$") + local chars = { "__", "▁▁", "▂▂", "▃▃", "▄▄", "▅▅", "▆▆", "▇▇", "██" } + local line_ratio = current_line / total_lines + local index = math.ceil(line_ratio * #chars) + return chars[index] +end + +local spaces = function() + return "spaces: " .. vim.api.nvim_buf_get_option(0, "shiftwidth") +end + +lualine.setup({ + options = { + icons_enabled = true, + theme = "auto", + component_separators = { left = "", right = "" }, + section_separators = { left = "", right = "" }, + disabled_filetypes = { "dashboard", "NvimTree", "Outline" }, + always_divide_middle = true, + }, + sections = { + lualine_a = { branch, diagnostics }, + lualine_b = { mode }, + lualine_c = {}, + -- lualine_x = { "encoding", "fileformat", "filetype" }, + lualine_x = { diff, spaces, "encoding", filetype }, + lualine_y = { location }, + lualine_z = { progress }, + }, + inactive_sections = { + lualine_a = {}, + lualine_b = {}, + lualine_c = { "filename" }, + lualine_x = { "location" }, + lualine_y = {}, + lualine_z = {}, + }, + tabline = {}, + extensions = {}, +}) diff --git a/nvim/lua/nvim/null-ls.lua b/nvim/lua/nvim/null-ls.lua deleted file mode 100644 index 23639ca..0000000 --- a/nvim/lua/nvim/null-ls.lua +++ /dev/null @@ -1,16 +0,0 @@ -local null_ls_status_ok, null_ls = pcall(require, "null-ls") -if not null_ls_status_ok then - return -end - -local formatting = null_ls.builtins.formatting -local diagnostics = null_ls.builtins.diagnostics - -null_ls.setup({ - debug = false, - sources = { - formatting.black, - formatting.stylua, - diagnostics.flake8, - }, -}) diff --git a/nvim/lua/nvim/options.lua b/nvim/lua/nvim/options.lua index a6e3feb..42276bc 100644 --- a/nvim/lua/nvim/options.lua +++ b/nvim/lua/nvim/options.lua @@ -18,7 +18,7 @@ local options = { undofile = true, updatetime = 300, writebackup = false, - expandtab = false, + expandtab = true, shiftwidth = 4, tabstop = 4, number = true, @@ -37,3 +37,24 @@ vim.opt.shortmess:append("c") for k, v in pairs(options) do vim.opt[k] = v end + +vim.cmd([[ + augroup Markdown + autocmd! + autocmd FileType markdown set wrap + augroup END +]]) + +vim.cmd([[ + augroup Format + autocmd! + autocmd BufWritePre *.html :normal mZgg=G`Z:delmarks Z + augroup END +]]) + +vim.cmd([[ + augroup FormatOnSave + autocmd! + autocmd BufWritePre * :Format + augroup END +]]) diff --git a/nvim/lua/nvim/plugins.lua b/nvim/lua/nvim/plugins.lua index e6cb192..18585d2 100644 --- a/nvim/lua/nvim/plugins.lua +++ b/nvim/lua/nvim/plugins.lua @@ -122,12 +122,21 @@ return packer.startup(function(use) "kyazdani42/nvim-web-devicons", } }) + -- Lualine + use({ + "nvim-lualine/lualine.nvim", + requires = { "kyazdani42/nvim-web-devicons", opt = true }, + }) + -- For quick movement between a file use("ggandor/leap.nvim") -- Shows hex colours use("norcalli/nvim-colorizer.lua") + -- Toggle Terminal + use("akinsho/toggleterm.nvim") + -- NON LUA PLUGINS use("moll/vim-bbye") diff --git a/nvim/lua/nvim/toggleterm.lua b/nvim/lua/nvim/toggleterm.lua new file mode 100644 index 0000000..99cca0c --- /dev/null +++ b/nvim/lua/nvim/toggleterm.lua @@ -0,0 +1,39 @@ +local status_ok, toggleterm = pcall(require, "toggleterm") +if not status_ok then + return +end + +toggleterm.setup({ + size = 20, + open_mapping = [[]], + hide_numbers = true, + shade_filetypes = {}, + shade_terminals = true, + shading_factor = 2, + start_in_insert = true, + insert_mappings = true, + persist_size = true, + direction = "float", + close_on_exit = true, + shell = vim.o.shell, + float_opts = { + border = "curved", + winblend = 0, + highlights = { + border = "Normal", + background = "Normal", + }, + }, +}) + +function _G.set_terminal_keymaps() + local opts = { noremap = true } + vim.api.nvim_buf_set_keymap(0, "t", "", [[]], opts) + vim.api.nvim_buf_set_keymap(0, "t", "jk", [[]], opts) + vim.api.nvim_buf_set_keymap(0, "t", "", [[h]], opts) + vim.api.nvim_buf_set_keymap(0, "t", "", [[j]], opts) + vim.api.nvim_buf_set_keymap(0, "t", "", [[k]], opts) + vim.api.nvim_buf_set_keymap(0, "t", "", [[l]], opts) +end + +vim.cmd("autocmd! TermOpen term://* lua set_terminal_keymaps()")