vim: Better snippets (and split completion file)
This commit is contained in:
parent
d325eb2d27
commit
6e4130fd26
|
@ -29,7 +29,7 @@
|
||||||
};
|
};
|
||||||
commonShellAliases = {
|
commonShellAliases = {
|
||||||
# Replacement commands
|
# Replacement commands
|
||||||
ls = "lsd";
|
# ls = "lsd"; # lsd is suuuper slow for large directories
|
||||||
cat = "bat -pp";
|
cat = "bat -pp";
|
||||||
|
|
||||||
# Completion for existing commands
|
# Completion for existing commands
|
||||||
|
|
54
hm/vim/completion.nix
Normal file
54
hm/vim/completion.nix
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
{ pkgs, lib, config, ... }:
|
||||||
|
{
|
||||||
|
config = {
|
||||||
|
# Completion
|
||||||
|
programs.nixvim = {
|
||||||
|
extraConfigLuaPre = builtins.readFile ./completion_pre.lua;
|
||||||
|
plugins = {
|
||||||
|
# Snippets
|
||||||
|
# UltiSnips should be the better snippet engine, but:
|
||||||
|
# - Not built-in into Nixvim yet (UPST?)
|
||||||
|
# - Couldn't manage to make it work with friendly-snippets, which seems to give better snippets for Python at least
|
||||||
|
# - Tab switching between fields seems hard to configure
|
||||||
|
luasnip = {
|
||||||
|
enable = true;
|
||||||
|
fromVscode = [
|
||||||
|
{ paths = "${pkgs.vimPlugins.friendly-snippets}"; }
|
||||||
|
# { paths = "${pkgs.vimPlugins.vim-snippets}"; } # UPST Needs snipmate support
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
# Completion
|
||||||
|
nvim-cmp = {
|
||||||
|
enable = true;
|
||||||
|
mapping = {
|
||||||
|
# Proposed example, since there's no default
|
||||||
|
"<C-Space>" = "cmp.mapping.complete()";
|
||||||
|
"<C-d>" = "cmp.mapping.scroll_docs(-4)";
|
||||||
|
"<C-e>" = "cmp.mapping.close()";
|
||||||
|
"<C-f>" = "cmp.mapping.scroll_docs(4)";
|
||||||
|
"<CR>" = "cmp.mapping.confirm({ select = true })";
|
||||||
|
"<S-Tab>" = {
|
||||||
|
action = "nvim_cmp_stab";
|
||||||
|
modes = [ "i" "s" ];
|
||||||
|
};
|
||||||
|
"<Tab>" = {
|
||||||
|
action = "nvim_cmp_tab";
|
||||||
|
modes = [ "i" "s" ];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
sources = [
|
||||||
|
# Respective plugins will get installed automatically
|
||||||
|
{ name = "buffer"; }
|
||||||
|
{ name = "calc"; }
|
||||||
|
{ name = "nvim_lsp"; }
|
||||||
|
{ name = "path"; }
|
||||||
|
{ name = "luasnip"; }
|
||||||
|
];
|
||||||
|
snippet.expand = "luasnip";
|
||||||
|
};
|
||||||
|
lspkind.enable = true; # Add icons to LSP completions
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
32
hm/vim/completion_pre.lua
Normal file
32
hm/vim/completion_pre.lua
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
-- https://github.com/hrsh7th/nvim-cmp/wiki/Example-mappings#luasnip
|
||||||
|
|
||||||
|
local has_words_before = function()
|
||||||
|
unpack = unpack or table.unpack
|
||||||
|
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 luasnip = require("luasnip")
|
||||||
|
local cmp = require("cmp")
|
||||||
|
|
||||||
|
local nvim_cmp_tab = function(fallback)
|
||||||
|
if cmp.visible() then
|
||||||
|
cmp.select_next_item()
|
||||||
|
elseif luasnip.expand_or_jumpable() then
|
||||||
|
luasnip.expand_or_jump()
|
||||||
|
elseif has_words_before() then
|
||||||
|
cmp.complete()
|
||||||
|
else
|
||||||
|
fallback()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local nvim_cmp_stab = function(fallback)
|
||||||
|
if cmp.visible() then
|
||||||
|
cmp.select_prev_item()
|
||||||
|
elseif luasnip.jumpable(-1) then
|
||||||
|
luasnip.jump(-1)
|
||||||
|
else
|
||||||
|
fallback()
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,5 +1,6 @@
|
||||||
{ pkgs, lib, config, ... }:
|
{ pkgs, lib, config, ... }:
|
||||||
let
|
let
|
||||||
|
# UPST
|
||||||
vim-shot-f = pkgs.vimUtils.buildVimPlugin {
|
vim-shot-f = pkgs.vimUtils.buildVimPlugin {
|
||||||
pname = "vim-shot-f";
|
pname = "vim-shot-f";
|
||||||
version = "2016-02-05";
|
version = "2016-02-05";
|
||||||
|
@ -78,33 +79,6 @@ in
|
||||||
# Tabline
|
# Tabline
|
||||||
barbar.enable = true;
|
barbar.enable = true;
|
||||||
|
|
||||||
# Completion
|
|
||||||
nvim-cmp = {
|
|
||||||
enable = true;
|
|
||||||
mapping = { # Proposed example, since there's no default
|
|
||||||
"<C-Space>" = "cmp.mapping.complete()";
|
|
||||||
"<C-d>" = "cmp.mapping.scroll_docs(-4)";
|
|
||||||
"<C-e>" = "cmp.mapping.close()";
|
|
||||||
"<C-f>" = "cmp.mapping.scroll_docs(4)";
|
|
||||||
"<CR>" = "cmp.mapping.confirm({ select = true })";
|
|
||||||
"<S-Tab>" = {
|
|
||||||
action = "cmp.mapping.select_prev_item()";
|
|
||||||
modes = [ "i" "s" ];
|
|
||||||
};
|
|
||||||
"<Tab>" = {
|
|
||||||
action = "cmp.mapping.select_next_item()";
|
|
||||||
modes = [ "i" "s" ];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
sources = [ # Respective plugins will get installed automatically
|
|
||||||
{ name = "buffer"; }
|
|
||||||
{ name = "calc"; }
|
|
||||||
{ name = "nvim_lsp"; }
|
|
||||||
{ name = "path"; }
|
|
||||||
{ name = "vsnip"; }
|
|
||||||
];
|
|
||||||
};
|
|
||||||
lspkind.enable = true; # Add icons to LSP completions
|
|
||||||
|
|
||||||
# Go to whatever
|
# Go to whatever
|
||||||
telescope = {
|
telescope = {
|
||||||
|
@ -254,12 +228,6 @@ in
|
||||||
# Language server
|
# Language server
|
||||||
lsp_signature-nvim # Show argument definition when typing a function
|
lsp_signature-nvim # Show argument definition when typing a function
|
||||||
|
|
||||||
# Snippets
|
|
||||||
vim-vsnip
|
|
||||||
vim-vsnip-integ
|
|
||||||
friendly-snippets
|
|
||||||
# TODO luasnip seems to be in Lua and more integrated with Nix.
|
|
||||||
|
|
||||||
# Git
|
# Git
|
||||||
fugitive-gitlab-vim # Open files in GitLab
|
fugitive-gitlab-vim # Open files in GitLab
|
||||||
# TODO Connect it!
|
# TODO Connect it!
|
||||||
|
@ -291,7 +259,6 @@ in
|
||||||
|
|
||||||
" vim-gutentags
|
" vim-gutentags
|
||||||
let g:gutentags_cache_dir = expand('~/.cache/nvim/tags')
|
let g:gutentags_cache_dir = expand('~/.cache/nvim/tags')
|
||||||
|
|
||||||
'' + lib.optionalString config.frogeye.extra ''
|
'' + lib.optionalString config.frogeye.extra ''
|
||||||
" languagetool
|
" languagetool
|
||||||
let g:languagetool_cmd = "${pkgs.languagetool}/bin/languagetool-commandline"
|
let g:languagetool_cmd = "${pkgs.languagetool}/bin/languagetool-commandline"
|
||||||
|
@ -368,4 +335,8 @@ in
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
imports = [
|
||||||
|
./completion.nix
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue