Compare commits

...

5 commits

Author SHA1 Message Date
Geoffrey Frogeye 942dff9d8c
nix: Vim: done 2023-11-02 17:06:46 +01:00
Geoffrey Frogeye 7f71eec03c
nix: Editor config
Should have started there I guess.
2023-11-02 17:04:53 +01:00
Geoffrey Frogeye 3d9dc4a4bf
nix: vim: plugins cleanup 2023-11-02 15:46:23 +01:00
Geoffrey Frogeye d811d025e6
nix: Finish adding vim plugins 2023-11-02 15:42:17 +01:00
Geoffrey Frogeye 9b450cc22f
nix: vim: Snippets and auto-completion 2023-11-01 18:03:14 +01:00
35 changed files with 134 additions and 409 deletions

View file

@ -9,8 +9,6 @@
when: root_access
- role: dotfiles
tags: dotfiles
- role: vim
tags: vim
- role: mnussbaum.base16-builder-ansible # Required for desktop_environment
tags:
- color

View file

@ -1,11 +0,0 @@
- name: Upgrade Neovim plugins
command: "nvim +PlugUpgrade +PlugUpdate +PlugInstall +qall!"
listen: nvim plugins changed
environment:
VIMINIT: "source {{ ansible_user_dir }}/.config/nvim/plugininstall.vim"
- name: Upgrade Vim plugins
command: "vim +PlugUpgrade +PlugUpdate +PlugInstall +qall!"
listen: vim plugins changed
environment:
VIMINIT: "source {{ ansible_user_dir }}/.config/vim/plugininstall.vim"

View file

@ -1,20 +0,0 @@
- name: Configure vim plugin list
template:
src: plugininstall.j2
dest: "{{ ansible_user_dir }}/.config/{{ variant }}/plugininstall.vim"
mode: "u=rw,g=r,o=r"
notify:
- "{{ variant }} plugins changed"
loop: "{{ vim_variants }}"
loop_control:
loop_var: variant
- name: Configure vim
template:
src: init.vim.j2
dest: "{{ ansible_user_dir }}/.config/{{ variant }}/init.vim"
mode: "u=rw,g=r,o=r"
loop: "{{ vim_variants }}"
loop_control:
loop_var: variant

View file

@ -1,101 +0,0 @@
" From https://www.hillelwayne.com/post/intermediate-vim/
set encoding=utf-8
set title
set number
set ruler
set wrap
set scrolloff=10
set ignorecase
set smartcase
set gdefault
if has('nvim')
set inccommand=nosplit " Shows you in realtime what changes your ex command should make.
endif
set incsearch
set hlsearch
set tabstop=4
set shiftwidth=4
set expandtab
set visualbell
set noerrorbells
set backspace=indent,eol,start
set hidden
set updatetime=250
set lazyredraw " Do not redraw screen in the middle of a macro. Makes them complete faster.
set cursorcolumn
set splitbelow
" Turn off relativenumber only for insert mode.
if has('nvim')
set relativenumber
augroup every
autocmd!
au InsertEnter * set norelativenumber
au InsertLeave * set relativenumber
augroup END
endif
" Keep undo history across sessions by storing it in a file
if has('persistent_undo')
let myUndoDir = expand(vimDir . '/undodir')
" Create dirs
call system('mkdir ' . myUndoDir)
let &undodir = myUndoDir
set undofile
endif
syntax enable
" From http://stackoverflow.com/a/5004785/2766106
set list
set listchars=tab:╾╌,trail:·,extends:↦,precedes:↤,nbsp:_
set showbreak=↪
filetype on
filetype plugin on
filetype indent on
set wildmode=longest:full,full
set wildmenu
set showcmd
" Completion
" Avoid showing message extra message when using completion
set shortmess+=c
" Close the file explorer once you select a file
let g:netrw_fastbrowse = 0
" Allow saving of files as sudo when I forgot to start vim using sudo.
" From https://stackoverflow.com/a/7078429
cmap w!! w !sudo tee > /dev/null %
imap jk <Esc>
vmap <Enter> <Esc>
nmap <Enter> o<Esc>
nmap <C-H> :bp<CR>
nmap <C-L> :bn<CR>
nmap <C-K> kkkkkkkkkkkkkkkkkkkkk
nmap <C-J> jjjjjjjjjjjjjjjjjjjjj
" \s to replace globally the word under the cursor
nnoremap <Leader>s :%s/\<<C-r><C-w>\>/
" add extensions to syntax
au BufNewFile,BufRead *.jinja set filetype=jinja2
command Reload source $MYVIMRC

