diff --git a/after/plugin/codex_unmap.lua b/after/plugin/codex_unmap.lua new file mode 100644 index 0000000..4357032 --- /dev/null +++ b/after/plugin/codex_unmap.lua @@ -0,0 +1 @@ +vim.api.nvim_del_keymap("n", "co") diff --git a/ftplugin/html.lua b/ftplugin/html.lua index 512c9b5..d0bac89 100644 --- a/ftplugin/html.lua +++ b/ftplugin/html.lua @@ -1,2 +1,2 @@ -vim.opt.shiftwidth = 2 -vim.opt.tabstop = 2 +vim.bo.shiftwidth = 2 +vim.bo.tabstop = 2 diff --git a/ftplugin/text.lua b/ftplugin/text.lua new file mode 100644 index 0000000..bc4afdd --- /dev/null +++ b/ftplugin/text.lua @@ -0,0 +1,21 @@ +local function local_map(mode, lhs, rhs, opts) + local options = {noremap = true} + if opts then + options = vim.tbl_extend("force", options, opts) + end + vim.api.nvim_buf_set_keymap(0, mode, lhs, rhs, options) +end + +local function silent_map(mode, lhs, rhs) + local_map(mode, lhs, rhs, {silent = true}) +end + +silent_map("n", "", "gk") +silent_map("n", "", "gj") +silent_map("n", "", "g") +silent_map("n", "", "g") + +silent_map("i", "", "gk") +silent_map("i", "", "gj") +silent_map("i", "", "g") +silent_map("i", "", "g") diff --git a/ftplugin/yaml.lua b/ftplugin/yaml.lua index 09db0f8..bcf38c1 100644 --- a/ftplugin/yaml.lua +++ b/ftplugin/yaml.lua @@ -1,2 +1,2 @@ -vim.opt.shiftwidth = 4 -vim.opt.tabstop = 4 +vim.bo.shiftwidth = 4 +vim.bo.tabstop = 4 diff --git a/lua/config.lua b/lua/config.lua index e68c178..37ce125 100644 --- a/lua/config.lua +++ b/lua/config.lua @@ -46,11 +46,24 @@ opt.titlestring = [[NVIM: [%{fnamemodify(getcwd(), ':t')}] %t]] opt.cursorline = true opt.cursorcolumn = true +-- disable highlight outside of search and replace +vim.cmd [[ +" Enable highlighting all the matches in incsearch mode +" But don't enable hlsearch always +augroup vimrc-incsearch-highlight + autocmd! + autocmd CmdlineEnter [/\?:] :set hlsearch + autocmd CmdlineLeave [/\?:] :set nohlsearch +augroup END +]] + ------------------ -- ONEDARK.NVIM -- ------------------ -g.onedark_toggle_style_keymap = "" --g.onedark_style = "cool" +g.onedark_style = "darker" +g.onedark_toggle_style_keymap = "" +--g.onedark_darker_diagnostics = false ---------------- -- BCLOSE.VIM -- @@ -94,7 +107,7 @@ require("lualine").setup { sections = { lualine_a = {"mode"}, lualine_b = { - "branch" + "FugitiveHead" }, lualine_c = {"filename"}, lualine_x = { @@ -104,7 +117,7 @@ require("lualine").setup { [[string.format("%d Lines", vim.fn.line('$'))]], { "diagnostics", - sources = {"nvim_lsp", "ale"} + sources = {"nvim_diagnostic", "ale"} } }, lualine_y = { @@ -180,3 +193,46 @@ require("harpoon").setup( } } ) + +-------------- +-- NVIM FZF -- +-------------- +require("fzf").default_options = { + fzf_cli_args = " --height 100% --preview='bat --color=always --style=header,grid --line-range :300 {}' " +} + +---------------------- +-- INDENT-BLANKLINE -- +---------------------- +--vim.opt.termguicolors = true +--vim.cmd [[highlight IndentBlanklineIndent1 guibg=#1f1f1f gui=nocombine]] +--vim.cmd [[highlight IndentBlanklineIndent2 guibg=#1a1a1a gui=nocombine]] +-- +--require("indent_blankline").setup { +-- char = "", +-- char_highlight_list = { +-- "IndentBlanklineIndent1", +-- "IndentBlanklineIndent2" +-- }, +-- space_char_highlight_list = { +-- "IndentBlanklineIndent1", +-- "IndentBlanklineIndent2" +-- }, +-- show_trailing_blankline_indent = false +--} + +--vim.opt.list = true +--vim.opt.listchars:append("eol:↴") +-- +--require("indent_blankline").setup { +-- show_end_of_line = true +--} +--vim.opt.listchars:append("eol:↴") +vim.opt.list = true +vim.opt.listchars:append("space:⋅") + +require("indent_blankline").setup { + space_char_blankline = " ", + show_current_context = true, + show_current_context_start = true +} diff --git a/lua/functions.lua b/lua/functions.lua index ad34a61..ab8e49a 100644 --- a/lua/functions.lua +++ b/lua/functions.lua @@ -6,10 +6,44 @@ local function harpoon_tab_switch() return require("harpoon.mark").get_length() > 1 end +local bug = + [[ + +Weird bug: + +When at home directory, `Marked.get_current_index()` returns `nil` on files. +Caused by differences in the outputs of `Marked.get_marked_file_name()` +and `require("harpoon.utils").normalize_path()`. + +Example: + marked: + ./code/py/old/test.py + + utils: + code/py/old/test.py + +]] + +local harpoon_cycle_marked_file = function(up) + local step = up and 1 or -1 + + local Marked = require("harpoon.mark") + local current_index = Marked.get_current_index() + local number_of_items = Marked.get_length() + + current_index = current_index + step + current_index = current_index % number_of_items + + require("harpoon.ui").nav_file(current_index) +end + -- Dynamically switches between bnext and harpoon.ui.nav_next function _G.harpoon_bnext() if harpoon_tab_switch() then - require("harpoon.ui").nav_next() + --require("harpoon.ui").nav_next() + -- for some reason, next and prev have opposite directions + require("harpoon.ui").nav_prev() + --harpoon_cycle_marked_file(true) print("Harpoon nav_next") else vim.api.nvim_command("bnext") @@ -20,7 +54,10 @@ end -- Dynamically switches between bprevious and harpoon.ui.nav_prev function _G.harpoon_bprevious() if harpoon_tab_switch() then - require("harpoon.ui").nav_prev() + --require("harpoon.ui").nav_prev() + -- for some reason, next and prev have opposite directions + require("harpoon.ui").nav_next() + --harpoon_cycle_marked_file(false) print("Harpoon nav_prev") else vim.api.nvim_command("bprevious") @@ -44,7 +81,7 @@ end -- I want my bclose bindings to also remove harpoon marks function _G.harpoon_rm_file() require("harpoon.mark").rm_file() - vim.api.nvim_command("bd") + vim.api.nvim_command("bw") end -- Lualine status element for harpoon @@ -58,3 +95,98 @@ function _G.harpoon_status() return string.format(status_str, marked_files) end --[[string.format("Harpoon: %d files", require("harpoon.mark").get_length())]] +local get_harpoon_marked = function() + 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 + +local fzf_opts = function() + return { + width = math.floor(vim.o.columns * 0.9), + height = math.floor(vim.o.lines * 0.6) + } +end + +local sleep = function(n) + local t0 = os.clock() + while os.clock() - t0 <= n do + end +end + +-- Marks buffers for harpoon +function _G.fzf_buffer_add_to_harpoon() + -- Returns list of buffer file paths. + -- Does not include buffers without a file path. + local get_buffer_paths = function() + local buffers = {} + for b = 1, vim.fn.bufnr "$" do + if vim.fn.buflisted(b) ~= 0 and vim.api.nvim_buf_get_option(b, "buftype") == "" then + local buf_path = vim.fn.expand("#" .. b) + if buf_path ~= "" then + buffers[#buffers + 1] = buf_path + end + end + end + + return buffers + end + + local add_to_harpoon = function() + local fzf = require("fzf").fzf + local action = require "fzf.actions".action + + local buf_paths = get_buffer_paths() + + -- items is a table of selected or hovered fzf items + local shell = + action( + function(items, fzf_lines, fzf_cols) + -- get last item + local buf = vim.fn.bufnr(items[#items]) + + -- you can return either a string or a table to show in the preview + -- window + return vim.api.nvim_buf_get_lines(buf, 0, fzf_lines, false) + end + ) + + --''\''nvim'\'' --headless --clean --cmd '\''luafile /home/guy/.local/share/nvim/site/pack/packer/start/nvim-fzf/action_helper.lua'\'' '\''/tmp/nvimDUg2xo/3'\'' 7 {+}' + -- + local results = fzf(buf_paths, " --multi ", fzf_opts()) + if results then + local Marked = require("harpoon.mark") + Marked.set_mark_list(results) + --for _, p in ipairs(results) do + -- Marked.toggle_file(p) + -- --sleep(0.5) + --end + end + end + + --coroutine.wrap(add_to_harpoon)() + require("fzf-commands").files({fzf = add_to_harpoon}) +end + +--local testing = function () +-- coroutine.wrap(function () +-- local fzf = require("fzf").fzf +-- fzf({}, '', { }) +-- end)() +--end + +-- width: 139 +-- margin width: 14 +-- 90% width +-- height: 35 +-- margin height: 14 +-- 60% height diff --git a/lua/keybinds.lua b/lua/keybinds.lua index 3e8dd9f..2127dae 100644 --- a/lua/keybinds.lua +++ b/lua/keybinds.lua @@ -1,3 +1,6 @@ +-- these are my custom functions +require("functions") + --local fn = vim.fn -- to call Vim functions e.g. fn.bufnr() local function map(mode, lhs, rhs, opts) local options = {noremap = true} @@ -9,8 +12,6 @@ end vim.g.mapleader = "," -require("functions") - map("v", "", '"+y') --map("n", "", ":bnext") --map("n", "", ":bprevious") @@ -18,9 +19,15 @@ map("n", "", ":lua harpoon_bnext()") map("n", "", ":lua harpoon_bprevious()") map("n", "", ":noh", {silent = true}) --After searching, pressing escape stops the highlight -map("n", "w", [[:%s/\s\+$//e ]]) +map("n", "w", [[:%s/\s\+$//e]]) --map("n", "x", ":Bclose ") -map("n", "t", ":tabnew ") +map("n", "t", ":tabnew") + +-- Move split +map("n", "", "") +map("n", "", "") +map("n", "", "") +map("n", "", "") -- Split navigations map("n", "", "") @@ -29,10 +36,10 @@ map("n", "", "") map("n", "", "") -- Resize split -map("n", "", "-") -map("n", "", "+") -map("n", "", "<") -map("n", "", ">") +--map("n", "", "-") +--map("n", "", "+") +--map("n", "", "<") +--map("n", "", ">") -- Scroll viewport map("n", "", "") @@ -41,6 +48,12 @@ map("v", "", "") map("v", "", "") map("i", "", "") map("i", "", "") +--map("n", "", "") +--map("n", "", "") +--map("v", "", "") +--map("v", "", "") +--map("i", "", "") +--map("i", "", "") -- Make visual yanks place the cursor back where started map("v", "y", "ygv") @@ -52,30 +65,96 @@ map("v", "y", "ygv") --------- -- HOP -- --------- -local hopword = [[lua require'hop'.hint_words()]] -local hopline = [[lua require'hop'.hint_lines_skip_whitespace()]] +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", "", hopline, {silent = true}) --map("v", "", hopline, {silent = true}) --map("n", "", hopword, {silent = true}) --map("v", "", hopword, {silent = true}) + map("n", "W", hopline, {silent = true}) map("v", "W", hopline, {silent = true}) map("n", "w", hopword, {silent = true}) map("v", "w", hopword, {silent = true}) +-- args: direction: bool, inclusive: bool +-- inclusive is broken in hop as of this comment +local hop_hint_char1 = function(args) + local direction = args.forward and "AFTER_CURSOR" or "BEFORE_CURSOR" + local inclusive = args.inclusive and "true" or "false" + + return ("lua require'hop'.hint_char1({ direction = require'hop.hint'.HintDirection." .. + direction .. ", current_line_only = true, inclusive_jump = " .. inclusive .. " })") +end + +vim.api.nvim_set_keymap("", "f", hop_hint_char1({forward = true, inclusive = false}), {}) +vim.api.nvim_set_keymap("", "F", hop_hint_char1({forward = false, inclusive = false}), {}) +vim.api.nvim_set_keymap("", "t", hop_hint_char1({forward = true, inclusive = false}), {}) +vim.api.nvim_set_keymap("", "T", hop_hint_char1({forward = false, inclusive = false}), {}) + +-- place this in one of your configuration file(s) +--vim.api.nvim_set_keymap( +-- "n", +-- "f", +-- "lua require'hop'.hint_char1({ direction = require'hop.hint'.HintDirection.AFTER_CURSOR, current_line_only = true })", +-- {} +--) +--vim.api.nvim_set_keymap( +-- "n", +-- "F", +-- "lua require'hop'.hint_char1({ direction = require'hop.hint'.HintDirection.BEFORE_CURSOR, current_line_only = true })", +-- {} +--) +--vim.api.nvim_set_keymap( +-- "", +-- "f", +-- "lua require'hop'.hint_char1({ direction = require'hop.hint'.HintDirection.AFTER_CURSOR, current_line_only = true, inclusive_jump = true })", +-- {} +--) +--vim.api.nvim_set_keymap( +-- "", +-- "F", +-- "lua require'hop'.hint_char1({ direction = require'hop.hint'.HintDirection.BEFORE_CURSOR, current_line_only = true, inclusive_jump = true })", +-- {} +--) +--vim.api.nvim_set_keymap( +-- "", +-- "t", +-- "lua require'hop'.hint_char1({ direction = require'hop.hint'.HintDirection.AFTER_CURSOR, current_line_only = true })", +-- {} +--) +--vim.api.nvim_set_keymap( +-- "", +-- "T", +-- "lua require'hop'.hint_char1({ direction = require'hop.hint'.HintDirection.BEFORE_CURSOR, current_line_only = true })", +-- {} +--) + --------- -- FZF -- --------- -map("n", "o", ":Files ") -map("n", "O", [[:lua vim.fn['fzf#vim#files']('~/') ]]) -map("n", "g", ":GFiles ") -map("n", "p", ":Buffers ") -map("n", "h", ":Helptags ") -map("n", ";", ":History: ") -map("n", "c", ":Commands ") -map("n", "s", ":Rg ") +map("n", "o", ":Files") +--map("n", "O", [[:lua vim.fn['fzf#vim#files']('~/')]]) +map("n", "O", ":Files ~/") +map("n", "b", ":Buffers") +map("n", "h", ":Helptags") +map("n", ";", ":History:") +map("n", "c", ":Commands") +map("n", "r", ":Rg") +map("n", "s", ":Lines") --map("n", "[", ":Windows ") +map("n", "gf", ":GFiles") +map("n", "gn", ":GFiles?") +map("n", "gc", ":Commits") + +------------------ +-- FZF-CHECKOUT -- +------------------ +map("n", "gb", ":GBranches") + --------- -- ALE -- --------- @@ -88,9 +167,22 @@ map("n", "s", ":Rg ") --map("n", "m", [[:lua require("harpoon.mark").add_file() ]]) map("n", "x", ":lua harpoon_rm_file()") -map("n", "m", [[:lua harpoon_toggle_file()]]) +--map("n", "m", [[:lua harpoon_toggle_file()]]) map("n", "M", [[:lua harpoon_clear_all()]]) map("n", "l", [[:lua require("harpoon.ui").toggle_quick_menu()]]) --map("n", "n", [[:lua require("harpoon.ui").nav_next() ]]) --map("n", "N", [[:lua require("harpoon.ui").nav_prev() ]]) + +----------- +-- CODEX -- +----------- +local create_completion = ":lua vim.fn.CreateCompletion(200)" +map("n", "", create_completion) +map("i", "", ("" .. create_completion)) +--map("i", "", "liul:CreateCompletion") + +-------------- +-- NVIM FZF -- +-------------- +map("n", "m", [[:lua fzf_buffer_add_to_harpoon()]]) diff --git a/lua/lsp.lua b/lua/lsp.lua index c5a5b03..174ae26 100644 --- a/lua/lsp.lua +++ b/lua/lsp.lua @@ -137,9 +137,12 @@ local common_on_attach = function(client, bufnr) end -- enable null-ls integration (optional) -require("null-ls").config {} -require("lspconfig")["null-ls"].setup { +-- lspconfig integration is deprecated; pass options to setup instead +--require("null-ls").config {} +require("null-ls").setup { on_attach = common_on_attach, + --} + --require("lspconfig")["null-ls"].setup { handlers = { ["textDocument/publishDiagnostics"] = vim.lsp.with( vim.lsp.diagnostic.on_publish_diagnostics, @@ -200,12 +203,12 @@ require("nvim-lsp-installer").on_server_ready( } } - local vscode_servers = {html = "html", jsonls = "json", cssls = "css"} - local lang = vscode_servers[server.name] + --local vscode_servers = {html = "html", jsonls = "json", cssls = "css"} + --local lang = vscode_servers[server.name] - if lang ~= nil then - opts.cmd = {("vscode-" .. lang .. "-language-server"), "--stdio"} - end + --if lang ~= nil then + -- opts.cmd = {("vscode-" .. lang .. "-language-server"), "--stdio"} + --end if server.name == "tsserver" then opts.on_attach = tsserver_on_attach diff --git a/lua/plugins.lua b/lua/plugins.lua index d2d47f8..1f517dc 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -4,6 +4,9 @@ require("packer").startup( function() use "wbthomason/packer.nvim" + -- OPENAI CODEX + use "tom-doerr/vim_codex" + -- NAVIGATION use { "phaazon/hop.nvim", @@ -30,6 +33,8 @@ require("packer").startup( use "junegunn/fzf.vim" use "rbgrouleff/bclose.vim" use "francoiscabrol/ranger.vim" + use "vijaymarupudi/nvim-fzf" + use "vijaymarupudi/nvim-fzf-commands" -- GIT use "tpope/vim-fugitive" @@ -47,6 +52,8 @@ require("packer").startup( use "dense-analysis/ale" --use "nathanmsmith/nvim-ale-diagnostic" use "turbio/bracey.vim" + -- init.lua + use "lukas-reineke/indent-blankline.nvim" -- LSP use {"nvim-treesitter/nvim-treesitter", run = ":TSUpdate"}