diff --git a/.gitignore b/.gitignore index dea16b3..d547881 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1 @@ packer_compiled.lua -ftplugin/html.lua -ftplugin/json.lua -ftplugin/typescript.lua diff --git a/after/ftplugin/rust.lua b/after/ftplugin/rust.lua deleted file mode 100644 index 11cdba7..0000000 --- a/after/ftplugin/rust.lua +++ /dev/null @@ -1,7 +0,0 @@ ---local helpers = require("helpers") ---local nmap = helpers.nmap --- ---nmap("]d", ":RustLsp renderDiagnostic") -----nmap("q", ":RustLsp explainError") ---nmap("q", ":RustLsp renderDiagnostic") ---nmap("f", ":RustFmt") diff --git a/ftplugin/htmldjango.lua b/ftplugin/htmldjango.lua index 57e3c47..bcf38c1 100644 --- a/ftplugin/htmldjango.lua +++ b/ftplugin/htmldjango.lua @@ -1 +1,2 @@ -require("helpers").set_tab(4) +vim.bo.shiftwidth = 4 +vim.bo.tabstop = 4 diff --git a/ftplugin/javascript.lua b/ftplugin/javascript.lua index 57e3c47..bcf38c1 100644 --- a/ftplugin/javascript.lua +++ b/ftplugin/javascript.lua @@ -1 +1,2 @@ -require("helpers").set_tab(4) +vim.bo.shiftwidth = 4 +vim.bo.tabstop = 4 diff --git a/ftplugin/javascriptreact.lua b/ftplugin/javascriptreact.lua index 57e3c47..bcf38c1 100644 --- a/ftplugin/javascriptreact.lua +++ b/ftplugin/javascriptreact.lua @@ -1 +1,2 @@ -require("helpers").set_tab(4) +vim.bo.shiftwidth = 4 +vim.bo.tabstop = 4 diff --git a/ftplugin/query.lua b/ftplugin/query.lua index 319e2e5..d0bac89 100644 --- a/ftplugin/query.lua +++ b/ftplugin/query.lua @@ -1 +1,2 @@ -require("helpers").set_tab(2) +vim.bo.shiftwidth = 2 +vim.bo.tabstop = 2 diff --git a/ftplugin/svelte.lua b/ftplugin/svelte.lua deleted file mode 100644 index 57e3c47..0000000 --- a/ftplugin/svelte.lua +++ /dev/null @@ -1 +0,0 @@ -require("helpers").set_tab(4) diff --git a/ftplugin/text.lua b/ftplugin/text.lua index 20ab5ea..afdaefc 100644 --- a/ftplugin/text.lua +++ b/ftplugin/text.lua @@ -1,20 +1,18 @@ -local map = require("helpers").map - -local function silent_map(mode, lhs, rhs) - map(mode, lhs, rhs, { silent = true }) +local function map(mode, lhs, rhs) + vim.keymap.set(mode, lhs, rhs, { silent = true, noremap = true }) end -silent_map("n", "", "gk") -silent_map("n", "", "gj") -silent_map("n", "", "g") -silent_map("n", "", "g") +map("n", "", "gk") +map("n", "", "gj") +map("n", "", "g") +map("n", "", "g") -silent_map("v", "", "gk") -silent_map("v", "", "gj") -silent_map("v", "", "g") -silent_map("v", "", "g") +map("v", "", "gk") +map("v", "", "gj") +map("v", "", "g") +map("v", "", "g") -silent_map("i", "", "gk") -silent_map("i", "", "gj") -silent_map("i", "", "g") -silent_map("i", "", "g") +map("i", "", "gk") +map("i", "", "gj") +map("i", "", "g") +map("i", "", "g") diff --git a/ftplugin/typescriptreact.lua b/ftplugin/typescriptreact.lua index 57e3c47..bcf38c1 100644 --- a/ftplugin/typescriptreact.lua +++ b/ftplugin/typescriptreact.lua @@ -1 +1,2 @@ -require("helpers").set_tab(4) +vim.bo.shiftwidth = 4 +vim.bo.tabstop = 4 diff --git a/ftplugin/yaml.lua b/ftplugin/yaml.lua deleted file mode 100644 index 57e3c47..0000000 --- a/ftplugin/yaml.lua +++ /dev/null @@ -1 +0,0 @@ -require("helpers").set_tab(4) diff --git a/init.lua b/init.lua index 2cdd970..f457a67 100644 --- a/init.lua +++ b/init.lua @@ -1,7 +1,6 @@ require("base") if (not vim.g.vscode) and os.getenv("NO_PLUGINS") == nil then - require("specifics") require("plugins") - require("buffer_tools").init() + require("buffer_tools") end diff --git a/lua/base/init.lua b/lua/base/init.lua index 7010d64..ac105c6 100644 --- a/lua/base/init.lua +++ b/lua/base/init.lua @@ -6,24 +6,20 @@ local function map(mode, lhs, rhs, opts) if opts then default_opts = vim.tbl_extend("force", default_opts, opts) end - --vim.api.nvim_set_keymap(mode, lhs, rhs, default_opts) vim.keymap.set(mode, lhs, rhs, default_opts) end +local function silent_map(mode, lhs, rhs) + map(mode, lhs, rhs, { silent = true }) +end + local opt = vim.opt local g = vim.g g.mapleader = "," --- Move cursor relative to visual line breaks -local function silent_map(mode, lhs, rhs) - map(mode, lhs, rhs, { silent = true }) -end - silent_map("v", "", '"+y') silent_map("n", "", ":noh") --After searching, pressing escape stops the highlight ---silent_map("n", "", ":bnext") ---silent_map("n", "", ":bprevious") map("n", "w", [[:%s/\s\+$//e]]) map("n", "x", ":bp|bd #") @@ -58,13 +54,6 @@ map("i", "", "") -- Make visual yanks place the cursor back where started map("v", "y", "ygv") --- Terminal binds ---local term_command = "split | set norelativenumber | set nonumber | term" -local term_command = "split | term" -map("t", "", [[]]) -map("n", [[\]], ":" .. term_command .. "") -map("n", [[|]], ":v" .. term_command .. "") - -- line-break movement --silent_map("n", "", "gk") --silent_map("n", "", "gj") @@ -81,14 +70,6 @@ map("n", [[|]], ":v" .. term_command .. "") --silent_map("i", "", "g") --silent_map("i", "", "g") --- half page movement ---silent_map("n", "", "M") ---silent_map("n", "", "M") ---silent_map("v", "", "M") ---silent_map("v", "", "M") ---silent_map("i", "", "M") ---silent_map("i", "", "M") - -- half page movement, primeagen version silent_map("n", "", "zz") silent_map("n", "", "zz") @@ -97,9 +78,9 @@ silent_map("v", "", "zz") silent_map("i", "", "zz") silent_map("i", "", "zz") --- dynamic tab -silent_map("n", "", ":lua require('dynamic_tab').tab()") -silent_map("n", "", ":lua require('dynamic_tab').shift_tab()") +-- tab buffer movement +silent_map("n", "", ":bnext") +silent_map("n", "", ":bprevious") opt.autoindent = true opt.autoread = true diff --git a/lua/buffer_tools.lua b/lua/buffer_tools.lua index 3b2deef..8b9497e 100644 --- a/lua/buffer_tools.lua +++ b/lua/buffer_tools.lua @@ -1,44 +1,37 @@ -local M = {} - local function get_active_buffers() - local active_buffers = {} - for tabnr = 1, vim.fn.tabpagenr("$") do - for _, bufnr in ipairs(vim.fn.tabpagebuflist(tabnr)) do - active_buffers[bufnr] = true - end - end - return active_buffers + local active_buffers = {} + for tabnr = 1, vim.fn.tabpagenr("$") do + for _, bufnr in ipairs(vim.fn.tabpagebuflist(tabnr)) do + active_buffers[bufnr] = true + end + end + return active_buffers end local function get_all_buffers() - local all_buffers = {} - for bufnr = 1, vim.fn.bufnr("$") do - if vim.fn.buflisted(bufnr) == 1 then - all_buffers[bufnr] = true - end - end - return all_buffers + local all_buffers = {} + for bufnr = 1, vim.fn.bufnr("$") do + if vim.fn.buflisted(bufnr) == 1 then + all_buffers[bufnr] = true + end + end + return all_buffers end -function M.remove_unused_buffers() - local active_buffers = get_active_buffers() - local all_buffers = get_all_buffers() - local buffers_to_remove = {} +local function remove_unused_buffers() + local active_buffers = get_active_buffers() + local all_buffers = get_all_buffers() + local buffers_to_remove = {} - for bufnr, _ in pairs(all_buffers) do - if active_buffers[bufnr] == nil then - buffers_to_remove[bufnr] = true - end - end + for bufnr, _ in pairs(all_buffers) do + if active_buffers[bufnr] == nil then + buffers_to_remove[bufnr] = true + end + end - for bufnr, _ in pairs(buffers_to_remove) do - vim.cmd("bd " .. bufnr) - end + for bufnr, _ in pairs(buffers_to_remove) do + vim.cmd("bd " .. bufnr) + end end -function M.init() - local map = require("helpers").map - map("n", "b", ":lua require('buffer_tools').remove_unused_buffers()") -end - -return M +vim.keymap.set("n", "b", remove_unused_buffers, { noremap = true }) diff --git a/lua/dynamic_tab.lua b/lua/dynamic_tab.lua deleted file mode 100644 index cd0a650..0000000 --- a/lua/dynamic_tab.lua +++ /dev/null @@ -1,16 +0,0 @@ -local M = {} - --- Whether to switch between buffers or tabs -function M.tab_mode() - return vim.fn.tabpagenr("$") > 1 -end - -function M.tab() - vim.cmd(M.tab_mode() and "tabn" or "bnext") -end - -function M.shift_tab() - vim.cmd(M.tab_mode() and "tabp" or "bprevious") -end - -return M diff --git a/lua/fzf_funcs.lua b/lua/fzf_funcs.lua deleted file mode 100644 index 337b817..0000000 --- a/lua/fzf_funcs.lua +++ /dev/null @@ -1,8 +0,0 @@ -local M = {} - -function M.cwd() - local path = vim.fn.expand("%:p:h") - vim.cmd("Files " .. path) -end - -return M diff --git a/lua/harpoon_fzf/init.lua b/lua/harpoon_fzf/init.lua deleted file mode 100644 index 2de3c67..0000000 --- a/lua/harpoon_fzf/init.lua +++ /dev/null @@ -1,19 +0,0 @@ -local M = {} - --- Grabbed from harpoon code -function M.get_marked_files() - local Marked = require("harpoon.mark") - local contents = {} - - for idx = 1, Marked.get_length() do - local file = Marked.get_marked_file_name(idx) - if file == "" then - file = "(empty)" - end - contents[idx] = string.format("%s", file) - end - - return contents -end - -return M diff --git a/lua/helpers.lua b/lua/helpers.lua deleted file mode 100644 index 1e3971a..0000000 --- a/lua/helpers.lua +++ /dev/null @@ -1,82 +0,0 @@ -local M = {} - -function M.map(mode, lhs, rhs, opts) - local default_opts = { noremap = true } - if opts then - default_opts = vim.tbl_extend("force", default_opts, opts) - end - --vim.api.nvim_set_keymap(mode, lhs, rhs, default_opts) - vim.keymap.set(mode, lhs, rhs, default_opts) -end - -function M.nmap(...) - M.map("n", ...) -end - -function M.lsp_config_defaults() - return { - root_dir = require("lspconfig.util").root_pattern( - "pyproject.toml", - "package.json", - ".null-ls-root", - ".git" - ), - - on_attach = function(client, bufnr) - local function buf_set_keymap(...) - vim.api.nvim_buf_set_keymap(bufnr, ...) - end - - local function buf_set_option(...) - vim.api.nvim_buf_set_option(bufnr, ...) - end - - ---- Disables document formatting by lsp - --client.resolved_capabilities.document_formatting = false - --client.resolved_capabilities.document_range_formatting = false - - -- Enable completion triggered by - buf_set_option("omnifunc", "v:lua.vim.lsp.omnifunc") - - -- Mappings. - local opts = { noremap = true, silent = true } - - -- See `:help vim.lsp.*` for documentation on any of the below functions - buf_set_keymap("n", "", "lua vim.lsp.buf.signature_help()", opts) - buf_set_keymap("n", "D", "lua vim.lsp.buf.type_definition()", opts) - buf_set_keymap("n", "ca", "lua vim.lsp.buf.code_action()", opts) - buf_set_keymap("n", "e", "lua vim.diagnostic.open_float()", opts) - buf_set_keymap("n", "q", "lua vim.diagnostic.setloclist()", opts) - buf_set_keymap("n", "rn", "lua vim.lsp.buf.rename()", opts) - buf_set_keymap("n", "wa", "lua vim.lsp.buf.add_workspace_folder()", opts) - buf_set_keymap( - "n", - "wl", - "lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))", - opts - ) - buf_set_keymap("n", "wr", "lua vim.lsp.buf.remove_workspace_folder()", opts) - buf_set_keymap("n", "K", "lua vim.lsp.buf.hover()", opts) - buf_set_keymap("n", "[d", "lua vim.diagnostic.goto_prev({wrap = true})", opts) - buf_set_keymap("n", "]d", "lua vim.diagnostic.goto_next({wrap = true})", opts) - buf_set_keymap("n", "gD", "lua vim.lsp.buf.declaration()", opts) - buf_set_keymap("n", "gd", "lua vim.lsp.buf.definition()", opts) - buf_set_keymap("n", "gi", "lua vim.lsp.buf.implementation()", opts) - buf_set_keymap("n", "gr", "lua vim.lsp.buf.references()", opts) - - local version = vim.version() - if version.api_level == 9 then - buf_set_keymap("n", "f", "lua vim.lsp.buf.formatting()", opts) - else - buf_set_keymap("n", "f", "lua vim.lsp.buf.format({ async = true })", opts) - end - end, - } -end - -function M.set_tab(length) - vim.bo.shiftwidth = length - vim.bo.tabstop = length -end - -return M diff --git a/lua/plugins/config.lua b/lua/plugins/config.lua index a9785fd..1e6a491 100644 --- a/lua/plugins/config.lua +++ b/lua/plugins/config.lua @@ -1,11 +1,57 @@ -local helpers = require("helpers") -local map = helpers.map -local lsp_config_defaults = helpers.lsp_config_defaults +local function map(mode, lhs, rhs, opts) + local default_opts = { noremap = true } + if opts then + default_opts = vim.tbl_extend("force", default_opts, opts) + end + vim.keymap.set(mode, lhs, rhs, default_opts) +end + +local function silent_map(mode, lhs, rhs) + map(mode, lhs, rhs, { silent = true }) +end local function nmap(...) map("n", ...) end +local function lsp_config_defaults() + return { + root_dir = require("lspconfig.util").root_pattern("pyproject.toml", "package.json", ".null-ls-root", ".git"), + + on_attach = function(_, bufnr) + vim.api.nvim_set_option_value("omnifunc", "v:lua.vim.lsp.omnifunc", { buf = bufnr }) + + local opts = { noremap = true, silent = true, buffer = bufnr } + + nmap("", vim.lsp.buf.signature_help, opts) + nmap("D", vim.lsp.buf.type_definition, opts) + nmap("ca", vim.lsp.buf.code_action, opts) + nmap("e", vim.diagnostic.open_float, opts) + nmap("q", vim.diagnostic.setloclist, opts) + nmap("rn", vim.lsp.buf.rename, opts) + nmap("wa", vim.lsp.buf.add_workspace_folder, opts) + nmap("wl", function() + print(vim.inspect(vim.lsp.buf.list_workspace_folders())) + end, opts) + nmap("wr", vim.lsp.buf.remove_workspace_folder, opts) + nmap("K", vim.lsp.buf.hover, opts) + nmap("[d", function() + vim.diagnostic.goto_prev({ wrap = true }) + end, opts) + nmap("]d", function() + vim.diagnostic.goto_next({ wrap = true }) + end, opts) + nmap("gD", vim.lsp.buf.declaration, opts) + nmap("gd", vim.lsp.buf.definition, opts) + nmap("gi", vim.lsp.buf.implementation, opts) + nmap("gr", vim.lsp.buf.references, opts) + nmap("f", function() + vim.lsp.buf.format({ async = true }) + end, opts) + end, + } +end + local M = {} function M.hop() @@ -22,6 +68,11 @@ function M.hop() end function M.fzf() + local function cwd() + local path = vim.fn.expand("%:p:h") + vim.cmd("Files " .. path) + end + map("n", "o", ":Files") map("n", "O", ":Files ~/") map("n", "p", ":Buffers") @@ -34,11 +85,7 @@ function M.fzf() map("n", "gl", ":GFiles") map("n", "gs", ":GFiles?") map("n", "gc", ":Commits") - --map("n", "l", ":lua require('fzf_funcs').cwd()") - --map("n", "f", ":lua require('fzf_funcs').cwd()") - - local fzf = require("fzf_funcs") - map("n", "l", fzf.cwd) + map("n", "l", cwd) end function M.fzf_checkout() @@ -82,15 +129,11 @@ function M.auto_session() auto_session_suppress_dirs = { "~/", "~/Projects" }, auto_session_use_git_branch = true, }) + + vim.o.sessionoptions = "blank,buffers,curdir,folds,help,tabpages,winsize,winpos,terminal,localoptions" 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, - --}) require("ibl").setup() end @@ -100,6 +143,22 @@ function M.lualine() return vim.o.columns * num / 6 end + local function tab_mode() + return vim.fn.tabpagenr("$") > 1 + end + + local function tab() + vim.cmd(tab_mode() and "tabn" or "bnext") + end + + local function shift_tab() + vim.cmd(tab_mode() and "tabp" or "bprevious") + end + + -- dynamic tab + silent_map("n", "", tab) + silent_map("n", "", shift_tab) + -- config options local function buffer_window(type, cond) return { @@ -158,7 +217,7 @@ function M.lualine() { "tabs", cond = function() - return require("dynamic_tab").tab_mode() + return tab_mode() end, max_length = function() return columns(1) @@ -167,10 +226,10 @@ function M.lualine() }, lualine_b = { buffer_window("windows", function() - return require("dynamic_tab").tab_mode() + return tab_mode() end), buffer_window("buffers", function() - return not require("dynamic_tab").tab_mode() + return not tab_mode() end), }, lualine_c = {}, @@ -458,41 +517,7 @@ end function M.rustaceanvim() vim.g.rustaceanvim = { server = { - on_attach = function(client, bufnr) - local function buf_set_keymap(...) - vim.api.nvim_buf_set_keymap(bufnr, ...) - end - - local opts = { noremap = true, silent = true } - - buf_set_keymap("n", "", "lua vim.lsp.buf.signature_help()", opts) - buf_set_keymap("n", "D", "lua vim.lsp.buf.type_definition()", opts) - buf_set_keymap("n", "ca", "lua vim.lsp.buf.code_action()", opts) - buf_set_keymap("n", "e", "lua vim.diagnostic.open_float()", opts) - buf_set_keymap("n", "q", "lua vim.diagnostic.setloclist()", opts) - buf_set_keymap("n", "rn", "lua vim.lsp.buf.rename()", opts) - buf_set_keymap("n", "wa", "lua vim.lsp.buf.add_workspace_folder()", opts) - buf_set_keymap( - "n", - "wl", - "lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))", - opts - ) - buf_set_keymap("n", "wr", "lua vim.lsp.buf.remove_workspace_folder()", opts) - buf_set_keymap("n", "K", "lua vim.lsp.buf.hover()", opts) - buf_set_keymap("n", "[d", "lua vim.diagnostic.goto_prev({wrap = true})", opts) - buf_set_keymap("n", "]d", "lua vim.diagnostic.goto_next({wrap = true})", opts) - buf_set_keymap("n", "gD", "lua vim.lsp.buf.declaration()", opts) - buf_set_keymap("n", "gd", "lua vim.lsp.buf.definition()", opts) - buf_set_keymap("n", "gi", "lua vim.lsp.buf.implementation()", opts) - buf_set_keymap("n", "gr", "lua vim.lsp.buf.references()", opts) - - if vim.version().api_level == 9 then - buf_set_keymap("n", "f", "lua vim.lsp.buf.formatting()", opts) - else - buf_set_keymap("n", "f", "lua vim.lsp.buf.format({ async = true })", opts) - end - end, + on_attach = lsp_config_defaults().on_attach, }, } end diff --git a/lua/specifics.lua b/lua/specifics.lua deleted file mode 100644 index 33fdbf0..0000000 --- a/lua/specifics.lua +++ /dev/null @@ -1,3 +0,0 @@ -local g = vim.g - -g.python3_host_prog = "/usr/bin/python3"