Configure (n)vim with Ansible. Fully

This commit is contained in:
Geoffrey Frogeye 2021-07-03 14:13:25 +02:00
parent dd0e5a2189
commit 72e54fd8f7
Signed by: geoffrey
GPG key ID: C72403E7F82E6AD8
43 changed files with 355 additions and 378 deletions

View file

@ -0,0 +1,94 @@
" 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,list
set wildmenu
set showcmd
" 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

View file

@ -0,0 +1,22 @@
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

@ -0,0 +1,5 @@
if has('nvim')
source ~/.config/nvim/init.vim
else
source ~/.config/vim/init.vim
endif

View file

@ -1,8 +0,0 @@
set nocompatible
filetype on
set runtimepath+=~/.config/vim,~/.cache/vim
set viminfo+=n~/.cache/vim/viminfo
{% include 'plugins.j2' %}

View file

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

View file

@ -0,0 +1,13 @@
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

@ -2,8 +2,57 @@
{% set plugins.sources = plugins.sources + [(link, extra)] %}
{%- endmacro -%}
{% macro use_plugin(name) -%}
{% include 'plugins/' + name + '.j2' %}
" START PLUGIN CONFIG {{ name }}
{% include 'plugins/' + name + '.j2' +%}
" END PLUGIN CONFIG {{ name }}
{%- endmacro -%}
{{ use_plugin('ale') }}
" Theming
{{ use_plugin('base16') }}
{{ use_plugin('airline') }}
" Goto utilities
{{ use_plugin('fzf') }}
" Search/replace
{{ use_plugin('abolish') }}
" Sourounding pairs
{{ use_plugin('surround') }}
{{ use_plugin('targets') }}
" f/F mode
{{ use_plugin('shot_f') }}
{{ use_plugin('quick_scope') }}
" Tags
{{ use_plugin('gutentags') }}
{{ use_plugin('vista') }}
" Language Server Client
{{ use_plugin('vim_lsp') }}
" Auto-completion
{{ use_plugin('deoplete') }}
{{ use_plugin('supertab') }}
" Undo management
{{ use_plugin('undotree') }}
" Git helpers
{{ use_plugin('fugitive') }}
{{ use_plugin('gitgutter') }}
" Language-specific stuff
{{ use_plugin('tcomment') }}
{{ use_plugin('languagetool') }}
{{ use_plugin('pandoc') }}
{% if 'c' in dev_stuffs or 'c++' in dev_stuffs %}
{{ use_plugin('vebugger') }}
{% endif %}
{% if 'python' in dev_stuffs and variant == 'nvim' %}
{{ use_plugin('semshi') }}
{% endif %}
{% if 'ansible' in dev_stuffs %}
{{ use_plugin('ansible') }}
{% endif %}

View file

@ -1,21 +0,0 @@
" Auto-install vim-plug
if empty(glob('~/.cache/vim/autoload/plug.vim'))
silent !curl -fLo ~/.cache/vim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
{% set plugins = namespace(sources=[]) %}
{% import 'pluginlist.j2' as pluginlist with context %}
call plug#begin('~/.cache/vim/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()
{% include 'pluginlist.j2' %}

View file

