This commit is contained in:
waldek 2021-09-06 07:30:45 +02:00
commit 9b11f01dd2
7 changed files with 441 additions and 0 deletions

70
essentials.vimrc Normal file
View File

@ -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 <SPACE> za
" set the leader key for shortcuts (uncomment if you don't want it to be the
" default \ key
"let mapleader=";"

12
main.vimrc Normal file
View File

@ -0,0 +1,12 @@
"define the files we want to source
let _vimrc_dir = fnamemodify(resolve(expand("<sfile>: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

49
systemd.vim Normal file
View File

@ -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'),
\ })

23
visual.vimrc Normal file
View File

@ -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

144
vundle_essentials.vimrc Normal file
View File

@ -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 <C-t> :NERDTreeToggle<CR>
" 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 <buffer> gd <plug>(lsp-definition)
nmap <buffer> gpd <plug>(lsp-peek-definition)
nmap <buffer> gs <plug>(lsp-document-symbol-search)
nmap <buffer> gS <plug>(lsp-workspace-symbol-search)
nmap <buffer> gr <plug>(lsp-references)
nmap <buffer> gi <plug>(lsp-implementation)
nmap <buffer> gt <plug>(lsp-type-definition)
nmap <buffer> <leader>rn <plug>(lsp-rename)
nmap <buffer> [g <plug>(lsp-previous-diagnostic)
nmap <buffer> ]g <plug>(lsp-next-diagnostic)
nmap <buffer> K <plug>(lsp-hover)
inoremap <buffer> <expr><c-f> lsp#scroll(+4)
inoremap <buffer> <expr><c-d> 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 <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
inoremap <expr> <cr> pumvisible() ? asyncomplete#close_popup() : "\<cr>"
" force refresh with CTRL-SPACE
imap <c-@> <Plug>(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

15
waldek_plugins.list Normal file
View File

@ -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'

128
waldek_plugins.vimrc Normal file
View File

@ -0,0 +1,128 @@
" ----------------------------------------------------------------------------
" waldek additions essentials
" ----------------------------------------------------------------------------
" close all windows except the one you're in
nmap <leader>o :only <cr>
" use the arrows for buffer navigation
nnoremap <down> <C-W><C-J>
nnoremap <up> <C-W><C-K>
nnoremap <left> <C-W><C-H>
nnoremap <right> <C-W><C-L>
" use CTRL-motion for buffer navigation
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l
" don't use the arrows for insert navigation
inoremap <Down> <Nop>
inoremap <Up> <Nop>
inoremap <Left> <Nop>
inoremap <Right> <Nop>
" 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 <leader>rs :let _pymain=expand('%:p')<CR>
map <leader>ru :let _pymain="null"<CR>
map <leader>r :execute '!x-terminal-emulator -e python3 ~/bin/python/vim_run.py ' . &filetype expand('%:p') _pymain <CR><CR>
map <leader>rr :execute '!x-terminal-emulator -e python3 ~/bin/python/vim_run.py ' . &filetype expand('%:p') "null" <CR><CR>
" 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 <buffer> <F5> :source % <CR>
" ----------------------------------------------------------------------------
" waldek plugins specific
" ----------------------------------------------------------------------------
" vim-lsp
" -------
set foldmethod=expr
\ foldexpr=lsp#ui#vim#folding#foldexpr()
\ foldtext=lsp#ui#vim#folding#foldtext()
" lsp-settings
" ------------
" TagBar
" ------
nmap <leader>c :TagbarToggle <cr>
" nerdtree
" --------
map <leader>n :NERDTreeToggle<CR>
let g:NERDTreeWinSize=30
let g:NERDDefaultAlign = 'left'
" vebugger
" --------
let g:vebugger_leader='<Leader>d'
" marker specific
" ---------------
let g:SignatureMap = {
\ 'Leader' : "m",
\ 'PlaceNextMark' : "mm",
\ 'ToggleMarkAtLine' : "m.",
\ 'PurgeMarksAtLine' : "m-",
\ 'DeleteMark' : "dm",
\ 'PurgeMarks' : "m<Space>",
\ 'PurgeMarkers' : "m<BS>",
\ 'GotoNextLineAlpha' : "m]",
\ 'GotoPrevLineAlpha' : "m[",
\ 'GotoNextSpotAlpha' : "M]",
\ 'GotoPrevSpotAlpha' : "M[",
\ 'GotoNextLineByPos' : "]m",
\ 'GotoPrevLineByPos' : "[m",
\ 'GotoNextSpotByPos' : "]M",
\ 'GotoPrevSpotByPos' : "[M",
\ 'GotoNextMarker' : "]-",
\ 'GotoPrevMarker' : "[-",
\ 'GotoNextMarkerAny' : "]=",
\ 'GotoPrevMarkerAny' : "[=",
\ 'ListBufferMarks' : "m/",
\ 'ListBufferMarkers' : "m?"
\ }