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;