diff --git a/flake.lock b/flake.lock index 175ccb9..eb434b6 100644 --- a/flake.lock +++ b/flake.lock @@ -49,11 +49,11 @@ ] }, "locked": { - "lastModified": 1641459437, - "narHash": "sha256-z0IOcc6LLbVhyri/aTyWzRqJs3p1pBK9idOiMwCWiqs=", + "lastModified": 1641700429, + "narHash": "sha256-+Pd33S+4+VX6RYGJQ5Q4n46+iRLr9y9ilq9oC/bcnoc=", "owner": "nix-community", "repo": "home-manager", - "rev": "c751aeb19e84a0a777f36fd5ea73482a066bb406", + "rev": "a90ddcd62748e445bbbe01834595eda29dc28db9", "type": "github" }, "original": { @@ -84,11 +84,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1641230035, - "narHash": "sha256-hFyqihERaTbLxCOlugy/rpp22VLtLh8SPRnA2uu3F/8=", + "lastModified": 1641528457, + "narHash": "sha256-FyU9E63n1W7Ql4pMnhW2/rO9OftWZ37pLppn/c1aisY=", "owner": "nixos", "repo": "nixpkgs", - "rev": "78cd22c1b8604de423546cd49bfe264b786eca13", + "rev": "ff377a78794d412a35245e05428c8f95fef3951f", "type": "github" }, "original": { diff --git a/home-manager/modules/fish/default.nix b/home-manager/modules/fish/default.nix index 26fc412..9586e81 100644 --- a/home-manager/modules/fish/default.nix +++ b/home-manager/modules/fish/default.nix @@ -46,6 +46,10 @@ in shellAliases = { # code = "${pkgs.vscode}/bin/code --enable-features=UseOzonePlatform --ozone-platform=wayland"; ls = "${pkgs.exa}/bin/exa -Fb"; + + vimdiff = mkIf (config.eboskma.programs.neovim.enable) "nvim -d"; + vim = mkIf (config.eboskma.programs.neovim.enable) "nvim"; + vi = mkIf (config.eboskma.programs.neovim.enable) "nvim"; }; interactiveShellInit = '' ''; diff --git a/home-manager/modules/neovim/config/init.lua b/home-manager/modules/neovim/config/init.lua new file mode 100644 index 0000000..fd4e059 --- /dev/null +++ b/home-manager/modules/neovim/config/init.lua @@ -0,0 +1,59 @@ +-- vim: ft=lua + +local execute = vim.api.nvim_command +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', 'https://github.com/wbthomason/packer.nvim', install_path}) + execute 'packadd packer.nvim' +end + +vim.cmd 'filetype on' +vim.cmd 'filetype plugin on' +vim.cmd 'filetype indent on' +vim.cmd 'syntax enable' + +local packer = require('packer') + +packer.startup(function() + + -- fzf-like file navigator + use 'nvim-telescope/telescope.nvim' + use 'nvim-lua/popup.nvim' + use 'nvim-lua/plenary.nvim' + use 'kyazdani42/nvim-web-devicons' + + -- Better syntax highlighting + use { 'nvim-treesitter/nvim-treesitter', run = ':TSUpdate' } + + -- LSP config + use 'neovim/nvim-lspconfig' + use 'simrat39/rust-tools.nvim' + + -- Elixir + use {'elixir-editors/vim-elixir', ft = { 'eelixir', 'elixir' }} + + -- Completion + use 'hrsh7th/nvim-compe' + + -- Monokai theme + use 'tanvirtin/monokai.nvim' + + -- Airline + use 'vim-airline/vim-airline' + use 'vim-airline/vim-airline-themes' + + -- Snippets + use 'hrsh7th/vim-vsnip' + + -- Colemak keymap - This needs to be last + use 'jooize/vim-colemak' +end) + +require('settings') +require('keys') +require('highlight') +require('lsp') +require('completion') diff --git a/home-manager/modules/neovim/config/lua/completion.lua b/home-manager/modules/neovim/config/lua/completion.lua new file mode 100644 index 0000000..4e77507 --- /dev/null +++ b/home-manager/modules/neovim/config/lua/completion.lua @@ -0,0 +1,76 @@ +-- vim: ft=lua + +local map = vim.api.nvim_set_keymap + +-- Compe setup +require('compe').setup { + enabled = true; + autocomplete = true; + debug = false; + min_length = 1; + preselect = 'enable'; + throttle_time = 80; + source_timeout = 200; + incomplete_delay = 400; + max_abbr_width = 100; + max_kind_width = 100; + max_menu_width = 100; + documentation = true; + + source = { + path = true; + buffer = true; + calc = true; + vsnip = true; + nvim_lsp = true; + nvim_lua = true; + spell = true; + treesitter = true; + }; +} + +local t = function(str) + 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 + +-- Use (s-)tab to: +--- move to prev/next item in completion menuone +--- jump to prev/next snippet's placeholder +_G.tab_complete = function() + if vim.fn.pumvisible() == 1 then + return t "" + 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 "" + else + return t "" + end +end + +map("i", "", "v:lua.tab_complete()", {expr = true}) +map("s", "", "v:lua.tab_complete()", {expr = true}) +map("i", "", "v:lua.s_tab_complete()", {expr = true}) +map("s", "", "v:lua.s_tab_complete()", {expr = true}) + +vim.o.completeopt = 'menuone,noselect' + +map('i', '', 'compe#complete()', {expr = true, silent = true, noremap = true}) +map('i', '', "compe#confirm('')", {expr = true, silent = true, noremap = true}) +map('i', '', "compe#close()", {expr = true, silent = true, noremap = true}) +map('i', '', "compe#scroll({'delta': +4})", {expr = true, silent = true, noremap = true}) +map('i', '', "compe#scroll({'delta': -4})", {expr = true, silent = true, noremap = true}) diff --git a/home-manager/modules/neovim/config/lua/highlight.lua b/home-manager/modules/neovim/config/lua/highlight.lua new file mode 100644 index 0000000..f3962df --- /dev/null +++ b/home-manager/modules/neovim/config/lua/highlight.lua @@ -0,0 +1,19 @@ +-- vim: ft=lua + +local treesitter = require('nvim-treesitter.configs') + +treesitter.setup({ + ensure_installed = 'maintained', + autopairs = { + enable = true + }, + highlight = { + enable = true + }, + incremental_selection = { + enable = true + }, + indent = { + enable = true + } +}) diff --git a/home-manager/modules/neovim/config/lua/keys.lua b/home-manager/modules/neovim/config/lua/keys.lua new file mode 100644 index 0000000..e330239 --- /dev/null +++ b/home-manager/modules/neovim/config/lua/keys.lua @@ -0,0 +1,36 @@ +local map = vim.api.nvim_set_keymap + +-- Set space as leader +map('n', ' ', '', {noremap = true}) +vim.g.mapleader = ' ' + +-- Clear highlights with +map('n', ' ', ':noh', {noremap = true}) + +-- Splits +map('n', 's', 's', {noremap = true}) +map('n', 'v', 'v', {noremap = true}) + +-- Previous and next tab +map('n', '[', ':tabp', {noremap = true}) +map('n', ']', ':tabn', {noremap = true}) + +-- New tab +map('n', 't', ':tabnew', {noremap = true}) + +-- File finder +map('n', 'ff', 'Telescope find_files', {noremap = true}) +map('n', 'fg', 'Telescope live_grep', {noremap = true}) +map('n', 'fb', 'Telescope buffers', {noremap = true}) +map('n', 'fh', 'Telescope help_tags', {noremap = true}) + +-- LSP +map('n', 'gd', 'lua vim.lsp.buf.definition()', {noremap = true, silent = true}) +map('n', 'gD', 'lua vim.lsp.buf.declaration()', {noremap = true, silent = true}) +map('n', 'gr', 'lua vim.lsp.buf.references()', {noremap = true, silent = true}) +map('n', 'gi', 'lua vim.lsp.buf.implementation()', {noremap = true, silent = true}) + +map('n', '', 'lua vim.lsp.buf.hover()', {noremap = true, silent = true}) +map('n', '', 'lua vim.lsp.buf.signature_help()', {noremap = true, silent = true}) +map('n', '[g', 'lua vim.lsp.diagnostic.goto_prev()', {noremap = true, silent = true}) +map('n', ']g', 'lua vim.lsp.diagnostic.goto_next()', {noremap = true, silent = true}) diff --git a/home-manager/modules/neovim/config/lua/lsp.lua b/home-manager/modules/neovim/config/lua/lsp.lua new file mode 100644 index 0000000..b70e1b6 --- /dev/null +++ b/home-manager/modules/neovim/config/lua/lsp.lua @@ -0,0 +1,46 @@ +-- vim: ft=lua + +local nvim_lsp = require('lspconfig') + +nvim_lsp.elixirls.setup({ + cmd = {'/home/erwin/elixir-ls/language_server.sh'}, + settings = { + elixirLS = { + fetchDeps = false + } + } +}) + +local rust_opts = { + tools = { + autoSetHints = true, + hover_with_actions = true, + runnables = { + use_telescope = true, + }, + inlay_hints = { + show_parameter_hints = true, + parameter_hints_prefix = '<-', + other_hints_prefix = '=>', + max_len_align = false, + max_len_align_padding = 1, + right_align = false, + right_align_padding = 7, + }, + hover_actions = { + border = { + {'╭', 'FloatBorder'}, + {'─', 'FloatBorder'}, + {'╮', 'FloatBorder'}, + {'│', 'FloatBorder'}, + {'╯', 'FloatBorder'}, + {'─', 'FloatBorder'}, + {'╰', 'FloatBorder'}, + {'│', 'FloatBorder'}, + }, + }, + }, + server = {}, +} + +require('rust-tools').setup(rust_opts) diff --git a/home-manager/modules/neovim/config/lua/settings.lua b/home-manager/modules/neovim/config/lua/settings.lua new file mode 100644 index 0000000..d25c868 --- /dev/null +++ b/home-manager/modules/neovim/config/lua/settings.lua @@ -0,0 +1,129 @@ +-- vim: ft=lua:foldmethod=marker:foldmarker=[[[,]]] + +local Path = require('plenary.path') + +local g = vim.g +local o = vim.o +local wo = vim.wo +local bo = vim.bo +local cmd = vim.cmd +local api = vim.api + +-- Line numbers [[[ + wo.number = true + wo.relativenumber = true +-- ]]] + +-- Indenting [[[ + bo.autoindent = true + bo.smartindent = true + o.smarttab = true + bo.expandtab = true + bo.tabstop = 2 + bo.shiftwidth = 2 +-- ]]] + +-- Backup and swap files [[[ + local cache_dir = Path:new(vim.env.HOME .. '/.cache/nvim/tmp') + if not cache_dir:exists() then + cache_dir:mkdir({mode = 493}) + end + + o.backupcopy = 'yes' + g.backupdir = cache_dir:expand() + o.updatetime = 300 + bo.swapfile = false +-- ]]] + +-- Theme [[[ + cmd 'colorscheme monokai' + o.termguicolors = true + o.background = 'dark' +-- ]]] + +-- Airline [[[ + g.airline_theme = 'molokai' + g.airline_powerline_fonts = 1 +-- ]]] + +-- Undo stuff [[[ + if vim.fn.exists('+undofile') then + local undo_dir = Path:new(vim.env.HOME .. '/.cache/nvim/undo') + if not undo_dir:exists() then + undo_dir:mkdir({mode = 493}) + end + + o.undofile = true + o.undodir = undo_dir:expand() + o.undolevels = 500 + end +-- ]]] + +-- Misc [[[ + wo.signcolumn = 'auto' + wo.colorcolumn = '+1' + -- bo.textwidth = 120 + o.wildmenu = true + o.hlsearch = true + wo.foldmethod = 'marker' + o.exrc = true + o.secure = true + wo.wrap = false +-- ]]] + +-- netrw [[[ + g.netrw_banner = 1 + g.netrw_liststyle = 3 + g.netrw_altv = 1 + g.netrw_winsize = 20 + g.netrw_preview = 1 +-- ]]] + +-- Autocommands [[[ + function create_augroup(autocmds, name) + cmd('augroup ' .. name) + cmd('autocmd!') + for _, autocmd in ipairs(autocmds) do + cmd('autocmd ' .. table.concat(autocmd, ' ')) + end + cmd('augroup END') + end + + if not vim.fn.has('gui_running') then + o.timeoutlen = 1000 + + create_augroup({ + { 'InsertEnter', '*', 'set timeoutlen=0' }, + { 'InsertLeave', '*', 'set timeoutlen=1000' } + }, 'fast_escape') + end + + if vim.fn.has('autocmd') then + create_augroup({ + { 'FileType', 'text', 'setlocal', 'textwidth=78' }, + { 'FileType', 'gitcommit', 'setlocal', 'spell' }, + { 'FileType', 'markdown', 'setlocal', 'spell' }, + { 'FileType', 'markdown', 'setlocal', 'wrap' }, + { 'BufNewFile,BufRead', '*.ex,*.eex', 'setf', 'elixir' }, + { 'BufNewFile,BufRead', '*.eex,*.leex,*.heex,*.sface', 'setf', 'eelixir' }, + { 'BufNewFile,BufRead', 'mix.lock', 'set', 'filetype=elixir' }, + }, 'filetypes') + end +-- ]]] + +-- Ignores [[[ + vim.opt.wildignore = { + '*/.git/*', + '*/tmp/*', + '*.swp', + '*/.DS_Store', + '*/vendor', + '*/env/*', + '*/deps/*', + '*/_build/*', + '*/elixir_ls/*', + '*/node_modules/*', + '*/*.ghc', + '*/*.o' + } +-- ]]] diff --git a/home-manager/modules/neovim/default.nix b/home-manager/modules/neovim/default.nix index 6e1c76d..accf2f6 100644 --- a/home-manager/modules/neovim/default.nix +++ b/home-manager/modules/neovim/default.nix @@ -7,17 +7,29 @@ in options.eboskma.programs.neovim = { enable = mkEnableOption "activate neovim"; }; config = mkIf cfg.enable { - programs.neovim = { - enable = true; + # unfortunately this does properly support a Lua based config + # programs.neovim = { + # enable = true; - # Enable some aliases - viAlias = true; - vimAlias = true; - vimdiffAlias = true; + # # Enable some aliases + # viAlias = true; + # vimAlias = true; + # vimdiffAlias = true; - withNodeJs = true; - withPython3 = true; - withRuby = true; + # withNodeJs = true; + # withPython3 = true; + # withRuby = true; + + # extraConfig = '' + # luafile ./config.lua + # ''; + # }; + + home.packages = with pkgs; [ neovim ]; + + xdg.configFile.nvim = { + source = ./config; + recursive = true; }; }; } diff --git a/home-manager/modules/ssh/default.nix b/home-manager/modules/ssh/default.nix index 44ef717..f25d403 100644 --- a/home-manager/modules/ssh/default.nix +++ b/home-manager/modules/ssh/default.nix @@ -19,6 +19,7 @@ in KexAlgorithms = "curve25519-sha256,curve25519-sha256@libssh.org,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group-exchange-sha256"; MACs = "hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,umac-128-etm@openssh.com"; HostKeyAlgorithms = "ssh-ed25519,ssh-ed25519-cert-v01@openssh.com,sk-ssh-ed25519@openssh.com,sk-ssh-ed25519-cert-v01@openssh.com,rsa-sha2-256,rsa-sha2-256-cert-v01@openssh.com,rsa-sha2-512,rsa-sha2-512-cert-v01@openssh.com"; + SetEnv = "TERM=xterm-256color"; }; }; home = {