local helpers = require("helpers") local map = helpers.map local lsp_config_defaults = helpers.lsp_config_defaults local M = {} function M.hop() require("hop").setup({ keys = "etovxqpdygfblzhckisuran" }) local hop_opts = "{ create_hl_autocmd = true }" local hopword = [[lua require'hop'.hint_words(]] .. hop_opts .. [[)]] local hopline = [[lua require'hop'.hint_lines_skip_whitespace(]] .. hop_opts .. [[)]] map("n", "W", hopline, { silent = true }) map("v", "W", hopline, { silent = true }) map("n", "w", hopword, { silent = true }) map("v", "w", hopword, { silent = true }) end function M.onedark() require("onedark").setup({ style = "darker", toggle_style_key = "", }) require("onedark").load() end function M.fzf() map("n", "o", ":Files") map("n", "O", ":Files ~/") map("n", "p", ":Buffers") map("n", "h", ":Helptags") map("n", "H", ":Helptags ") map("n", ";", ":History:") map("n", "c", ":Commands") map("n", "r", ":Rg ") map("n", "R", ":Rg") map("n", "s", ":Lines") map("n", "gf", ":GFiles") map("n", "gn", ":GFiles?") map("n", "gc", ":Commits") end function M.rnvimr() map("n", "f", [[:RnvimrToggle]]) end function M.nvim_fzf() require("fzf").default_options = { --fzf_cli_args = " --height 100% --preview='bat --color=always --style=header,grid --line-range :300 {}' ", fzf_cli_args = " --height 100% --preview='[[ -n \"$(command -v bat)\" ]] && bat --color=always --style=header,grid --line-range :300 {} || strings {+}' ", } end function M.harpoon() require("harpoon").setup({ global_settings = { save_on_toggle = false, save_on_change = true, enter_on_sendcmd = false, tmux_autoclose_windows = false, excluded_filetypes = { "harpoon" }, }, }) end function M.auto_session() require("auto-session").setup({ log_level = "info", auto_session_suppress_dirs = { "~/", "~/Projects" }, auto_session_use_git_branch = true, }) end function M.fzf_checkout() map("n", "gb", ":GBranches") end function M.indent_blankline() vim.opt.list = true require("indent_blankline").setup({ space_char_blankline = " ", show_current_context = true, show_current_context_start = true, }) end function M.lualine() require("lualine").setup({ options = { theme = "onedark", icons_enabled = true }, sections = { lualine_a = { "mode" }, lualine_b = { "FugitiveHead", }, lualine_c = { "filename" }, lualine_x = { "encoding", "fileformat", "filetype", [[string.format("%d Lines", vim.fn.line('$'))]], { "diagnostics", sources = { "nvim_diagnostic", "ale" }, }, }, lualine_y = { "progress", }, lualine_z = { "location" }, }, inactive_sections = { lualine_a = {}, lualine_b = {}, lualine_c = { "filename" }, lualine_x = { "location" }, lualine_y = {}, lualine_z = {}, }, tabline = { lualine_a = { { "buffers", show_filename_only = false, -- shows shortened relative path when false show_modified_status = true, -- shows indicator then bufder is modified max_length = function() return vim.o.columns * 5 / 6 end, -- maximum width of buffers component filetype_names = { TelescopePrompt = "Telescope", dashboard = "Dashboard", packer = "Packer", fzf = "FZF", alpha = "Alpha", ["lsp-installer"] = "LSP Installer", }, -- shows specific buffer name for that filetype ( { `filetype` = `buffer_name`, ... } ) buffers_color = { active = nil, -- color for active buffer inactive = nil, -- color for inactive buffer }, }, }, lualine_b = {}, lualine_c = {}, lualine_x = {}, lualine_y = {}, lualine_z = { { [[string.format("Tab %d/%d", vim.fn.tabpagenr(), vim.fn.tabpagenr('$'))]], cond = function() return vim.fn.tabpagenr("$") > 1 end, }, { [[harpoon_status()]], cond = function() return require("harpoon.mark").get_length() > 0 end, }, }, }, extensions = {}, }) end function M.nvim_treesitter() local ts_visual_disable = { "typescript", "tsx", "html", "javascript" } require("nvim-treesitter.configs").setup({ ensure_installed = "all", highlight = { enable = true, disable = ts_visual_disable, }, rainbow = { enable = true, disable = ts_visual_disable, extended_mode = true, -- Also highlight non-bracket delimiters like html tags, boolean or table: lang -> boolean max_file_lines = nil, -- Do not enable for files with more than n lines, int -- colors = {}, -- table of hex strings --termcolors = {}, }, }) local version = vim.version() if version.api_level ~= 9 then vim.opt.foldmethod = "expr" vim.opt.foldexpr = "nvim_treesitter#foldexpr()" end end function M.nvim_lspconfig() vim.diagnostic.config({ virtual_text = true, signs = true, update_in_insert = false, }) end function M.nvim_lsp_installer() local config = lsp_config_defaults() local on_attach_tsserver = function(client, bufnr) local ts_utils = require("nvim-lsp-ts-utils") ts_utils.setup({ eslint_bin = "eslint_d", eslint_enable_diagnostics = true, eslint_enable_code_actions = true, enable_import_on_completion = true, filter_out_diagnostics_by_severity = { "information", "hint", --"warning", --"error", }, }) ts_utils.setup_client(client) -- no default maps, so you may want to define some here local o = { silent = true } vim.api.nvim_buf_set_keymap(bufnr, "n", "gs", ":TSLspOrganize", o) vim.api.nvim_buf_set_keymap(bufnr, "n", "rN", ":TSLspRenameFile", o) vim.api.nvim_buf_set_keymap(bufnr, "n", "gI", ":TSLspImportAll", o) end require("nvim-lsp-installer").on_server_ready(function(server) --Enable (broadcasting) snippet capability for completion local capabilities = vim.lsp.protocol.make_client_capabilities() capabilities.textDocument.completion.completionItem.snippetSupport = true local disable_diag = { ["textDocument/publishDiagnostics"] = function() end, } local on_attach_generic = function(client, bufnr) -- Disables document formatting by lsp client.server_capabilities.document_formatting = false client.server_capabilities.document_range_formatting = false config.on_attach(client, bufnr) end local opts = { on_attach = on_attach_generic, capabilities = capabilities, flags = { debounce_text_changes = 150, }, settings = { format = { enable = true }, }, root_dir = config.root_dir, } if server.name == "tsserver" then opts.on_attach = function(...) on_attach_tsserver(...) on_attach_generic(...) end elseif server.name == "sumneko_lua" then opts.settings.Lua = { diagnostics = { globals = { "vim", "awesome", "client", }, }, } elseif server.name == "html" then opts.filetypes = { "html", "htmldjango" } elseif server.name == "tailwindcss" then opts.init_options = { userLanguages = { htmldjango = "html", }, } end server:setup(opts) vim.cmd([[do User LspAttachBuffers]]) end) local lsp_installer_servers = require("nvim-lsp-installer.servers") local auto_servers = { "sumneko_lua", "tsserver", "bashls", "vimls", "rust_analyzer", "html", "cssls", "jsonls", --"jedi_language_server", "pylsp", "svelte", "tailwindcss", "zls", } for _, s in ipairs(auto_servers) do local ok, server = lsp_installer_servers.get_server(s) if ok and not server:is_installed() then server:install() end end end function M.null_ls() local null_ls = require("null-ls") local config = lsp_config_defaults() -- ORDER IN TABLE DETERMINES EXECUTION ORDER local sources = { -- python null_ls.builtins.diagnostics.flake8, null_ls.builtins.diagnostics.mypy, null_ls.builtins.formatting.black, null_ls.builtins.formatting.isort, -- js null_ls.builtins.diagnostics.eslint, null_ls.builtins.code_actions.eslint, null_ls.builtins.formatting.prettier.with({ extra_filetypes = { "svelte" }, }), -- lua null_ls.builtins.formatting.stylua, -- bash null_ls.builtins.formatting.shfmt, null_ls.builtins.diagnostics.shellcheck, null_ls.builtins.code_actions.shellcheck, -- cpp null_ls.builtins.formatting.clang_format, } null_ls.setup({ sources = sources, on_attach = config.on_attach, root_dir = config.root_dir, }) end function M.nvim_autopairs() require("nvim-autopairs").setup({ check_ts = true }) end function M.nvim_cmp() vim.opt.completeopt = "menuone,noselect" local cmp_autopairs = require("nvim-autopairs.completion.cmp") local cmp = require("cmp") -- CMP NVIM ULTISNIP local cmp_ultisnips_mappings = require("cmp_nvim_ultisnips.mappings") local ultisnip = { expand = function(args) vim.fn["UltiSnips#Anon"](args.body) end, tab = cmp.mapping(function(fallback) cmp_ultisnips_mappings.compose({ "select_next_item" })(fallback) end, { "i", "s" }), shift_tab = cmp.mapping(function(fallback) cmp_ultisnips_mappings.compose({ "select_prev_item" })(fallback) end, { "i", "s" }), } cmp.setup({ snippet = { expand = ultisnip.expand, }, 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({ select = true, }), [""] = ultisnip.tab, [""] = ultisnip.shift_tab, }, sources = { { name = "nvim_lsp" }, { name = "ultisnips" }, }, }) cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done({ map_char = { tex = "" } })) end return M