From 57ac15367f8b092779cf53e07710660321566379 Mon Sep 17 00:00:00 2001 From: Fabian Page Date: Mon, 27 Feb 2023 15:38:19 +0100 Subject: [PATCH 1/2] initial commit --- .gitignore | 1 + flake.lock | 17 ++++ flake.nix | 10 +++ modules/lib/types-plugin.nix | 1 + modules/modules.nix | 1 + modules/tmux/default.nix | 145 +++++++++++++++++++++++++++++++++++ 6 files changed, 175 insertions(+) create mode 100644 modules/tmux/default.nix diff --git a/.gitignore b/.gitignore index 121ea04..5e0be38 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ result .config +.direnv diff --git a/flake.lock b/flake.lock index df4f993..abf9e2e 100644 --- a/flake.lock +++ b/flake.lock @@ -785,6 +785,7 @@ "sqls-nvim": "sqls-nvim", "telescope": "telescope", "tidalcycles": "tidalcycles", + "tmux-navigator": "tmux-navigator", "todo-comments": "todo-comments", "tokyonight": "tokyonight", "trouble": "trouble", @@ -923,6 +924,22 @@ "type": "github" } }, + "tmux-navigator": { + "flake": false, + "locked": { + "lastModified": 1673311166, + "narHash": "sha256-gF1b5aBQTNQm2hCY5aR+RSU4cCNG356Yg6uPnlgqS4o=", + "owner": "christoomey", + "repo": "vim-tmux-navigator", + "rev": "cdd66d6a37d991bba7997d593586fc51a5b37aa8", + "type": "github" + }, + "original": { + "owner": "christoomey", + "repo": "vim-tmux-navigator", + "type": "github" + } + }, "todo-comments": { "flake": false, "locked": { diff --git a/flake.nix b/flake.nix index b342a9f..2e00b9b 100644 --- a/flake.nix +++ b/flake.nix @@ -178,6 +178,12 @@ flake = false; }; + # tmux-navigator + tmux-navigator = { + url = "github:christoomey/vim-tmux-navigator"; + flake = false; + }; + # Rust crates crates-nvim = { url = "github:Saecki/crates.nvim"; @@ -352,6 +358,10 @@ gitsigns.enable = true; }; vim.plantuml.enable = true; + vim.tmux-navigator = { + enable = true; + autosave-on-leave = "wall"; + }; }; }; diff --git a/modules/lib/types-plugin.nix b/modules/lib/types-plugin.nix index aabc6de..30fcebf 100644 --- a/modules/lib/types-plugin.nix +++ b/modules/lib/types-plugin.nix @@ -43,6 +43,7 @@ with lib; let "open-browser" "plantuml-syntax" "plantuml-previewer" + "tmux-navigator" ]; pluginsType = with types; listOf (nullOr (either (enum availablePlugins) package)); diff --git a/modules/modules.nix b/modules/modules.nix index 3ea7604..f9b1446 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -22,6 +22,7 @@ ./telescope ./git ./plantuml + ./tmux ]; pkgsModule = {config, ...}: { diff --git a/modules/tmux/default.nix b/modules/tmux/default.nix new file mode 100644 index 0000000..6e8ef63 --- /dev/null +++ b/modules/tmux/default.nix @@ -0,0 +1,145 @@ +{ + pkgs, + lib, + config, + ... +}: +with lib; +with builtins; let + cfg = config.vim.tmux-navigator; +in { + options.vim = { + tmux-navigator = { + enable = mkOption { + type = types.bool; + default = false; + description = "enable tmux-navigator"; + }; + + autosave-on-leave = mkOption { + type = types.enum ["disabled" "update" "wall"]; + default = "disabled"; + description = "enable autosave when navigating to tmux"; + }; + + disable-when-zoomed = mkOption { + type = types.bool; + default = false; + description = "disable navigator when the tmux pane is zoomed"; + }; + + preserve-zoom = mkOption { + type = types.bool; + default = false; + description = "preserve zoom when moving from "; + }; + + type = mkOption { + type = types.enum ["nvim-cmp"]; + default = "nvim-cmp"; + description = "Set the autocomplete plugin. Options: [nvim-cmp]"; + }; + }; + }; + + config = mkIf cfg.enable { + vim.startPlugins = [ + "tmux-navigator" + ]; + + vim.configRC.tmux-navigator = nvim.dag.entryAnywhere '' + ${optionalString (cfg.autosave-on-leave == "update") "let g:tmux_navigator_save_on_switch = 1"} + ${optionalString (cfg.autosave-on-leave == "wall") "let g:tmux_navigator_save_on_switch = 2"} + ''; + + # vim.luaConfigRC.completion = mkIf (cfg.type == "nvim-cmp") (nvim.dag.entryAnywhere '' + # local has_words_before = function() + # local line, col = unpack(vim.api.nvim_win_get_cursor(0)) + # return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil + # end + + # local feedkey = function(key, mode) + # vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true) + # end + + # local cmp = require'cmp' + # cmp.setup({ + # snippet = { + # expand = function(args) + # vim.fn["vsnip#anonymous"](args.body) + # end, + # }, + # sources = { + # ${optionalString (config.vim.lsp.enable) "{ name = 'nvim_lsp' },"} + # ${optionalString (config.vim.lsp.rust.enable) "{ name = 'crates' },"} + # { name = 'vsnip' }, + # { name = 'treesitter' }, + # { name = 'path' }, + # { name = 'buffer' }, + # }, + # mapping = { + # [''] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }), + # [''] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c'}), + # [''] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c'}), + # [''] = cmp.config.disable, + # [''] = cmp.mapping({ + # i = cmp.mapping.abort(), + # c = cmp.mapping.close(), + # }), + # [''] = cmp.mapping.confirm({ + # select = true, + # }), + # [''] = cmp.mapping(function (fallback) + # if cmp.visible() then + # cmp.select_next_item() + # elseif vim.fn['vsnip#available'](1) == 1 then + # feedkey("(vsnip-expand-or-jump)", "") + # elseif has_words_before() then + # cmp.complete() + # else + # fallback() + # end + # end, { 'i', 's' }), + # [''] = cmp.mapping(function (fallback) + # if cmp.visible() then + # cmp.select_prev_item() + # elseif vim.fn['vsnip#available'](-1) == 1 then + # feedkeys("(vsnip-jump-prev)", "") + # end + # end, { 'i', 's' }) + # }, + # completion = { + # completeopt = 'menu,menuone,noinsert', + # }, + # formatting = { + # format = function(entry, vim_item) + # -- type of kind + # vim_item.kind = ${ + # optionalString (config.vim.visuals.lspkind.enable) + # "require('lspkind').presets.default[vim_item.kind] .. ' ' .." + # } vim_item.kind + + # -- name for each source + # vim_item.menu = ({ + # buffer = "[Buffer]", + # nvim_lsp = "[LSP]", + # vsnip = "[VSnip]", + # crates = "[Crates]", + # path = "[Path]", + # })[entry.source.name] + # return vim_item + # end, + # } + # }) + # ${optionalString (config.vim.autopairs.enable && config.vim.autopairs.type == "nvim-autopairs") '' + # local cmp_autopairs = require('nvim-autopairs.completion.cmp') + # cmp.event:on('confirm_done', cmp_autopairs.on_confirm_done({ map_char = { text = ""} })) + # ''} + # ''); + + # vim.snippets.vsnip.enable = + # if (cfg.type == "nvim-cmp") + # then true + # else config.vim.snippets.vsnip.enable; + }; +} From ac9c54a959f4ef3dd400c343c7b881f656a743c2 Mon Sep 17 00:00:00 2001 From: Fabian Page Date: Mon, 27 Feb 2023 15:44:14 +0100 Subject: [PATCH 2/2] added some options --- flake.nix | 4 -- modules/tmux/default.nix | 102 ++------------------------------------- 2 files changed, 4 insertions(+), 102 deletions(-) diff --git a/flake.nix b/flake.nix index 2e00b9b..9ec161e 100644 --- a/flake.nix +++ b/flake.nix @@ -358,10 +358,6 @@ gitsigns.enable = true; }; vim.plantuml.enable = true; - vim.tmux-navigator = { - enable = true; - autosave-on-leave = "wall"; - }; }; }; diff --git a/modules/tmux/default.nix b/modules/tmux/default.nix index 6e8ef63..ba9ca16 100644 --- a/modules/tmux/default.nix +++ b/modules/tmux/default.nix @@ -13,7 +13,7 @@ in { enable = mkOption { type = types.bool; default = false; - description = "enable tmux-navigator"; + description = "enable tmux-navigator, this plugin will only work together with tmuxPlugins.vim-tmux-navigator"; }; autosave-on-leave = mkOption { @@ -33,12 +33,6 @@ in { default = false; description = "preserve zoom when moving from "; }; - - type = mkOption { - type = types.enum ["nvim-cmp"]; - default = "nvim-cmp"; - description = "Set the autocomplete plugin. Options: [nvim-cmp]"; - }; }; }; @@ -48,98 +42,10 @@ in { ]; vim.configRC.tmux-navigator = nvim.dag.entryAnywhere '' - ${optionalString (cfg.autosave-on-leave == "update") "let g:tmux_navigator_save_on_switch = 1"} + ${optionalString (cfg.autosave-on-leave == "update") "let g:tmux_navigator_save_on_switch = 1"} ${optionalString (cfg.autosave-on-leave == "wall") "let g:tmux_navigator_save_on_switch = 2"} + ${optionalString (cfg.disable-when-zoomed) "let g:tmux_navigator_disable_when_zoomed = 1"} + ${optionalString (cfg.preserve-zoom) "let g:tmux_navigator_preserve_zoom = 1"} ''; - - # vim.luaConfigRC.completion = mkIf (cfg.type == "nvim-cmp") (nvim.dag.entryAnywhere '' - # local has_words_before = function() - # local line, col = unpack(vim.api.nvim_win_get_cursor(0)) - # return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil - # end - - # local feedkey = function(key, mode) - # vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true) - # end - - # local cmp = require'cmp' - # cmp.setup({ - # snippet = { - # expand = function(args) - # vim.fn["vsnip#anonymous"](args.body) - # end, - # }, - # sources = { - # ${optionalString (config.vim.lsp.enable) "{ name = 'nvim_lsp' },"} - # ${optionalString (config.vim.lsp.rust.enable) "{ name = 'crates' },"} - # { name = 'vsnip' }, - # { name = 'treesitter' }, - # { name = 'path' }, - # { name = 'buffer' }, - # }, - # mapping = { - # [''] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }), - # [''] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c'}), - # [''] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c'}), - # [''] = cmp.config.disable, - # [''] = cmp.mapping({ - # i = cmp.mapping.abort(), - # c = cmp.mapping.close(), - # }), - # [''] = cmp.mapping.confirm({ - # select = true, - # }), - # [''] = cmp.mapping(function (fallback) - # if cmp.visible() then - # cmp.select_next_item() - # elseif vim.fn['vsnip#available'](1) == 1 then - # feedkey("(vsnip-expand-or-jump)", "") - # elseif has_words_before() then - # cmp.complete() - # else - # fallback() - # end - # end, { 'i', 's' }), - # [''] = cmp.mapping(function (fallback) - # if cmp.visible() then - # cmp.select_prev_item() - # elseif vim.fn['vsnip#available'](-1) == 1 then - # feedkeys("(vsnip-jump-prev)", "") - # end - # end, { 'i', 's' }) - # }, - # completion = { - # completeopt = 'menu,menuone,noinsert', - # }, - # formatting = { - # format = function(entry, vim_item) - # -- type of kind - # vim_item.kind = ${ - # optionalString (config.vim.visuals.lspkind.enable) - # "require('lspkind').presets.default[vim_item.kind] .. ' ' .." - # } vim_item.kind - - # -- name for each source - # vim_item.menu = ({ - # buffer = "[Buffer]", - # nvim_lsp = "[LSP]", - # vsnip = "[VSnip]", - # crates = "[Crates]", - # path = "[Path]", - # })[entry.source.name] - # return vim_item - # end, - # } - # }) - # ${optionalString (config.vim.autopairs.enable && config.vim.autopairs.type == "nvim-autopairs") '' - # local cmp_autopairs = require('nvim-autopairs.completion.cmp') - # cmp.event:on('confirm_done', cmp_autopairs.on_confirm_done({ map_char = { text = ""} })) - # ''} - # ''); - - # vim.snippets.vsnip.enable = - # if (cfg.type == "nvim-cmp") - # then true - # else config.vim.snippets.vsnip.enable; }; }