@ -0,0 +1,2 @@
{# Regex for words, with case in mind #}
{{ add_source('tpope/tpope-vim-abolish') -}}

View file

@ -0,0 +1,14 @@
{{ add_source('vim-airline/vim-airline') -}}
{{ add_source('vim-airline/vim-airline-themes') -}}
set noshowmode
set laststatus=2
let g:airline_powerline_fonts = 1
let g:airline#extensions#tabline#enabled = 1
let g:airline_section_a = airline#section#create(['mode'])
let g:airline_section_b = airline#section#create(['branch', 'hunks'])
" let g:airline_section_z = airline#section#create(['%B', '@', '%l', ':', '%c'])
let g:airline_theme = 'base16_monokai'
let airline#extensions#languageclient#error_symbol = '✖ '
let airline#extensions#languageclient#warning_symbol = '⚠ '

View file

@ -1,3 +1,5 @@
" Asynchronous Lint Engine
" LSP client for vim and nvim
{{ add_source('dense-analysis/ale') }}
nmap <F3> :ALEFix<CR>
@ -6,4 +8,3 @@ 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']
let g:ale_php_phpcs_standard = '/srv/http/machines/ruleset.xml'

View file

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

View file

@ -0,0 +1,14 @@
{{ 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

@ -0,0 +1,8 @@
{{ add_source('chriskempson/base16-vim') -}}
colorscheme base16-default-dark
" let base16colorspace=256
" set termguicolors
" Some terminals requires a combination of the previous
" (the last one being setting the colorscheme to the exact theme in use),
" but it's a mess so I let you to figure out which one needs which

View file

@ -1 +1,26 @@
{{ add_source('Shougo/deoplete.nvim', {'do': ':UpdateRemotePlugins'}) }}
{# 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

@ -0,0 +1,4 @@
{# Aligning lines around a certain character #}
{{ add_source('junegunn/vim-easy-align') -}}
" Align GitHub-flavored Markdown tables
au FileType markdown vmap <Bar> :EasyAlign*<Bar><Enter>

View file

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

View file

@ -0,0 +1,36 @@
{# Fuzzy matching for all kind of stuff #}
{{ add_source('junegunn/fzf', {'do': './install --bin'}) }}
{{ add_source('junegunn/fzf.vim') -}}
let g:fzf_layout = { 'down': '~40%' }
let g:fzf_colors =
\ { 'fg': ['fg', 'Normal'],
\ 'bg': ['bg', 'Normal'],
\ 'hl': ['fg', 'Comment'],
\ 'fg+': ['fg', 'CursorLine', 'CursorColumn', 'Normal'],
\ 'bg+': ['bg', 'CursorLine', 'CursorColumn'],
\ 'hl+': ['fg', 'Statement'],
\ 'info': ['fg', 'PreProc'],
\ 'border': ['fg', 'Ignore'],
\ 'prompt': ['fg', 'Conditional'],
\ 'pointer': ['fg', 'Exception'],
\ 'marker': ['fg', 'Keyword'],
\ 'spinner': ['fg', 'Label'],
\ 'header': ['fg', 'Comment'] }
let g:fzf_command_prefix = 'Fzf'
nmap gF :FzfFiles<CR>
nmap gf :FzfGFiles<CR>
nmap gb :FzfBuffers<CR>
nmap gL :FzfLines<CR>
nmap gl :FzfBLines<CR>
nmap gT :FzfTags<CR>
nmap gt :FzfBTags<CR>
nmap gm :FzfMarks<CR>
nmap gw :FzfWindows<CR>
nmap gh :FzfHistory<CR>
nmap gH :FzfHistory:<CR>
nmap gS :FzfHistory/<CR>
nmap gs :FzfSnippets<CR>
" TODO `gd` → go to tag matching selected word, or show a list with that
" of tags pre-filtered with that word

View file

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

View file

@ -0,0 +1,3 @@
{# Generate tags #}
{{ add_source('ludovicchabant/vim-gutentags') -}}
let g:gutentags_cache_dir = expand('~/.cache/{{ variant }}/tags')

View file

@ -0,0 +1,20 @@
{{ 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

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

View file

@ -0,0 +1,6 @@
{# 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

@ -0,0 +1,2 @@
{# Auto-highlight one character per word for quick f/F movement #}
{{ add_source('unblevable/quick-scope') -}}

View file

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

View file

@ -0,0 +1,2 @@
{# When in f/F/t/T mode, highlight in red the characters that can be jumped to #}
{{ add_source('deris/vim-shot-f') -}}

View file

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

View file

@ -0,0 +1,4 @@
{# Use TAB for autocompletion #}
{{ add_source('ervandew/supertab') -}}
let g:SuperTabDefaultCompletionType = "<c-n>" " Go down when completing
let g:SuperTabContextDefaultCompletionType = "<c-n>"

View file

@ -0,0 +1,2 @@
{# Change surroundings pairs (e.g. brackets, quotes… #}
{{ add_source('tpope/vim-surround') -}}

View file

@ -0,0 +1,2 @@
{# Better interaction with surrounding pairs #}
{{ add_source('wellle/targets.vim') -}}

View file

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

View file

@ -0,0 +1,2 @@
{{ add_source('mbbill/undotree') -}}
nmap <F7> :UndotreeToggle<CR>

View file

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

View file

@ -0,0 +1,23 @@
{# LSP client for Vim8 and neovim #}
{{ add_source('prabirshrestha/vim-lsp') -}}
{{ add_source('mattn/vim-lsp-settings') -}}
" (providers are automatically detected thanks to vim-lsp-settings.
" You can even install some locally using :LspInstallServer)
nnoremap gd :LspDefinition<CR>
nnoremap gD :LspDeclaration<CR>
nnoremap <F3> :LspDocumentFormat<CR>
vnoremap <F3> :LspDocumentRangeFormat<CR>
nnoremap gE :LspNextDiagnostic<CR>
nnoremap ge :LspNextError<CR>
nnoremap <F2> :LspRename<CR>
let g:lsp_signs_enabled = 1
let g:lsp_diagnostics_echo_cursor = 1
let g:lsp_signs_error = {'text': '✗'}
let g:lsp_signs_warning = {'text': '‼'}
let g:lsp_signs_information = {'text': ''}
let g:lsp_signs_hint = {'text': '?'}
let g:lsp_highlight_references_enabled = 1

View file

@ -0,0 +1,12 @@
{# Tag bar #}
{{ add_source('liuchengxu/vista.vim') -}}
nmap <F8> :Vista!!<CR>
let g:vista_icon_indent = ["▸ ", ""]
let g:vista#renderer#enable_icon = 0
" 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",
\ }