diff --git a/.config/git/ignore b/.config/git/ignore index a0ed808..ee17658 100644 --- a/.config/git/ignore +++ b/.config/git/ignore @@ -4,3 +4,24 @@ *.orig *.temp *.tmp + +# Vim +# Source: https://github.com/github/gitignore/blob/main/Global/Vim.gitignore +# +# Swap +[._]*.s[a-v][a-z] +!*.svg +[._]*.sw[a-p] +[._]s[a-rt-v][a-z] +[._]ss[a-gi-z] +[._]sw[a-p] +# Session +Session.vim +Sessionx.vim +# Temporary +.netrwhist +*~ +# Auto-generated tag files +tags +# Persistent undo +[._]*.un~ diff --git a/.config/shell/env b/.config/shell/env index 73751b4..84ee7c7 100644 --- a/.config/shell/env +++ b/.config/shell/env @@ -22,11 +22,14 @@ export DOTFILES_DIR="$XDG_DATA_HOME/dotfiles" # also set in ~/.local/bin/instal # Generic shell configs +export EDITOR=vim export GPG_TTY=$(tty) export PAGER="less --chop-long-lines --ignore-case --LONG-PROMPT --no-init --status-column --quit-if-one-screen" export TZ="Europe/Berlin" +export VISUAL=$EDITOR # Move common tools' config and cache files into XDG directories export LESSHISTFILE="$XDG_STATE_HOME/less/history" +export VIMINIT='let $MYVIMRC="'"$XDG_CONFIG_HOME"'/vim/vimrc" | source $MYVIMRC' diff --git a/.config/vim/after/ftplugin/python.vim b/.config/vim/after/ftplugin/python.vim new file mode 100644 index 0000000..85426a5 --- /dev/null +++ b/.config/vim/after/ftplugin/python.vim @@ -0,0 +1,91 @@ +" Set the search path to the folder of the current file and its sub-folders +setlocal path=.,** + +" Exclude Python's compiled files from searches +setlocal wildignore=*/__pycache__/*,*.pyc + + +" Resolve Python imports to files, +" so that `gf` jumps to the module under the cursor +" +" Examples, with the cursor on the marked word: +" - `from lalib.elements import galois` => lalib/elements/galois.py +" - `from lalib.elements import ...` => lalib/elements/__init__.py +" - `import lalib.config` => lalib/config.py +" +if !exists('*s:PyGoToFile') + + " Build the dotted module path for the word under the cursor + function! s:PyModuleUnderCursor() + let l:word = expand('') + let l:from = matchstr(getline('.'), '^\s*from\s\+\zs[A-Za-z0-9_.]\+') + let l:imp = matchstr(getline('.'), '^\s*import\s\+\zs[A-Za-z0-9_.]\+') + let l:base = !empty(l:from) ? l:from : l:imp + if empty(l:base) + return '' + endif + let l:parts = split(l:base, '\.') + let l:idx = index(l:parts, l:word) + if l:idx >= 0 " Cursor within the dotted prefix => Truncate there + return join(l:parts[0:l:idx], '/') + elseif !empty(l:from) " Cursor on an imported name => Append it + return join(l:parts, '/') . '/' . l:word + endif + return '' + endfunction + + function! s:PyFindFile(mod) + for l:candidate in [a:mod . '.py', a:mod . '/__init__.py'] + let l:found = findfile(l:candidate) " search the `path` + if !empty(l:found) + return l:found + endif + endfor + return '' + endfunction + + function! s:PyGoToFile() + let l:mod = s:PyModuleUnderCursor() + let l:file = empty(l:mod) ? '' : s:PyFindFile(l:mod) + if empty(l:file) + echohl ErrorMsg | echo 'No module file for: ' . l:mod | echohl NONE + return + endif + execute 'edit ' . fnameescape(l:file) + endfunction + +endif + +" jumps back +nnoremap gf :call PyGoToFile() + +" Find `def`s and `class`es with [d and [D +setlocal define=^\\s*\\<\\(def\\|class\\)\\> + + +" Indentation settings come from ~/.config/vim/vimrc, and +" `smartindent` is left off as it interferes with VIM's Python indent script + + +" Auto-wrap lines after 88 characters, which is PEP8's limit plus 10%, +" a more relaxed boundary which occasionally may be used +setlocal textwidth=88 + + +" Make column 80 red to indicate PEP8's maximum allowed line length +setlocal colorcolumn=80 + +" Additionally, give every character beyond 80 columns a red background +" (matches are window-local, so re-apply them per buffer) +highlight ColorColumn ctermbg=DarkRed +augroup python_overlength + autocmd! * + autocmd BufEnter call matchadd('ErrorMsg', '\%>80v.\+', 100) + autocmd BufLeave call clearmatches() +augroup END +call matchadd('ErrorMsg', '\%>80v.\+', 100) + + +" Show line numbers by default for .py files +let g:show_numbers=1 +call ShowLineNumbers() diff --git a/.config/vim/spell/.gitkeep b/.config/vim/spell/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/.config/vim/vimrc b/.config/vim/vimrc new file mode 100644 index 0000000..05031b6 --- /dev/null +++ b/.config/vim/vimrc @@ -0,0 +1,318 @@ +" Use VIM improved mode +set nocompatible + + +" Disable VIM's startup message +set shortmess+=I + +" Number of remembered undo steps +set undolevels=1000 + + +set runtimepath^=$XDG_CONFIG_HOME/vim +set runtimepath+=$XDG_CONFIG_HOME/vim/after + +" Set environment variables for convenient usage +let $RC = expand('$XDG_CONFIG_HOME/vim/vimrc') +let $RTP=split(&runtimepath, ',')[0] + + +" Detect the file's type and load the corresponding plugin and indent files +filetype plugin indent on + +" Enable syntax highlighting +syntax on + + +" Configure tab behavior +set expandtab " Insert spaces instead of tab characters +set tabstop=4 " Width of an existing tab character +set shiftwidth=4 " Width of one >> or << indent step +set softtabstop=4 " Width inserted/removed by and +set shiftround " Round indents to a multiple of shiftwidth +set autoindent " Keep the previous line's indent on a new line +vnoremap >gv +vnoremap