From 4f1f493a1697f96ba4f040fa8eeeb6b7d8f8f0fc Mon Sep 17 00:00:00 2001 From: Tyrel Souza Date: Mon, 2 Jan 2023 15:15:50 -0500 Subject: [PATCH 1/4] more nvim configs --- home/config/nvim/init.lua | 25 +++++ home/config/nvim/init.vim | 180 ------------------------------ home/config/nvim/legacy.vim | 81 ++++++++++++++ home/config/nvim/lua/plugins.lua | 69 ++++++++++++ home/config/nvim/lua/settings.lua | 122 ++++++++++++++++++++ hosts/_common/programs.nix | 7 ++ hosts/_common/xdg.nix | 7 +- 7 files changed, 310 insertions(+), 181 deletions(-) create mode 100644 home/config/nvim/init.lua delete mode 100644 home/config/nvim/init.vim create mode 100644 home/config/nvim/legacy.vim create mode 100644 home/config/nvim/lua/plugins.lua create mode 100644 home/config/nvim/lua/settings.lua diff --git a/home/config/nvim/init.lua b/home/config/nvim/init.lua new file mode 100644 index 0000000..a10eace --- /dev/null +++ b/home/config/nvim/init.lua @@ -0,0 +1,25 @@ +require("settings") + +-- Install Packer automatically: +local ensure_packer = function() + local fn = vim.fn + local install_path = fn.stdpath('data')..'/site/pack/packer/start/packer.nvim' + if fn.empty(fn.glob(install_path)) > 0 then + fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path}) + vim.cmd [[packadd packer.nvim]] + return true + end + return false +end + +return require('packer').startup(function(use) + -- Packer can manage itself + use("wbthomason/packer.nvim") + + require("plugins")(use) + + local packer_bootstrap = ensure_packer() + if packer_bootstrap then + require('packer').sync() + end +end) diff --git a/home/config/nvim/init.vim b/home/config/nvim/init.vim deleted file mode 100644 index 37f51fd..0000000 --- a/home/config/nvim/init.vim +++ /dev/null @@ -1,180 +0,0 @@ -syntax enable -let mapleader = " " - -call plug#begin('~/.vim/plugged') - Plug 'atelierbram/vim-colors_atelier-schemes' - Plug 'robertmeta/nofrils' - Plug 'vim-test/vim-test' - Plug 'hashivim/vim-terraform' - Plug 'rmagatti/auto-session' - Plug 'rmagatti/session-lens' - Plug 'ludovicchabant/vim-gutentags' - Plug 'ervandew/supertab' - Plug 'preservim/nerdtree' - Plug 'liuchengxu/space-vim-dark' - Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' } - Plug 'junegunn/fzf.vim' - Plug 'mhinz/vim-startify' - Plug 'jeetsukumaran/vim-buffergator' - Plug 'ap/vim-buftabline' - Plug 'airblade/vim-gitgutter' - Plug 'majutsushi/tagbar' - Plug 'vim-airline/vim-airline' - Plug 'enricobacis/vim-airline-clock' - Plug 'nvim-lua/plenary.nvim' - Plug 'nvim-telescope/telescope.nvim' - Plug 'thoughtbot/vim-rspec' - Plug 'voldikss/vim-floaterm' - Plug 'fatih/vim-go' - Plug 'whatyouhide/vim-gotham' - Plug 'nanotech/jellybeans.vim' - Plug 'sickill/vim-monokai' - Plug 'flebel/vim-mypy', { 'for': 'python', 'branch': 'bugfix/fast_parser_is_default_and_only_parser' } - Plug 'tpope/vim-fugitive' - Plug 'tpope/vim-rhubarb' - Plug 'psf/black', { 'branch': 'stable' } - Plug 'gf3/peg.vim' -call plug#end() - - -map :NERDTreeToggle - - -set tabstop=2 -set shiftwidth=2 -set expandtab -set hidden -set background=dark -set autoindent -set preserveindent -set copyindent -set mouse= -set shell=~/.nix-profile/bin/fish - -" Set Colors -if (has("termguicolors")) - set termguicolors -endif -colorscheme Atelier_SulphurpoolDark -hi Comment cterm=italic - -" Relative numbers and when not in buffer set absolute numbers -set number relativenumber -augroup numbertoggle - autocmd! - autocmd BufEnter,FocusGained,InsertLeave * set relativenumber - autocmd BufLeave,FocusLost,InsertEnter * set norelativenumber -augroup END - -" Disable EX Mode -map q: -" Disable EX Mode -nnoremap Q - -nnoremap :bnext -nnoremap :bprev -nmap bq :bp bd # - -" Airline -let g:airline#extensions#clock#format = '%I:%M:%S %X' - -" Find files using Telescope command-line sugar. -nnoremap ff Telescope find_files -nnoremap fg Telescope live_grep -nnoremap fb Telescope buffers -nnoremap fa Ag -" nnoremap ft Telescope help_tags -"lua << EOF -"require('telescope').setup{ -" file_ignore_patterns = {"node_modules","./venv/"}, -"} -"EOF - -" RSpec.vim mappings -map rt :call RunCurrentSpecFile() -map rs :call RunNearestSpec() -map rl :call RunLastSpec() -map ra :call RunAllSpecs() - -" let g:python_host_prog = '~/.nvim.pythonenv2/bin/python' -if exists("$VIRTUAL_ENV") - let g:python3_host_prog=substitute(system("which -a python3 | head -n2 | tail -n1"), "\n", '', 'g') -else - let g:python3_host_prog=substitute(system("which python3"), "\n", '', 'g') -endif - -" Floaterm -let g:floaterm_keymap_toggle = '' -let g:floaterm_width = 0.9 -let g:floaterm_height = 0.9 - - -" Line Numbers -set number relativenumber " Turn line numbering on at startup -noremap :set invnumber invrelativenumber - -"Tagbar -" -noremap :Tagbar -let g:tagbar_autofocus=1 - -" Session Lens -lua < :SearchSession - - -" Syntax Colors -function! SynStack () - for i1 in synstack(line("."), col(".")) - let i2 = synIDtrans(i1) - let n1 = synIDattr(i1, "name") - let n2 = synIDattr(i2, "name") - echo n1 "->" n2 - endfor -endfunction - - -" TreeSitter -lua <gb :.GBrowse - - -" vim-test -nmap t. :TestNearest -nmap tf :TestFile -nmap ts :TestSuite -let test#strategy = "neovim" - -" Mypy -nmap mp :Mypy - diff --git a/home/config/nvim/legacy.vim b/home/config/nvim/legacy.vim new file mode 100644 index 0000000..95673c0 --- /dev/null +++ b/home/config/nvim/legacy.vim @@ -0,0 +1,81 @@ +syntax enable +let mapleader = " " + + +set autoindentz +set preserveindent +set copyindent +set shell=~/.nix-profile/bin/fish + +" Set Colors +if (has("termguicolors")) + set termguicolors +endif +hi Comment cterm=italic + +" Relative numbers and when not in buffer set absolute numbers +set number relativenumber +augroup numbertoggle + autocmd! + autocmd BufEnter,FocusGained,InsertLeave * set relativenumber + autocmd BufLeave,FocusLost,InsertEnter * set norelativenumber +augroup END + +" Disable EX Mode +map q: +" Disable EX Mode +nnoremap Q + + +" Airline +let g:airline#extensions#clock#format = '%I:%M:%S %X' + + +" nnoremap ft Telescope help_tags + + + +" let g:python_host_prog = '~/.nvim.pythonenv2/bin/python' +if exists("$VIRTUAL_ENV") + let g:python3_host_prog=substitute(system("which -a python3 | head -n2 | tail -n1"), "\n", '', 'g') +else + let g:python3_host_prog=substitute(system("which python3"), "\n", '', 'g') +endif + + +" Line Numbers +set number relativenumber " Turn line numbering on at startup +noremap :set invnumber invrelativenumber + +"Tagbar +" + + +" Syntax Colors +function! SynStack () + for i1 in synstack(line("."), col(".")) + let i2 = synIDtrans(i1) + let n1 = synIDattr(i1, "name") + let n2 = synIDattr(i2, "name") + echo n1 "->" n2 + endfor +endfunction + + +" Guten Tags +" set statusline+=%{gutentags#statusline()} + + +" Indent Line +let g:indentLine_char = '│' + + +" vim-test +nmap t. :TestNearest +nmap tf :TestFile +nmap ts :TestSuite +let test#strategy = "neovim" + +" Mypy +nmap mp :Mypy + diff --git a/home/config/nvim/lua/plugins.lua b/home/config/nvim/lua/plugins.lua new file mode 100644 index 0000000..1600459 --- /dev/null +++ b/home/config/nvim/lua/plugins.lua @@ -0,0 +1,69 @@ +vim.cmd([[autocmd BufWritePost plugins.lua PackerCompile]]) + +return function(use) + local parser_install_dir = vim.fn.stdpath("cache") .. "/treesitters" + vim.fn.mkdir(parser_install_dir, "p") + -- Prevents reinstall of treesitter plugins every boot + vim.opt.runtimepath:append(parser_install_dir) + + -- Treesitter is managed by the package config, we just manage configs/deps here + -- use({ "nvim-treesitter/nvim-treesitter-refactor" }) + -- use({ "RRethy/nvim-treesitter-textsubjects" }) + -- require("nvim-treesitter.configs").setup({ + -- highlight = { enable = true, disable = { "lua" } }, + -- indent = { enable = true }, + -- refactor = { highlight_definitions = { enable = true } }, + -- incremental_selection = { enable = true }, + -- matchup = { enable = true }, + -- textsubjects = { + -- enable = true, + -- prev_selection = ",", + -- keymaps = { + -- ["."] = "textsubjects-smart", + -- }, + -- }, + -- parser_install_dir = parser_install_dir, + -- }) + + use({'atelierbram/vim-colors_atelier-schemes'}) + use({'robertmeta/nofrils'}) + use({'vim-test/vim-test'}) + use({'hashivim/vim-terraform'}) + use({'rmagatti/auto-session'}) + use({'rmagatti/session-lens', + config = function(){ + require'session-lens'.setup { path_display={'shorten'}, } + } + }) + use({'ludovicchabant/vim-gutentags'}) + -- use({'ervandew/supertab'}) + use({'preservim/nerdtree'}) + use({'liuchengxu/space-vim-dark'}) + use({'junegunn/fzf', dir='~/.fzf'}) + use({'junegunn/fzf.vim'}) + use({'mhinz/vim-startify'}) + use({'jeetsukumaran/vim-buffergator'}) + use({'ap/vim-buftabline'}) + use({'airblade/vim-gitgutter'}) + use({'majutsushi/tagbar'}) + use { + 'nvim-lualine/lualine.nvim', + requires = { 'kyazdani42/nvim-web-devicons', opt = true } + } + use({ + 'nvim-telescope/telescope.nvim', + config = function () { + require('telescope').setup{ file_ignore_patterns = {"node_modules","./venv/"}, } + } + }) + use({'thoughtbot/vim-rspec'}) + use({'voldikss/vim-floaterm'}) + use({'fatih/vim-go'}) + use({'whatyouhide/vim-gotham'}) + use({'nanotech/jellybeans.vim'}) + use({'sickill/vim-monokai'}) + use({'tpope/vim-fugitive'}) + use({'tpope/vim-rhubarb'}) + use({'gf3/peg.vim'}) + +end diff --git a/home/config/nvim/lua/settings.lua b/home/config/nvim/lua/settings.lua new file mode 100644 index 0000000..87bd69c --- /dev/null +++ b/home/config/nvim/lua/settings.lua @@ -0,0 +1,122 @@ +vim.g.mapleader = " " +vim.g.maplocalleader = " " + +vim.opt.shell = "/usr/local/bin/fish" + +vim.opt.history = 1000 +vim.opt.termguicolors = true +vim.opt.background = "dark" + +vim.opt.mouse = "" -- disable +-- vim.opt.ruler = true -- Position at the bottom of the screen +vim.opt.joinspaces = false +vim.opt.hidden = true +vim.opt.previewheight = 5 +-- +vim.opt.shortmess = vim.o.shortmess .. "atI" +vim.opt.lazyredraw = true +vim.opt.splitbelow = true +vim.opt.splitright = true + +-- Global settings +vim.opt.autochdir = true -- Keep vim's directory context same as the current buffer +vim.opt.listchars = "tab:> ,trail:.,extends:$,nbsp:_" +vim.opt.fillchars = "fold:-" + +-- Search +vim.opt.hlsearch = true +vim.opt.incsearch = true +vim.opt.ignorecase = true +vim.opt.wildmode = "list:longest" -- Autocomplete + +-- Buffer settings +vim.opt.autoindent = true +vim.opt.expandtab = true +vim.opt.shiftwidth = 2 +vim.opt.softtabstop = 4 +vim.opt.tabstop = 2 +vim.opt.undofile = true + +vim.opt.number = true +vim.opt.relativenumber = true + +vim.g.colors = "Atelier_SulphurpoolDark" +vim.g.floaterm_keymap_toggle = '' +vim.g.floaterm_width = 0.9 +vim.g.floaterm_height = 0.9 + + +vim.g.tagbar_autofocus=1 + + + +-- Highlight yank +vim.api.nvim_command([[ + au TextYankPost * lua vim.highlight.on_yank {higroup="IncSearch", timeout=150, on_visual=true} +]]) + +-- TODO: ... the rest of plugin/legacy.vim + +local map = vim.api.nvim_set_keymap +local function t(str) -- Convert termcodes for mapping + return vim.api.nvim_replace_termcodes(str, true, true, true) +end + +local check_back_space = function() + local col = vim.fn.col(".") - 1 + if col == 0 or vim.fn.getline("."):sub(col, col):match("%s") then + return true + else + return false + end +end + +_G.tab_complete = function() + if vim.fn.pumvisible() == 1 then + return t("") + elseif vim.fn.call("vsnip#available", { 1 }) == 1 then + return t("(vsnip-expand-or-jump)") + elseif check_back_space() then + return t("") + else + return vim.fn["compe#complete"]() + end +end +_G.s_tab_complete = function() + if vim.fn.pumvisible() == 1 then + return t("") + elseif vim.fn.call("vsnip#jumpable", { -1 }) == 1 then + return t("(vsnip-jump-prev)") + else + -- If is not working in your terminal, change it to + return t("") + end +end + +vim.api.nvim_set_keymap("i", "", "v:lua.tab_complete()", { expr = true }) +vim.api.nvim_set_keymap("s", "", "v:lua.tab_complete()", { expr = true }) +vim.api.nvim_set_keymap("i", "", "v:lua.s_tab_complete()", { expr = true }) +vim.api.nvim_set_keymap("s", "", "v:lua.s_tab_complete()", { expr = true }) + +map("v", ">", ">gv", {}) -- Retain visual select when indenting +map("v", "<", "bq",":bp bd #", {silent=true}) + +vim.api.nvim_set_keymap("n", "ff", ":Telescope find_files", {silent=true}) +vim.api.nvim_set_keymap("n", "fg", ":Telescope live_grep", {silent=true}) +vim.api.nvim_set_keymap("n", "fb", ":Telescope buffers", {silent=true}) +vim.api.nvim_set_keymap("n", "fa", ":Ag", {silent=true}) + +vim.api.nvim_set_keymap("n", "gb",":.GBrowse", {silent=true}) + +vim.api.nvim_set_keymap("n", "", ":bprev", {silent = true}) +vim.api.nvim_set_keymap("n", "", ":bnext", {silent = true}) +vim.api.nvim_set_keymap("n", "", ":NERDTreeToggle", {silent = true}) + +vim.api.nvim_set_keymap("n", "", ":set invnumber invrelativenumber", {silent = true }) +vim.api.nvim_set_keymap("n", "",":SearchSession", {silent = true }) +vim.api.nvim_set_keymap("n", "", ":Tagbar", {silent = true }) + + diff --git a/hosts/_common/programs.nix b/hosts/_common/programs.nix index 38c4655..af7eec3 100644 --- a/hosts/_common/programs.nix +++ b/hosts/_common/programs.nix @@ -27,6 +27,13 @@ # Inject tree-sitters, since they're annoying to maintain with sideloading (nvim-treesitter.withPlugins (plugins: pkgs.tree-sitter.allGrammars)) ]; + # We used to manage our own init.lua but now we want the home-manager + # managed init.vim to load our init.lua which makes this a little dirty. + extraConfig = '' + lua << EOF + ${builtins.readFile ../../home/config/nvim/init.lua} + EOF + ''; }; programs.fish = { diff --git a/hosts/_common/xdg.nix b/hosts/_common/xdg.nix index d730ea5..b8bc91c 100644 --- a/hosts/_common/xdg.nix +++ b/hosts/_common/xdg.nix @@ -1,10 +1,15 @@ -{ pkgs, ... }: +{ pkgs, config, ... }: { xdg.configFile = { "nvim" = { source = ../../home/config/nvim; recursive = true; }; + "nvim/lua" = { + source = config.lib.file.mkOutOfStoreSymlink ../config/nvim/lua; + recursive = true; + }; + "nvim/legacy.vim".source = config.lib.file.mkOutOfStoreSymlink ../../home/config/nvim/legacy.vim; "fish" = { source = ../../home/config/fish; recursive = true; -- 2.34.1 From d2c7d381d0583da8426843a5d02486656b1d6992 Mon Sep 17 00:00:00 2001 From: Tyrel Souza Date: Mon, 2 Jan 2023 15:22:22 -0500 Subject: [PATCH 2/4] fix functions, derp --- home/config/nvim/lua/plugins.lua | 8 ++------ home/config/nvim/lua/settings.lua | 8 ++++---- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/home/config/nvim/lua/plugins.lua b/home/config/nvim/lua/plugins.lua index 1600459..6e77d92 100644 --- a/home/config/nvim/lua/plugins.lua +++ b/home/config/nvim/lua/plugins.lua @@ -31,9 +31,7 @@ return function(use) use({'hashivim/vim-terraform'}) use({'rmagatti/auto-session'}) use({'rmagatti/session-lens', - config = function(){ - require'session-lens'.setup { path_display={'shorten'}, } - } + config = function() require'session-lens'.setup { path_display={'shorten'} } end }) use({'ludovicchabant/vim-gutentags'}) -- use({'ervandew/supertab'}) @@ -52,9 +50,7 @@ return function(use) } use({ 'nvim-telescope/telescope.nvim', - config = function () { - require('telescope').setup{ file_ignore_patterns = {"node_modules","./venv/"}, } - } + config = function () require('telescope').setup{ file_ignore_patterns = {"node_modules","./venv/"} } end }) use({'thoughtbot/vim-rspec'}) use({'voldikss/vim-floaterm'}) diff --git a/home/config/nvim/lua/settings.lua b/home/config/nvim/lua/settings.lua index 87bd69c..8783e7d 100644 --- a/home/config/nvim/lua/settings.lua +++ b/home/config/nvim/lua/settings.lua @@ -93,10 +93,10 @@ _G.s_tab_complete = function() end end -vim.api.nvim_set_keymap("i", "", "v:lua.tab_complete()", { expr = true }) -vim.api.nvim_set_keymap("s", "", "v:lua.tab_complete()", { expr = true }) -vim.api.nvim_set_keymap("i", "", "v:lua.s_tab_complete()", { expr = true }) -vim.api.nvim_set_keymap("s", "", "v:lua.s_tab_complete()", { expr = true }) +-- vim.api.nvim_set_keymap("i", "", "v:lua.tab_complete()", { expr = true }) +-- vim.api.nvim_set_keymap("s", "", "v:lua.tab_complete()", { expr = true }) +-- vim.api.nvim_set_keymap("i", "", "v:lua.s_tab_complete()", { expr = true }) +-- vim.api.nvim_set_keymap("s", "", "v:lua.s_tab_complete()", { expr = true }) map("v", ">", ">gv", {}) -- Retain visual select when indenting map("v", "<", " Date: Mon, 2 Jan 2023 15:37:07 -0500 Subject: [PATCH 3/4] treesitter almost fixed --- Makefile | 0 home/config/nvim/lua/plugins.lua | 37 +++++++++++++++-------------- home/config/nvim/lua/settings.lua | 2 +- home/config/nvim/lua/utils/init.lua | 16 +++++++++++++ 4 files changed, 36 insertions(+), 19 deletions(-) create mode 100644 Makefile create mode 100644 home/config/nvim/lua/utils/init.lua diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e69de29 diff --git a/home/config/nvim/lua/plugins.lua b/home/config/nvim/lua/plugins.lua index 6e77d92..5fe6abe 100644 --- a/home/config/nvim/lua/plugins.lua +++ b/home/config/nvim/lua/plugins.lua @@ -6,24 +6,25 @@ return function(use) -- Prevents reinstall of treesitter plugins every boot vim.opt.runtimepath:append(parser_install_dir) - -- Treesitter is managed by the package config, we just manage configs/deps here - -- use({ "nvim-treesitter/nvim-treesitter-refactor" }) - -- use({ "RRethy/nvim-treesitter-textsubjects" }) - -- require("nvim-treesitter.configs").setup({ - -- highlight = { enable = true, disable = { "lua" } }, - -- indent = { enable = true }, - -- refactor = { highlight_definitions = { enable = true } }, - -- incremental_selection = { enable = true }, - -- matchup = { enable = true }, - -- textsubjects = { - -- enable = true, - -- prev_selection = ",", - -- keymaps = { - -- ["."] = "textsubjects-smart", - -- }, - -- }, - -- parser_install_dir = parser_install_dir, - -- }) + -- Treesitter is managed by the package config, we just manage configs/deps here + use({ "nvim-treesitter/nvim-treesitter-refactor" }) + use({ "RRethy/nvim-treesitter-textsubjects" }) + + require("nvim-treesitter.configs").setup({ + -- highlight = { enable = true, disable = { "lua" } }, + -- indent = { enable = true }, + -- refactor = { highlight_definitions = { enable = true } }, + -- incremental_selection = { enable = true }, + -- matchup = { enable = true }, + -- textsubjects = { + -- enable = true, + -- prev_selection = ",", + -- keymaps = { + -- ["."] = "textsubjects-smart", + -- }, + -- }, + parser_install_dir = parser_install_dir, + }) use({'atelierbram/vim-colors_atelier-schemes'}) use({'robertmeta/nofrils'}) diff --git a/home/config/nvim/lua/settings.lua b/home/config/nvim/lua/settings.lua index 8783e7d..b3f8993 100644 --- a/home/config/nvim/lua/settings.lua +++ b/home/config/nvim/lua/settings.lua @@ -40,7 +40,7 @@ vim.opt.undofile = true vim.opt.number = true vim.opt.relativenumber = true -vim.g.colors = "Atelier_SulphurpoolDark" +vim.cmd 'colorscheme Atelier_SulphurpoolDark' vim.g.floaterm_keymap_toggle = '' vim.g.floaterm_width = 0.9 vim.g.floaterm_height = 0.9 diff --git a/home/config/nvim/lua/utils/init.lua b/home/config/nvim/lua/utils/init.lua new file mode 100644 index 0000000..bd53235 --- /dev/null +++ b/home/config/nvim/lua/utils/init.lua @@ -0,0 +1,16 @@ +local utils = { } + +local scopes = {o = vim.o, b = vim.bo, w = vim.wo} + +function utils.opt(scope, key, value) + scopes[scope][key] = value + if scope ~= 'o' then scopes['o'][key] = value end +end + +function utils.map(mode, lhs, rhs, opts) + local options = {noremap = true} + if opts then options = vim.tbl_extend('force', options, opts) end + vim.api.nvim_set_keymap(mode, lhs, rhs, options) +end + +return utils -- 2.34.1 From ade52e693620d6632d6e053a2655ff806f24ef20 Mon Sep 17 00:00:00 2001 From: Tyrel Souza Date: Mon, 2 Jan 2023 15:37:16 -0500 Subject: [PATCH 4/4] stahp --- Makefile | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 Makefile diff --git a/Makefile b/Makefile deleted file mode 100644 index e69de29..0000000 -- 2.34.1