401 lines
11 KiB
VimL
401 lines
11 KiB
VimL
set nocompatible
|
|
filetype off
|
|
|
|
if ((!filereadable(stdpath('config') . "/.shared_config")) || (exists('$SUDO_USER') && $SUDO_USER == 'fabian'))
|
|
let shared_config = 0
|
|
else
|
|
let shared_config = 1
|
|
echo "Using shared config."
|
|
endif
|
|
|
|
" Plugins
|
|
" Note: on most systems, this will make the plugins reside in \
|
|
" ~/.local/share/nvim/plugged/
|
|
let data_dir = has('nvim') ? stdpath('data') . '/site' : '~/.vim'
|
|
if empty(glob(data_dir . '/autoload/plug.vim'))
|
|
silent execute '!curl -fLo '.data_dir.'/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
|
|
let &runtimepath = &runtimepath
|
|
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
|
|
endif
|
|
call plug#begin()
|
|
|
|
" Powerline replacement
|
|
Plug 'vim-airline/vim-airline'
|
|
Plug 'vim-airline/vim-airline-themes'
|
|
|
|
" Tags
|
|
Plug 'xolox/vim-misc'
|
|
"Plugin 'ludovicchabant/vim-gutentags'
|
|
Plug 'majutsushi/tagbar'
|
|
|
|
" Templates
|
|
Plug 'aperezdc/vim-template'
|
|
|
|
" Selection expand
|
|
Plug 'terryma/vim-expand-region'
|
|
Plug 'kana/vim-textobj-user'
|
|
Plug 'kana/vim-textobj-line'
|
|
Plug 'kana/vim-submode'
|
|
|
|
" Better Pasting
|
|
Plug 'ConradIrwin/vim-bracketed-paste'
|
|
|
|
" Tmux navigation
|
|
Plug 'christoomey/vim-tmux-navigator'
|
|
|
|
" Git
|
|
Plug 'tpope/vim-fugitive'
|
|
|
|
" Comments
|
|
Plug 'scrooloose/nerdcommenter'
|
|
|
|
" Surround
|
|
Plug 'tpope/vim-surround'
|
|
|
|
" Snippets
|
|
" Track the engine.
|
|
Plug 'SirVer/ultisnips'
|
|
" Snippets are separated from the engine. Add this if you want them:
|
|
Plug 'honza/vim-snippets'
|
|
Plug 'ervandew/supertab'
|
|
|
|
" Highlight matching xml tags
|
|
Plug 'Valloric/MatchTagAlways'
|
|
|
|
"Javascript
|
|
Plug 'pangloss/vim-javascript'
|
|
|
|
" Tex
|
|
Plug 'lervag/vimtex'
|
|
|
|
"Go
|
|
Plug 'fatih/vim-go'
|
|
|
|
call plug#end()
|
|
|
|
" Check for plugin updates after the editor is responsive.
|
|
lua << EOF
|
|
local function check_plugin_updates()
|
|
local plugins = {}
|
|
for name, plugin in pairs(vim.g.plugs or {}) do
|
|
if vim.fn.isdirectory(plugin.dir) == 1 then
|
|
table.insert(plugins, { name = name, dir = plugin.dir })
|
|
end
|
|
end
|
|
table.sort(plugins, function(a, b) return a.name < b.name end)
|
|
|
|
local next_plugin = 1
|
|
local active = 0
|
|
local finished = 0
|
|
local failures = 0
|
|
local updates = {}
|
|
local concurrency = 2
|
|
|
|
local function git_command(args)
|
|
local command = { 'ionice', '-c', '3', 'nice', '-n', '10', 'git' }
|
|
vim.list_extend(command, args)
|
|
return command
|
|
end
|
|
|
|
local function set_airline_status(message)
|
|
vim.g.plugin_update_status = message
|
|
local marker = '%{get(g:,"plugin_update_status","")}'
|
|
local warning = vim.g.airline_section_warning or ''
|
|
if not string.find(warning, 'plugin_update_status', 1, true) then
|
|
vim.g.airline_section_warning = warning .. ' ' .. marker
|
|
end
|
|
if vim.fn.exists(':AirlineRefresh') == 2 then
|
|
vim.cmd('AirlineRefresh')
|
|
end
|
|
end
|
|
|
|
local function report()
|
|
if #updates > 0 then
|
|
set_airline_status(string.format('[updates: %d]', #updates))
|
|
local message = string.format(
|
|
'%d plugin update%s available: %s',
|
|
#updates,
|
|
#updates == 1 and '' or 's',
|
|
table.concat(updates, ', ')
|
|
)
|
|
if failures > 0 then
|
|
message = message .. string.format(' (%d check%s failed)', failures, failures == 1 and '' or 's')
|
|
end
|
|
vim.notify(message, failures > 0 and vim.log.levels.WARN or vim.log.levels.INFO)
|
|
elseif failures > 0 then
|
|
set_airline_status('[update check failed]')
|
|
vim.notify(
|
|
string.format('Plugin update check incomplete: %d check%s failed', failures, failures == 1 and '' or 's'),
|
|
vim.log.levels.WARN
|
|
)
|
|
else
|
|
set_airline_status('')
|
|
vim.notify('All plugins up-to-date', vim.log.levels.INFO)
|
|
end
|
|
end
|
|
|
|
local pump
|
|
local function complete_one()
|
|
active = active - 1
|
|
finished = finished + 1
|
|
if finished == #plugins then
|
|
report()
|
|
else
|
|
pump()
|
|
end
|
|
end
|
|
|
|
local function check_one(plugin)
|
|
active = active + 1
|
|
vim.system(
|
|
git_command({ '-C', plugin.dir, 'fetch', '--quiet', '--no-tags', 'origin' }),
|
|
{ text = true, timeout = 20000 },
|
|
vim.schedule_wrap(function(fetch_result)
|
|
if fetch_result.code ~= 0 then
|
|
failures = failures + 1
|
|
complete_one()
|
|
return
|
|
end
|
|
|
|
vim.system(
|
|
git_command({ '-C', plugin.dir, 'rev-list', '--count', 'HEAD..@{upstream}' }),
|
|
{ text = true, timeout = 5000 },
|
|
vim.schedule_wrap(function(count_result)
|
|
local count = tonumber(vim.trim(count_result.stdout or ''))
|
|
if count_result.code ~= 0 or count == nil then
|
|
failures = failures + 1
|
|
elseif count > 0 then
|
|
table.insert(updates, plugin.name)
|
|
end
|
|
complete_one()
|
|
end)
|
|
)
|
|
end)
|
|
)
|
|
end
|
|
|
|
pump = function()
|
|
while active < concurrency and next_plugin <= #plugins do
|
|
local plugin = plugins[next_plugin]
|
|
next_plugin = next_plugin + 1
|
|
check_one(plugin)
|
|
end
|
|
end
|
|
|
|
if #plugins > 0 then
|
|
pump()
|
|
end
|
|
end
|
|
|
|
vim.api.nvim_create_autocmd('VimEnter', {
|
|
group = vim.api.nvim_create_augroup('plugin_update_check', { clear = true }),
|
|
once = true,
|
|
callback = function()
|
|
vim.defer_fn(check_plugin_updates, 1500)
|
|
end,
|
|
})
|
|
EOF
|
|
|
|
" Run PlugInstall if there are missing plugins
|
|
autocmd VimEnter * if len(filter(values(g:plugs), '!isdirectory(v:val.dir)'))
|
|
\| PlugInstall --sync | source $MYVIMRC
|
|
\| endif
|
|
|
|
|
|
filetype plugin indent on
|
|
set cinkeys-=0#
|
|
|
|
" Terminal emulator settings
|
|
set t_Co=256
|
|
"set term=screen-256color
|
|
|
|
" Color configuration
|
|
try
|
|
source ~/.config/nvim/scheme.vim
|
|
catch
|
|
" Ignore non existing file
|
|
endtry
|
|
syntax enable " enable syntax processing
|
|
|
|
" Disable annoying bell
|
|
set noerrorbells
|
|
|
|
" Allow modelines at the beginning and end of a file
|
|
set modeline
|
|
|
|
" Key configuration
|
|
let mapleader = "\<Space>" " Make space the leader key
|
|
nnoremap <Leader>w :w<CR>| " Write file
|
|
nnoremap <Leader>q :q<CR>| " Close file
|
|
nnoremap <Leader>s :w !sudo tee %<CR>L<CR>
|
|
ca w!! w !sudo tee "%"
|
|
|
|
nmap <Leader><Leader> V| " Change to visual line mode
|
|
map q: :q| " No command history
|
|
nmap <Leader><CR> O<ESC> | " Add line above
|
|
nmap <CR> o<ESC>| " Add line below
|
|
nmap <Leader>f gq}| " Format paragraph
|
|
" Window management
|
|
nmap <Leader>mt :tab sp<CR> | " maximize window to new tab
|
|
nmap <Leader>. <C-w>= | " Split windows equally
|
|
map gb :bnext<CR>
|
|
map gB :bNext<CR>
|
|
call submode#enter_with('grow/shrink', 'n', '', '<Leader>r', '<Nop>')
|
|
call submode#map('grow/shrink', 'n', '', '+', '<C-w>+')
|
|
call submode#map('grow/shrink', 'n', '', '-', '<C-w>-')
|
|
call submode#map('grow/shrink', 'n', '', '<', '<C-w><')
|
|
call submode#map('grow/shrink', 'n', '', '>', '<C-w>>')
|
|
set splitbelow
|
|
set splitright
|
|
|
|
" Delete without copying
|
|
nnoremap <leader>d "_d
|
|
xnoremap <leader>d "_d
|
|
nnoremap <leader>x "_x
|
|
xnoremap <leader>x "_x
|
|
xnoremap <leader>p "_dP
|
|
|
|
"disable submode timeouts:
|
|
let g:submode_timeout = 0
|
|
" don't consume submode-leaving key
|
|
let g:submode_keep_leaving_key = 1
|
|
|
|
" Configuration of spaces and tabs
|
|
set tabstop=4 " show 4 spaces per TAB
|
|
set softtabstop=4 " insert 4 spaces per TAB
|
|
set smarttab
|
|
set expandtab " tabs are spaces
|
|
set shiftwidth=4
|
|
|
|
" UI
|
|
set number " show line numbers
|
|
set relativenumber "relative line numbers
|
|
set showcmd " show last command in bottom bar
|
|
set cursorline " highlight current line
|
|
|
|
" Statusline
|
|
set statusline+=%f\ " show Filepath
|
|
set statusline+=[%{strlen(&fenc)?&fenc:'none'}] "file encoding
|
|
set statusline+=%m%r " Modified and read only flag
|
|
set statusline+=%= " align left
|
|
set statusline+=%y " show Filetype
|
|
set statusline+=[%{&fo}] " Show format options
|
|
set laststatus=2 " always show statusline
|
|
|
|
" Filetypes
|
|
filetype on " filetype detection on
|
|
filetype indent on " filetype-specific indent .vim/indent/
|
|
filetype plugin on " filteype plugins in .vim/ftplugins
|
|
|
|
set smartindent
|
|
set wildmenu " visual autocomplete for command menu
|
|
set lazyredraw " redraw only when necessary
|
|
set showmatch " highlight matching brackets
|
|
set mouse=a " Mouse control
|
|
|
|
" Searching
|
|
set incsearch " search while entering
|
|
set hlsearch " highlight matches
|
|
nnoremap <Leader>h :set hlsearch!<CR>
|
|
set ignorecase
|
|
set smartcase
|
|
|
|
" Line wrapping
|
|
set tw=100 " set textwidth of 100 characters
|
|
set formatoptions-=t " Don't wrap code
|
|
set formatoptions+=c " Wrap comments
|
|
set formatoptions+=mB " Don't break multibyte characters
|
|
set formatoptions+=j " Remove multiple comment markers
|
|
function TextWrapToggle()
|
|
if &fo =~'t'
|
|
setlocal fo-=t
|
|
else
|
|
setlocal fo+=t
|
|
endif
|
|
let formatoptions = &formatoptions
|
|
echom formatoptions
|
|
endfunction
|
|
nmap <Leader>t :call TextWrapToggle()<CR>
|
|
|
|
" Highlight characters past 80
|
|
"augroup vimrc_autocmds
|
|
"autocmd BufEnter * highlight OverLength ctermbg=88 guibg=#592929
|
|
"autocmd BufEnter * match OverLength /\%81v.*/
|
|
"augroup END
|
|
|
|
"Copying
|
|
if ((!shared_config) && (exists('$LC_OSC52') && $LC_OSC52 == '1'))
|
|
lua << EOF
|
|
vim.g.clipboard = 'osc52'
|
|
EOF
|
|
endif
|
|
set clipboard=unnamedplus,unnamed " Copy/Paste
|
|
|
|
" Airline
|
|
let g:airline_powerline_fonts = 1
|
|
|
|
" TagBar
|
|
nmap <F8> :TagbarToggle<CR>
|
|
imap <F8> <ESC>:TagbarToggle<CR>gi
|
|
nmap <C-]> <C-w><C-]><C-w>T
|
|
|
|
"Tags
|
|
let g:easytags_async = 1
|
|
|
|
" make
|
|
set switchbuf=split
|
|
|
|
" vim-templates config-file
|
|
try
|
|
source ~/.config/nvim/.vimrc_config_template
|
|
catch
|
|
" Ignore non existing file
|
|
endtry
|
|
|
|
" Expand region
|
|
vmap v <Plug>(expand_region_expand)
|
|
vmap <C-v> <Plug>(expand_region_shrink)
|
|
|
|
" Snippets
|
|
let g:SuperTabDefaultCompletionType = '<C-n>'
|
|
let g:SuperTabCrMapping = 0
|
|
|
|
let g:UltiSnipsExpandTrigger="<tab>"
|
|
let g:UltiSnipsJumpForwardTrigger="<tab>"
|
|
let g:UltiSnipsJumpBackwardTrigger="<s-tab>"
|
|
let g:UltiSnipsEditSplit="vertical"
|
|
set rtp+=~/.config/nvim/my-snippets
|
|
|
|
" Folding
|
|
set foldmethod=syntax
|
|
set foldlevel=100
|
|
" Use F9 to toggle folding
|
|
inoremap <F9> <C-O>za
|
|
nnoremap <F9> za
|
|
onoremap <F9> <C-C>za
|
|
vnoremap <F9> zf
|
|
nnoremap <Leader>a za
|
|
onoremap <Leader>a <C-C>za
|
|
vnoremap <Leader>a zf
|
|
|
|
try
|
|
source ~/.config/nvim/.vimrc_config_expand_region
|
|
catch
|
|
" Ignore non existing file
|
|
endtry
|
|
|
|
" Extra stuff
|
|
try
|
|
source ~/.config/nvim/.vimrc_config_extra_stuff
|
|
catch
|
|
" Ignore non existing file
|
|
endtry
|
|
let g:tex_flavor = "latex"
|
|
autocmd FileType yaml setlocal ts=2 sts=2 sw=2 expandtab
|
|
|
|
if filereadable(expand("~/python-envs/neovim/bin/python3"))
|
|
let g:python3_host_prog="~/python-envs/neovim/bin/python3"
|
|
else
|
|
let g:python3_host_prog="/usr/bin/python3"
|
|
endif
|