From 9b11f01dd2adf6d859dedbdf58026d017e07c609 Mon Sep 17 00:00:00 2001 From: waldek Date: Mon, 6 Sep 2021 07:30:45 +0200 Subject: [PATCH] init --- essentials.vimrc | 70 +++++++++++++++++++ main.vimrc | 12 ++++ systemd.vim | 49 ++++++++++++++ visual.vimrc | 23 +++++++ vundle_essentials.vimrc | 144 ++++++++++++++++++++++++++++++++++++++++ waldek_plugins.list | 15 +++++ waldek_plugins.vimrc | 128 +++++++++++++++++++++++++++++++++++ 7 files changed, 441 insertions(+) create mode 100644 essentials.vimrc create mode 100644 main.vimrc create mode 100644 systemd.vim create mode 100644 visual.vimrc create mode 100644 vundle_essentials.vimrc create mode 100644 waldek_plugins.list create mode 100644 waldek_plugins.vimrc diff --git a/essentials.vimrc b/essentials.vimrc new file mode 100644 index 0000000..098a988 --- /dev/null +++ b/essentials.vimrc @@ -0,0 +1,70 @@ +" ---------------------------------------------------------------------------- +" basic essentials +" ---------------------------------------------------------------------------- + +" don't make vim vi compatible (if not set you miss out on a lot of features!) +" you'll see this option set in most configuration files found online +set nocompatible + +" enable filetype recognition plus indent and plugin (pretty much mandatory) +filetype plugin indent on " required + +" enable syntax highlighting +syntax on + +" backspace can be a tricky thing and this setting make it work a lot better +set backspace=indent,eol,start + +" when tab completing on the expert line you don't want to miss out on EDIT vs +" edit or nerdtree vs NERDTree and this setting ignores case completely +set ignorecase + +" highlight your search patterns (very handy when building regexes) +set hlsearch + +" highlight the search pattern as-you-go (tremendously helpful when +" constructing regexes) +set incsearch + +" always show a status line at the bottom of your vim which shows some basic +" information about the file, which line you're at etc +set laststatus=2 + +" show files in statusbar when opening via expert mode +set wildmenu + +" also show all possible expert mode commands in the statusline +set wildmode=full + +" reverse numbering (in the sideline) so you don't have to manually count how +" many lines you have to yank +set rnu + +" it's also nice to still have your absolute line number in the sideline +set nu + +" can do copy paste from the clipboard +set clipboard=unnamedplus + +" automatically save buffers +set autowrite +set autowriteall + +" spaces not tabs for coding purposes +set sw=4 +set ts=4 +set sts=4 + +" mouse usage can be handy, especially when using LspPeekDefinition +set mouse=a + +" enable code folding +set foldmethod=indent + +" set SPACE to toggle a fold +nnoremap za + +" set the leader key for shortcuts (uncomment if you don't want it to be the +" default \ key +"let mapleader=";" + diff --git a/main.vimrc b/main.vimrc new file mode 100644 index 0000000..a6b71a8 --- /dev/null +++ b/main.vimrc @@ -0,0 +1,12 @@ + +"define the files we want to source +let _vimrc_dir = fnamemodify(resolve(expand(":p")), ":p:h") +let _files = [] +call add(_files, _vimrc_dir . "/vundle_essentials.vimrc") +call add(_files, _vimrc_dir . "/essentials.vimrc") +call add(_files, _vimrc_dir . "/visual.vimrc") +call add(_files, _vimrc_dir . "/systemd.vim") + +for f in _files + execute 'source' f +endfor diff --git a/systemd.vim b/systemd.vim new file mode 100644 index 0000000..416945b --- /dev/null +++ b/systemd.vim @@ -0,0 +1,49 @@ +let s:matches = system('systemd --dump-configuration --no-pager | grep -o -P "(^\w+[=])|([\[]\w+[\]])"') +let s:matches = split(s:matches, "\n") +let s:allkeys = system('systemd --dump-configuration --no-pager | grep -o -P "(^[\[]\w+[\]])" | sed -e "s/[]]//g"') +let s:allkeys = split(s:allkeys, "\n") +"let g:AutoPairs = {'(':')', '{':'}',"'":"'",'"':'"', '`':'`'} +"let g:asyncomplete_triggers = {'*': ['.', '>', ':', '['] } + +function s:get_key() + let l:line = search('[\w*\]', "bnW") + if l:line == 0 + return 0 + endif + let l:key = getbufline(bufnr("%"), l:line)[0] + return l:key +endfunction + +function s:get_matches() + let l:key = s:get_key() + if l:key == 0 + let l:from = index(s:matches, l:key) + 1 + let l:until = match(s:matches, '\[\w\+\]', l:from) + let l:until = l:until - 1 + return s:matches[l:from:l:until] + endif + return s:allkeys +endfunction + +function! s:systemd_completor(opt, ctx) abort + let l:col = a:ctx['col'] + let l:typed = a:ctx['typed'] + if match(l:typed, '[') != -1 + let l:matches = s:allkeys + else + let l:matches = s:get_matches() + endif + echom l:typed + let l:kw = matchstr(l:typed, '\v\S+$') + let l:kwlen = len(l:kw) + let l:startcol = l:col - l:kwlen + let l:startcol = 1 + call asyncomplete#complete(a:opt['name'], a:ctx, l:startcol, l:matches) + echo 'done' +endfunction + +au User asyncomplete_setup call asyncomplete#register_source({ + \ 'name': 'systemd', + \ 'allowlist': ['systemd'], + \ 'completor': function('s:systemd_completor'), + \ }) diff --git a/visual.vimrc b/visual.vimrc new file mode 100644 index 0000000..fc18d59 --- /dev/null +++ b/visual.vimrc @@ -0,0 +1,23 @@ +" ---------------------------------------------------------------------------- +" visual configuration +" ---------------------------------------------------------------------------- + +" set a colorscheme +colorscheme solarized +set background=dark + +" do soft wrap of text but not in the middle of words +set wrap linebreak nolist + +" don't do hard wraps in any files +set textwidth=0 + +" add a color column at the 80 char +set colorcolumn=80 + +" spelling highlight needs to be done after the colorscheme load +highlight SpellBad term=underline cterm=underline + +" enable English spellchecking in markdown files +autocmd FileType markdown setlocal spell +autocmd FileType markdown setlocal spelllang=en diff --git a/vundle_essentials.vimrc b/vundle_essentials.vimrc new file mode 100644 index 0000000..74af70f --- /dev/null +++ b/vundle_essentials.vimrc @@ -0,0 +1,144 @@ +" ---------------------------------------------------------------------------- +" vundle essentials +" ---------------------------------------------------------------------------- + +set nocompatible +filetype off + +" set the runtime path to include Vundle and initialize +set rtp+=~/.vim/bundle/Vundle.vim + +call vundle#begin() + +" let vundle manage vundle... +Plugin 'VundleVim/Vundle.vim' + +" Basic plugins +Plugin 'jiangmiao/auto-pairs' +Plugin 'preservim/nerdtree' +Plugin 'jeetsukumaran/vim-buffergator' + +" IDE like plugins +Plugin 'prabirshrestha/asyncomplete.vim' +Plugin 'prabirshrestha/vim-lsp' +Plugin 'prabirshrestha/asyncomplete-lsp.vim' +Plugin 'mattn/vim-lsp-settings' +"Plugin 'yami-beta/asyncomplete-omni.vim' +Plugin 'prabirshrestha/asyncomplete-file.vim' + +" Language autocomplete for English +Plugin 'htlsne/asyncomplete-look' + +" an additional colorscheme I like +Plugin 'altercation/vim-colors-solarized' + +let _plugins_list = _vimrc_dir . "/" . $USER . "_plugins.list" +if filereadable(_plugins_list) + "echomsg "found user plugins " . _plugins_list + execute 'source '.fnameescape(_plugins_list) +endif + +call vundle#end() + +filetype plugin indent on + +" ---------------------------------------------------------------------------- +" plugin configuration +" ---------------------------------------------------------------------------- + +" NERDTree +" -------- + +" map a keyboard shortcut to show and hide NERDTree +nnoremap :NERDTreeToggle + +" Exit Vim if NERDTree is the only window remaining in the only tab. +autocmd BufEnter * if tabpagenr('$') == 1 && winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif + +" vim-lsp +" ------- + +" general vim-lsp settings +" ------------------------ + +" maps quite q few keyboad shortcuts +" this is taken staight off the github page with one added shortcut to peak at +" the definition of a function or class +function! s:on_lsp_buffer_enabled() abort + setlocal omnifunc=lsp#complete + setlocal signcolumn=no " messes with some autocomplete! + if exists('+tagfunc') | setlocal tagfunc=lsp#tagfunc | endif + nmap gd (lsp-definition) + nmap gpd (lsp-peek-definition) + nmap gs (lsp-document-symbol-search) + nmap gS (lsp-workspace-symbol-search) + nmap gr (lsp-references) + nmap gi (lsp-implementation) + nmap gt (lsp-type-definition) + nmap rn (lsp-rename) + nmap [g (lsp-previous-diagnostic) + nmap ]g (lsp-next-diagnostic) + nmap K (lsp-hover) + inoremap lsp#scroll(+4) + inoremap lsp#scroll(-4) + + let g:lsp_format_sync_timeout = 2000 + autocmd! BufWritePre *.rs,*.go call execute('LspDocumentFormatSync') +endfunction + +augroup lsp_install + au! + " call s:on_lsp_buffer_enabled only for languages that has the server registered. + autocmd User lsp_buffer_enabled call s:on_lsp_buffer_enabled() +augroup END + +" asyncomplete +" ------------ + +" make tab complete work +inoremap pumvisible() ? "\" : "\" +inoremap pumvisible() ? "\" : "\" +inoremap pumvisible() ? asyncomplete#close_popup() : "\" + +" force refresh with CTRL-SPACE +imap (asyncomplete_force_refresh) + +" asyncomplete-file +" ----------------- + +au User asyncomplete_setup call asyncomplete#register_source(asyncomplete#sources#file#get_source_options({ + \ 'name': 'file', + \ 'allowlist': ['*'], + \ 'priority': 10, + \ 'completor': function('asyncomplete#sources#file#completor') + \ })) + +" asyncomplete-omni +" ----------------- + +"autocmd User asyncomplete_setup call asyncomplete#register_source(asyncomplete#sources#omni#get_source_options({ +" \ 'name': 'omni', +" \ 'allowlist': ['*'], +" \ 'blocklist': ['c', 'cpp', 'html'], +" \ 'completor': function('asyncomplete#sources#omni#completor'), +" \ 'config': { +" \ 'show_source_kind': 1, +" \ }, +" \ })) + +" asyncomplete-look +" ----------------- + +au User asyncomplete_setup call asyncomplete#register_source({ + \ 'name': 'look', + \ 'allowlist': ['text', 'markdown'], + \ 'completor': function('asyncomplete#sources#look#completor'), + \ }) + +" source the additional config + +let _plugins_list = _vimrc_dir . "/" . $USER . "_plugins.vimrc" +if filereadable(_plugins_list) + "echomsg "found user plugin configuration " . _plugins_list + execute 'source '.fnameescape(_plugins_list) +endif diff --git a/waldek_plugins.list b/waldek_plugins.list new file mode 100644 index 0000000..4f1813f --- /dev/null +++ b/waldek_plugins.list @@ -0,0 +1,15 @@ +" ---------------------------------------------------------------------------- +" list of additional plugins +" ---------------------------------------------------------------------------- + +"Plugin 'kshenoy/vim-signature' +"Plugin 'tpope/vim-surround' +"Plugin 'tpope/vim-fugitive' +Plugin 'majutsushi/tagbar' +"Plugin 'Xuyuanp/nerdtree-git-plugin' +"Plugin 'scrooloose/nerdcommenter' +"Plugin 'kalafut/vim-taskjuggler' + +" debugging inside vim +"Plugin 'Shougo/vimproc.vim' +"Plugin 'idanarye/vim-vebugger' diff --git a/waldek_plugins.vimrc b/waldek_plugins.vimrc new file mode 100644 index 0000000..9875de8 --- /dev/null +++ b/waldek_plugins.vimrc @@ -0,0 +1,128 @@ +" ---------------------------------------------------------------------------- +" waldek additions essentials +" ---------------------------------------------------------------------------- + +" close all windows except the one you're in +nmap o :only + +" use the arrows for buffer navigation +nnoremap +nnoremap +nnoremap +nnoremap + +" use CTRL-motion for buffer navigation +nnoremap h +nnoremap j +nnoremap k +nnoremap l + +" don't use the arrows for insert navigation +inoremap +inoremap +inoremap +inoremap + +" more natural splits set splitbelow +set splitright +set splitbelow + +" ---------------------------------------------------------------------------- +" waldek filetype specific +" ---------------------------------------------------------------------------- + +" python3 +" ------- + +" let gi introspection work +if has('python3') +py3 << EOF +import os.path +import sys +import vim +sys.path.insert(0, os.path.join(os.path.expanduser('~'), '.cache/fakegir/')) +EOF +endif + +" run code in new window +let _pymain="null" +map rs :let _pymain=expand('%:p') +map ru :let _pymain="null" +map r :execute '!x-terminal-emulator -e python3 ~/bin/python/vim_run.py ' . &filetype expand('%:p') _pymain +map rr :execute '!x-terminal-emulator -e python3 ~/bin/python/vim_run.py ' . &filetype expand('%:p') "null" + +" mail +" ---- + +" mail should not wrap for mutt +autocmd FileType mail set textwidth=0 + +" arduino +" ------- + +au BufRead,BufNewFile *.pde set filetype=arduino +au BufRead,BufNewFile *.ino set filetype=arduino + +" vimscript +" ---- + +" mail should not wrap for mutt +autocmd FileType vim nnoremap :source % + +" ---------------------------------------------------------------------------- +" waldek plugins specific +" ---------------------------------------------------------------------------- + +" vim-lsp +" ------- + +set foldmethod=expr + \ foldexpr=lsp#ui#vim#folding#foldexpr() + \ foldtext=lsp#ui#vim#folding#foldtext() + +" lsp-settings +" ------------ + +" TagBar +" ------ + +nmap c :TagbarToggle + +" nerdtree +" -------- + +map n :NERDTreeToggle +let g:NERDTreeWinSize=30 +let g:NERDDefaultAlign = 'left' + +" vebugger +" -------- + +let g:vebugger_leader='d' + +" marker specific +" --------------- + +let g:SignatureMap = { + \ 'Leader' : "m", + \ 'PlaceNextMark' : "mm", + \ 'ToggleMarkAtLine' : "m.", + \ 'PurgeMarksAtLine' : "m-", + \ 'DeleteMark' : "dm", + \ 'PurgeMarks' : "m", + \ 'PurgeMarkers' : "m", + \ 'GotoNextLineAlpha' : "m]", + \ 'GotoPrevLineAlpha' : "m[", + \ 'GotoNextSpotAlpha' : "M]", + \ 'GotoPrevSpotAlpha' : "M[", + \ 'GotoNextLineByPos' : "]m", + \ 'GotoPrevLineByPos' : "[m", + \ 'GotoNextSpotByPos' : "]M", + \ 'GotoPrevSpotByPos' : "[M", + \ 'GotoNextMarker' : "]-", + \ 'GotoPrevMarker' : "[-", + \ 'GotoNextMarkerAny' : "]=", + \ 'GotoPrevMarkerAny' : "[=", + \ 'ListBufferMarks' : "m/", + \ 'ListBufferMarkers' : "m?" + \ }