Neovim config

This commit is contained in:
Erwin Boskma 2022-01-13 09:03:22 +01:00
parent f8fb5e9471
commit b730d12c9a
Signed by: erwin
GPG key ID: 270B20D17394F7E5
10 changed files with 397 additions and 15 deletions

View file

@ -49,11 +49,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1641459437, "lastModified": 1641700429,
"narHash": "sha256-z0IOcc6LLbVhyri/aTyWzRqJs3p1pBK9idOiMwCWiqs=", "narHash": "sha256-+Pd33S+4+VX6RYGJQ5Q4n46+iRLr9y9ilq9oC/bcnoc=",
"owner": "nix-community", "owner": "nix-community",
"repo": "home-manager", "repo": "home-manager",
"rev": "c751aeb19e84a0a777f36fd5ea73482a066bb406", "rev": "a90ddcd62748e445bbbe01834595eda29dc28db9",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -84,11 +84,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1641230035, "lastModified": 1641528457,
"narHash": "sha256-hFyqihERaTbLxCOlugy/rpp22VLtLh8SPRnA2uu3F/8=", "narHash": "sha256-FyU9E63n1W7Ql4pMnhW2/rO9OftWZ37pLppn/c1aisY=",
"owner": "nixos", "owner": "nixos",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "78cd22c1b8604de423546cd49bfe264b786eca13", "rev": "ff377a78794d412a35245e05428c8f95fef3951f",
"type": "github" "type": "github"
}, },
"original": { "original": {

View file

@ -46,6 +46,10 @@ in
shellAliases = { shellAliases = {
# code = "${pkgs.vscode}/bin/code --enable-features=UseOzonePlatform --ozone-platform=wayland"; # code = "${pkgs.vscode}/bin/code --enable-features=UseOzonePlatform --ozone-platform=wayland";
ls = "${pkgs.exa}/bin/exa -Fb"; 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 = '' interactiveShellInit = ''
''; '';

View file

@ -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')

View file

@ -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 "<C-n>"
elseif check_back_space() then
return t "<Tab>"
else
return vim.fn['compe#complete']()
end
end
_G.s_tab_complete = function()
if vim.fn.pumvisible() == 1 then
return t "<C-p>"
else
return t "<S-Tab>"
end
end
map("i", "<Tab>", "v:lua.tab_complete()", {expr = true})
map("s", "<Tab>", "v:lua.tab_complete()", {expr = true})
map("i", "<S-Tab>", "v:lua.s_tab_complete()", {expr = true})
map("s", "<S-Tab>", "v:lua.s_tab_complete()", {expr = true})
vim.o.completeopt = 'menuone,noselect'
map('i', '<C-Space>', 'compe#complete()', {expr = true, silent = true, noremap = true})
map('i', '<CR>', "compe#confirm('<CR>')", {expr = true, silent = true, noremap = true})
map('i', '<C-e>', "compe#close()", {expr = true, silent = true, noremap = true})
map('i', '<C-t>', "compe#scroll({'delta': +4})", {expr = true, silent = true, noremap = true})
map('i', '<C-s>', "compe#scroll({'delta': -4})", {expr = true, silent = true, noremap = true})

View file

@ -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
}
})

View file

@ -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 <space><space>
map('n', '<leader> ', ':noh<cr>', {noremap = true})
-- Splits
map('n', '<leader>s', '<C-w>s', {noremap = true})
map('n', '<leader>v', '<C-w>v', {noremap = true})
-- Previous and next tab
map('n', '<leader>[', ':tabp<cr>', {noremap = true})
map('n', '<leader>]', ':tabn<cr>', {noremap = true})
-- New tab
map('n', '<leader>t', ':tabnew<cr>', {noremap = true})
-- File finder
map('n', '<leader>ff', '<cmd>Telescope find_files<cr>', {noremap = true})
map('n', '<leader>fg', '<cmd>Telescope live_grep<cr>', {noremap = true})
map('n', '<leader>fb', '<cmd>Telescope buffers<cr>', {noremap = true})
map('n', '<leader>fh', '<cmd>Telescope help_tags<cr>', {noremap = true})
-- LSP
map('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<cr>', {noremap = true, silent = true})
map('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<cr>', {noremap = true, silent = true})
map('n', 'gr', '<cmd>lua vim.lsp.buf.references()<cr>', {noremap = true, silent = true})
map('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<cr>', {noremap = true, silent = true})
map('n', '<C-.>', '<cmd>lua vim.lsp.buf.hover()<cr>', {noremap = true, silent = true})
map('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<cr>', {noremap = true, silent = true})
map('n', '[g', '<cmd>lua vim.lsp.diagnostic.goto_prev()<cr>', {noremap = true, silent = true})
map('n', ']g', '<cmd>lua vim.lsp.diagnostic.goto_next()<cr>', {noremap = true, silent = true})

View file

@ -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)

View file

@ -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'
}
-- ]]]

View file

@ -7,17 +7,29 @@ in
options.eboskma.programs.neovim = { enable = mkEnableOption "activate neovim"; }; options.eboskma.programs.neovim = { enable = mkEnableOption "activate neovim"; };
config = mkIf cfg.enable { config = mkIf cfg.enable {
programs.neovim = { # unfortunately this does properly support a Lua based config
enable = true; # programs.neovim = {
# enable = true;
# Enable some aliases # # Enable some aliases
viAlias = true; # viAlias = true;
vimAlias = true; # vimAlias = true;
vimdiffAlias = true; # vimdiffAlias = true;
withNodeJs = true; # withNodeJs = true;
withPython3 = true; # withPython3 = true;
withRuby = true; # withRuby = true;
# extraConfig = ''
# luafile ./config.lua
# '';
# };
home.packages = with pkgs; [ neovim ];
xdg.configFile.nvim = {
source = ./config;
recursive = true;
}; };
}; };
} }

View file

@ -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"; 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"; 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"; 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 = { home = {