View file

@ -1,23 +0,0 @@
set nocompatible
filetype on
" SET PATHS
set runtimepath+=~/.config/{{ variant }}
let vimDir = '$HOME/.cache/{{ variant }}'
call system('mkdir ' . vimDir)
let &runtimepath.=','.vimDir
set viminfo+=n~/.cache/{{ variant }}/viminfo
" PLUGIN INSTALLATION
source ~/.config/{{ variant }}/plugininstall.vim
" EDITOR CONFIGURATION
{% include 'editor.j2' %}
" PLUGINS CONFIGURATION
{% include 'pluginconfig.j2' %}

View file

@ -1,2 +0,0 @@
{% set plugins = namespace(sources=[]) %}
{% include 'pluginlist.j2' %}

View file

@ -1,13 +0,0 @@
source ~/.config/vim/plug.vim
{% set plugins = namespace(sources=[]) %}
{% import 'pluginlist.j2' as pluginlist with context %}
call plug#begin('~/.cache/{{ variant }}/plugged')
{% for link, extra in plugins.sources %}
{% if extra %}
Plug '{{ link }}', { {% for k, v in extra.items() %}'{{ k }}': '{{ v }}', {% endfor %} }
{% else %}
Plug '{{ link }}'
{% endif %}
{% endfor %}
call plug#end()

View file

@ -1,55 +0,0 @@
{% macro add_source(link, extra={}) -%}
{% set plugins.sources = plugins.sources + [(link, extra)] %}
{%- endmacro -%}
{% macro use_plugin(name) -%}
" START PLUGIN CONFIG {{ name }}
{% include 'plugins/' + name + '.j2' +%}
" END PLUGIN CONFIG {{ name }}
{%- endmacro -%}
" Visuals
{{ use_plugin('devicons') }}
{% if variant == 'nvim' %}
{{ use_plugin('specs') }}
{% endif %}
" Theme
source ~/.config/vim/theme.vim
" Snippets
{{ use_plugin('vsnip') }}
" Auto-completion
{% if variant == 'nvim' %}
{{ use_plugin('nvim_compe') }}
{% else %}
{{ use_plugin('deoplete') }}
{{ use_plugin('supertab') }}
{% endif %}
" Undo management
{{ use_plugin('undotree') }}
" Git helpers
{{ use_plugin('fugitive') }}
{% if variant == 'nvim' %}
{{ use_plugin('gitsigns') }}
{% else %}
{{ use_plugin('gitgutter') }}
{% endif %}
" Language-specific stuff
{{ use_plugin('tcomment') }}
{{ use_plugin('languagetool') }}
{{ use_plugin('pandoc') }}
{% if variant == 'nvim' %}
{{ use_plugin('dap') }}
{{ use_plugin('colorizer') }}
{% else %}
{% if 'c' in dev_stuffs or 'c++' in dev_stuffs %}
{{ use_plugin('vebugger') }}
{% endif %}
{% endif %}
{% if 'ansible' in dev_stuffs %}
{{ use_plugin('ansible') }}
{% endif %}

View file

@ -1,10 +0,0 @@
" Asynchronous Lint Engine
" LSP client for vim and nvim
{{ add_source('dense-analysis/ale') }}
nmap <F3> :ALEFix<CR>
let g:ale_sign_error = '×'
let g:ale_sign_warning = '!'
let g:ale_completion_enabled = 1
let g:ale_fixers = ['autopep8', 'shfmt', 'uncrustify', 'remove_trailing_lines', 'trim_whitespace', 'phpcbf']

View file

@ -1,2 +0,0 @@
{# Various for Ansible #}
{{ add_source('pearofducks/ansible-vim', { 'do': './UltiSnips/generate.sh'}) -}}

View file

@ -1,14 +0,0 @@
{{ add_source('prabirshrestha/asyncomplete.vim') -}}
let g:asyncomplete_auto_popup = 1
inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
inoremap <expr> <cr> pumvisible() ? "\<C-y>" : "\<cr>"
imap <c-space> <Plug>(asyncomplete_force_refresh)
{{ add_source('prabirshrestha/asyncomplete-file.vim') -}}
au User asyncomplete_setup call asyncomplete#register_source(asyncomplete#sources#file#get_source_options({
\ 'name': 'file',
\ 'whitelist': ['*'],
\ 'priority': 10,
\ 'completor': function('asyncomplete#sources#file#completor')
\ }))

View file

@ -1,7 +0,0 @@
{# Display the actual color for color codes " #}
{{ add_source('norcalli/nvim-colorizer.lua') -}}
set termguicolors
lua << EOF
require'colorizer'.setup()
EOF
{# TODO Enable for css functions too #}

View file

@ -1,2 +0,0 @@
{# Debug Adapter Protocol client #}
{{ add_source('mfussenegger/nvim-dap') -}}

View file

@ -1,26 +0,0 @@
{# Auto-completion for vim and nvim #}
{% if variant == 'nvim' -%}
{{ add_source('Shougo/deoplete.nvim', {'do': ':UpdateRemotePlugins'}) -}}
{% else -%}
{{ add_source('Shougo/deoplete.nvim') -}}
{{ add_source('roxma/nvim-yarp') -}}
{{ add_source('roxma/vim-hug-neovim-rpc') -}}
{% endif -%}
{% raw %}
let g:deoplete#enable_at_startup = 1
inoremap <silent><expr> <TAB>
\ pumvisible() ? "\<C-n>" :
\ <SID>check_back_space() ? "\<TAB>" :
\ deoplete#manual_complete()
function! s:check_back_space() abort "{{{
let col = col('.') - 1
return !col || getline('.')[col - 1] =~ '\s'
endfunction"}}}
{% endraw %}
" suggested by ssemshi to make it not too slow
" let g:deoplete#auto_complete_delay = 100
call deoplete#custom#option({
\ 'auto_complete_delay': 100,
\ 'smart_case': v:true,
\ })

View file

@ -1,5 +0,0 @@
{% if variant == 'nvim' %}
{{ add_source('kyazdani42/nvim-web-devicons') -}}
{% else %}
{{ add_source('ryanoasis/vim-devicons') -}}
{% endif %}

View file

@ -1,4 +0,0 @@
{# Git basics #}
{{ add_source('tpope/vim-fugitive') -}}
{# Open files in GitLab #}
{{ add_source('shumphrey/fugitive-gitlab.vim') -}}

View file

@ -1,2 +0,0 @@
{# Show changed git lines in the gutter #}
{{ add_source('airblade/vim-gitgutter') -}}

View file

@ -1,7 +0,0 @@
{# Show changed git lines in the gutter #}
{{ add_source('lewis6991/gitsigns.nvim') -}}
{# Dependency #}
{{ add_source('nvim-lua/plenary.nvim') -}}
lua << EOF
require('gitsigns').setup()
EOF

View file

@ -1,20 +0,0 @@
{{ add_source('autozimu/LanguageClient-neovim', { 'branch': 'next', 'do': 'bash install.sh'}) -}}
let g:LanguageClient_serverCommands = {
\ 'python': ['pyls'],
\ 'sh': ['bash-language-server', 'start'],
\ }
let g:LanguageClient_loggingFile = expand('~/.cache/{{ variant }}/LanguageClient.log')
function LC_maps()
if has_key(g:LanguageClient_serverCommands, &filetype)
nnoremap <buffer> <silent> K :call LanguageClient#textDocument_hover()<cr>
nnoremap <buffer> <silent> gd :call LanguageClient#textDocument_definition()<CR>
nnoremap <buffer> <silent> gD :call LanguageClient#textDocument_references()<CR>
nnoremap <buffer> <silent> <F2> :call LanguageClient#textDocument_rename()<CR>
nnoremap <buffer> <silent> <F3> :call LanguageClient#textDocument_formatting()<CR>
set completefunc=LanguageClient#complete
set omnifunc=LanguageClient#complete
endif
endfunction
autocmd FileType * call LC_maps()

View file

@ -1,3 +0,0 @@
{# Check grammar for human languages #}
{{ add_source('dpelle/vim-LanguageTool') -}}
let g:languagetool_jar = "/usr/share/java/languagetool/languagetool-commandline.jar"

View file

@ -1,6 +0,0 @@
{# Pandoc specific stuff because there's no LSP for it #}
{{ add_source('vim-pandoc/vim-pandoc') -}}
{{ add_source('vim-pandoc/vim-pandoc-syntax') -}}
let g:pandoc#modules#disabled = ["folding"]
let g:pandoc#spell#enabled = 0
let g:pandoc#syntax#conceal#use = 0

View file

@ -1,4 +0,0 @@
{# Live reload #}
{{ add_source('famiu/nvim-reload') -}}
{{ add_source('nvim-lua/plenary.nvim') -}}
{# Not used, this breaks color, and source $MYVIMRC is all that we need to reload colorscheme #}

View file

@ -1,2 +0,0 @@
{# Semantic highlighting for Python for neovim #}
{{ add_source('numirias/semshi', {'do': ':UpdateRemotePlugins'}) -}}

View file

@ -1,6 +0,0 @@
{# Dim inactive windows #}
{# Not working very well, at least with undotree #}
{{add_source('sunjon/shade.nvim')-}}
lua << EOF
require'shade'.setup()
EOF

View file

@ -1,2 +0,0 @@
{# Smoooooth scrolling #}
{{ add_source('terryma/vim-smooth-scroll') -}}

View file

@ -1,15 +0,0 @@
{# Flashes under the cursor when moving far #}
{{ add_source('edluffy/specs.nvim') -}}
lua << EOF
require('specs').setup{
popup = {
delay_ms = 0, -- delay before popup displays
inc_ms = 10, -- time increments used for fade/resize effects
blend = 10, -- starting blend, between 0-100 (fully transparent), see :h winblend
width = 10,
winhl = "PMenu",
fader = require('specs').pulse_fader,
resizer = require('specs').shrink_resizer
},
}
EOF

View file

@ -1,7 +0,0 @@
{# Use TAB for autocompletion #}
{{ add_source('ervandew/supertab') -}}
let g:SuperTabLongestEnhanced = 1
let g:SuperTabLongestHighlight = 1
{# TODO longest doesn't work, even when longest is set in completeopt #}
let g:SuperTabDefaultCompletionType = "<c-n>" " Go down when completing
let g:SuperTabContextDefaultCompletionType = "<c-n>"

View file

@ -1,2 +0,0 @@
{# Language-aware (un)commenting #}
{{ add_source('tomtom/tcomment_vim') -}}

View file

@ -1,3 +0,0 @@
{# Navigate undo #}
{{ add_source('mbbill/undotree') -}}
nmap <space>u :UndotreeToggle<CR>

View file

@ -1,2 +0,0 @@
{# Debug from the editor #}
{{ add_source('idanarye/vim-vebugger') -}}

View file

@ -1,12 +0,0 @@
{# Tag bar #}
{{ add_source('liuchengxu/vista.vim') -}}
nmap <space>s :Vista!!<CR>
let g:vista_icon_indent = ["▸ ", ""]
let g:vista#renderer#enable_icon = 1
" The default icons can't be suitable for all the filetypes, you can extend it as you wish.
let g:vista#renderer#icons = {
\ "function": "f",
\ "variable": "x",
\ }

View file

@ -1,4 +0,0 @@
{{ add_source('hrsh7th/vim-vsnip') -}}
{{ add_source('hrsh7th/vim-vsnip-integ') -}}
{{ add_source('rafamadriz/friendly-snippets') -}}
{# TODO Ansible snippets? #}

View file

@ -21,7 +21,7 @@
# FIXME Still want this despite using nixvim
gpg = {
enable = true;
homedir = "${config.xdg.dataHome}/gnupg";
homedir = "${config.xdg.stateHome}/gnupg";
settings = {
# Remove fluff
no-greeting = true;

View file

@ -34,6 +34,40 @@ in
programs.nixvim = {
enable = true;
options = {
# From https://www.hillelwayne.com/post/intermediate-vim/
title = true;
number = true;
relativenumber = true;
scrolloff = 10;
lazyredraw = true; # Do not redraw screen in the middle of a macro. Makes them complete faster.
cursorcolumn = true;
ignorecase = true;
smartcase = true;
gdefault = true;
tabstop = 4;
shiftwidth = 4;
expandtab = true;
splitbelow = true;
visualbell = true;
updatetime = 250;
undofile = true;
# From http://stackoverflow.com/a/5004785/2766106
list = true;
listchars = "tab:,trail:·,extends:,precedes:,nbsp:_";
showbreak = "";
wildmode = "longest:full,full";
wildmenu = true;
};
globals = {
netrw_fastbrowse = 0; # Close the file explorer once you select a file
};
colorschemes.base16 = {
# FIXME Dynamic... or use stylix
enable = true;
@ -46,6 +80,8 @@ in
specs = {
enable = true;
min_jump = 5;
fader = { builtin = "pulse_fader"; };
resizer = { builtin = "shrink_resizer"; };
};
# Tabline
@ -175,6 +211,16 @@ in
};
# TODO Investigate https://github.com/nvim-treesitter/nvim-treesitter-textobjects
indent-blankline.enable = true; # 23.11 integrate with rainbow-delimiters and use more of the options
undotree.enable = true; # Navigate edition history
# Git
fugitive.enable = true; # Git basics
gitsigns.enable = true; # Show changed lines in the gutter
# Language-specific
# dap.enable = true; # Debug Adapter Protocol client # 23.11
nvim-colorizer.enable = true; # Display colors of color-codes
};
extraPlugins = with pkgs.vimPlugins; [
nvim-scrollview # Scroll bar
@ -210,6 +256,27 @@ in
# Treesitter
nvim-ts-rainbow # Randomly color parenthesis pairs
# 23.11: Replace with plugins.rainbow-delimiters
# Snippets
vim-vsnip
vim-vsnip-integ
friendly-snippets
# Auto-completion
nvim-compe
# TODO Archived. Maybe use nvim-cmp and plugins instead?
# Git
fugitive-gitlab-vim # Open files in GitLab
# TODO Connect it!
# Language-specific
tcomment_vim # Language-aware (un)commenting
vim-LanguageTool # Check grammar for human languages
vim-pandoc # Pandoc-specific stuff because there's no LSP for it
vim-pandoc-syntax
nvim-dap # Debug Adapter Protocol client
ansible-vim # FIXME See if it doesn't require to do ./UltiSnips/generate.sh
];
extraConfigLua = lib.strings.concatMapStringsSep "\n" (f: builtins.readFile f) [
./vim/feline.lua
@ -218,16 +285,77 @@ in
./vim/nvim-ts-rainbow.lua
];
extraConfigVim = ''
" GENERAL
" Avoid showing message extra message when using completion
set shortmess+=c
command Reload source $MYVIMRC
" PLUGINS
" vim-gutentags
let g:gutentags_cache_dir = expand('~/.cache/nvim/tags')
" nvim-compe
" Copy-pasted because I couldn't be bothered
set completeopt=menuone,noselect
inoremap <silent><expr> <C-Space> compe#complete()
inoremap <silent><expr> <CR> compe#confirm('<CR>')
inoremap <silent><expr> <C-e> compe#close('<C-e>')
inoremap <silent><expr> <C-f> compe#scroll({ 'delta': +4 })
inoremap <silent><expr> <C-d> compe#scroll({ 'delta': -4 })
" languagetool
let g:languagetool_cmd = "${pkgs.languagetool}/bin/languagetool-commandline"
" TODO Doesn't work
" vim-pandox
let g:pandoc#modules#disabled = ["folding"]
let g:pandoc#spell#enabled = 0
let g:pandoc#syntax#conceal#use = 0
'';
autoCmd = [
# Turn off relativenumber only for insert mode
{ event = "InsertEnter *"; command = "set norelativenumber"; }
{ event = "InsertLeave *"; command = "set relativenumber"; }
# Additional extensions
{ event = "BufNewFile,BufRead"; pattern = "*.jinja"; command = "set filetype=jinja2"; } # TODO Probably GH-specific?
# vim-easy-align: Align Markdown tables
{ event = "FileType markdown"; command = "vmap <Bar> :EasyAlign*<Bar><Enter>"; }
];
userCommands = {
# Reload = { command = "source $MYVIRMC"; };
# TODO Is not working, options is set to nil even though it shouldn't
};
# 23.11: Use keymaps, seems better
maps = {
# GENERAL
# Allow saving of files as sudo when I forgot to start vim using sudo.
# From https://stackoverflow.com/a/7078429
command."w!!" = { action = "w !sudo tee > /dev/null %"; };
insert."jk" = { action = "<Esc>"; };
visual."<Enter>" = { action = "<Esc>"; };
normal."<Enter>" = { action = "o<Esc>"; };
# normal."<C-H>" = { action = ":bp<CR>"; };
# normal."<C-L>" = { action = ":bn<CR>"; };
normal."<C-K>" = { action = "kkkkkkkkkkkkkkkkkkkkk"; };
normal."<C-J>" = { action = "jjjjjjjjjjjjjjjjjjjjj"; };
# \s to replace globally the word under the cursor
normal."<Leader>s" = { action = ":%s/\\<<C-r><C-w>\\>/"; };
# PLUGINS
# barbar
normal."<C-H>" = { action = "<Cmd>BufferPrevious<CR>"; silent = true; };
normal."<C-L>" = { action = "<Cmd>BufferNext<CR>"; silent = true; };
@ -251,6 +379,9 @@ in
# symbols-outline-nvim
normal."<Space>s" = { action = "<Cmd>SymbolsOutline<CR>"; silent = true; };
# undotree
normal."<Space>u" = { action = "<Cmd>UndotreeToggle<CR>"; silent = true; };
};
};
}

View file

@ -1,7 +1,4 @@
{{ add_source('hrsh7th/nvim-compe') -}}
{# I'm a bit lost with all this, so this is the default recommended config,
using vim-vsnip because the proposed configuration for tab-completion uses it, so #}
lua << EOF
-- Default recommended config
require'compe'.setup {
enabled = true;
autocomplete = true;
@ -32,17 +29,9 @@ require'compe'.setup {
vsnip = true;
};
}
EOF
set completeopt=menuone,noselect
-- Vim instructions were here
inoremap <silent><expr> <C-Space> compe#complete()
inoremap <silent><expr> <CR> compe#confirm('<CR>')
inoremap <silent><expr> <C-e> compe#close('<C-e>')
inoremap <silent><expr> <C-f> compe#scroll({ 'delta': +4 })
inoremap <silent><expr> <C-d> compe#scroll({ 'delta': -4 })
lua << EOF
local t = function(str)
return vim.api.nvim_replace_termcodes(str, true, true, true)
end
@ -81,4 +70,3 @@ vim.api.nvim_set_keymap("i", "<Tab>", "v:lua.tab_complete()", {expr = true})
vim.api.nvim_set_keymap("s", "<Tab>", "v:lua.tab_complete()", {expr = true})
vim.api.nvim_set_keymap("i", "<S-Tab>", "v:lua.s_tab_complete()", {expr = true})
vim.api.nvim_set_keymap("s", "<S-Tab>", "v:lua.s_tab_complete()", {expr = true})
EOF