dotfiles/.vimrc

271 lines
7.7 KiB
VimL
Raw Normal View History

2021-05-27 17:54:53 +02:00
" Vundle
filetype off
" Set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
" Download plug-ins to the ~/.vim/plugged/ directory
call vundle#begin('~/.vim/plugged')
2021-08-31 13:08:37 +02:00
" Let Vundle manage Vundle; muss immer der erste Eintrag sein
2021-06-01 17:44:59 +02:00
Plugin 'VundleVim/Vundle.vim'
2022-07-31 09:46:13 +02:00
" project drawer
Plugin 'preservim/nerdtree'
2022-07-30 14:36:45 +02:00
" ansible integration
Plugin 'pearofducks/ansible-vim'
" omnicompletion während dem tippen
Plugin 'vim-scripts/AutoComplPop'
2023-11-15 08:59:16 +01:00
" statusline
Plugin 'itchyny/lightline.vim'
2021-06-01 17:44:59 +02:00
" languagepack
2021-08-12 13:30:31 +02:00
Plugin 'sheerun/vim-polyglot'
2021-12-21 22:38:56 +01:00
" highlight fuer movement mit tTfFwW
Plugin 'unblevable/quick-scope'
2021-05-31 20:44:56 +02:00
" fuzzy finder
2021-08-12 13:30:31 +02:00
Plugin 'ctrlpvim/ctrlp.vim'
2021-05-31 20:44:56 +02:00
" git integration G:
2021-08-12 13:30:31 +02:00
Plugin 'tpope/vim-fugitive'
2021-12-21 21:17:13 +01:00
" ausrichten von text
Plugin 'junegunn/vim-easy-align'
2021-11-21 11:06:52 +01:00
" buffer in tabline
Plugin 'ap/vim-buftabline'
2021-11-21 11:22:17 +01:00
" start screen
Plugin 'mhinz/vim-startify'
2023-11-15 08:59:16 +01:00
" bracketed paste/ kein set-paste mehr
2021-11-22 07:19:31 +01:00
Plugin 'ConradIrwin/vim-bracketed-paste'
2023-01-07 12:00:59 +01:00
" Undotree
Plugin 'mbbill/undotree'
2023-08-18 11:19:32 +02:00
" highlight yanked text
Plugin 'machakann/vim-highlightedyank'
" nord theme für vimdiff
Plugin 'nordtheme/vim'
" outline md usw.
Plugin 'vim-voom/VOoM'
2021-05-27 17:54:53 +02:00
call vundle#end()
2021-06-01 17:44:59 +02:00
2021-11-30 08:39:30 +01:00
let mapleader = ","
2021-06-01 17:44:59 +02:00
2021-08-31 13:08:37 +02:00
" ### allgemeine Optionen
2023-08-31 08:21:53 +02:00
" indentation
" https://vim.fandom.com/wiki/Indenting_source_code
set expandtab
set shiftwidth=2
set softtabstop=2
2021-08-31 13:08:37 +02:00
" ### Suche
" While typing a search command, show immediately where the so far typed pattern matches.
set incsearch
2021-08-31 13:08:37 +02:00
" When there is a previous search pattern, highlight all its matches.
set hlsearch
2021-08-31 13:08:37 +02:00
" Ignore case in search patterns.
set ignorecase
2021-08-31 13:08:37 +02:00
" Override the 'ignorecase' option if the search pattern contains upper case characters.
set smartcase
2023-11-15 08:59:16 +01:00
" show status-bar
set laststatus=2
2021-08-31 13:08:37 +02:00
" Show line numbers.
set number
2021-08-31 13:08:37 +02:00
" ### Kommandovervollständigung
" https://www.reddit.com/r/vim/comments/oo9gms/any_way_to_get_vim_to_not_defaulting_to_the_first/h5wygix/?context=8&depth=9
set wildmode=longest,list,full
set wildmenu
set wildignore=*.o,*~
" ### Rest
" Show (partial) command in status line.
set showcmd
2021-06-01 17:44:59 +02:00
set virtualedit=onemore
set encoding=UTF-8
set visualbell
set ruler
set undolevels=1000
set backspace=indent,eol,start
2021-08-31 13:08:37 +02:00
" ermögliche das bearbeitete buffer in der hintergrund können
set hidden
" verhindert zeilenumbrüche
set nowrap
" https://vim.fandom.com/wiki/Automatic_word_wrapping
set wrap linebreak
" Enable syntax highlighting
syntax on
2023-11-15 08:59:16 +01:00
" aktiviere maus
2022-07-01 14:25:55 +02:00
set mouse=a
2023-10-25 10:09:50 +02:00
" vergrößere/verkleinere splits mit der maus
" https://vi.stackexchange.com/questions/514/how-do-i-change-the-current-splits-width-and-height
:set ttymouse=xterm2
2021-08-31 13:08:37 +02:00
" https://unix.stackexchange.com/questions/12535/how-to-copy-text-from-vim-to-an-external-program
set clipboard=unnamedplus
" zeige "matching" klammer usw.
set showmatch
2021-06-01 17:44:59 +02:00
2021-10-26 12:12:30 +02:00
" ### Plugins
2021-08-31 13:08:37 +02:00
" ### ripgrep und ctrlp
2021-05-27 17:54:53 +02:00
if executable('rg')
let g:ctrlp_user_command = 'rg %s --files --hidden --color=never --glob ""'
2021-10-06 19:49:30 +02:00
else
let g:ctrlp_user_command = 'find %s -type f'
2021-05-27 17:54:53 +02:00
endif
" ignore files
" https://github.com/ctrlpvim/ctrlp.vim
set wildignore+=*/tmp/*,*.so,*.swp,*.zip " MacOSX/Linux
set wildignore+=*\\tmp\\*,*.swp,*.zip,*.exe " Windows
2021-05-28 13:26:56 +02:00
let g:ctrlp_custom_ignore = '\v[\/]\.(git|hg|svn)$'
2021-08-24 08:57:21 +02:00
let g:ctrlp_map = ''
2021-11-24 14:51:25 +01:00
2021-11-19 07:50:05 +01:00
" ### lightline/statusline
" blende insert/visual/... in der commandline aus, steht in lightline
set noshowmode
set laststatus=2
let g:lightline = {
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ],
\ [ 'gitbranch', 'readonly', 'filename', 'modified' ] ]
\ },
\ 'component_function': {
\ 'gitbranch': 'FugitiveHead'
\ },
\ }
" ### vim startify
2021-11-21 11:22:17 +01:00
" returns all modified files of the current git repo
" `2>/dev/null` makes the command fail quietly, so that when we are not
" in a git repo, the list will be empty
2023-11-15 08:59:16 +01:00
function! s:gitmodified()
2021-11-21 11:22:17 +01:00
let files = systemlist('git ls-files -m 2>/dev/null')
return map(files, "{'line': v:val, 'path': v:val}")
endfunction
" same as above, but show untracked files, honouring .gitignore
2023-11-15 08:59:16 +01:00
function! s:gituntracked()
2021-11-21 11:22:17 +01:00
let files = systemlist('git ls-files -o --exclude-standard 2>/dev/null')
return map(files, "{'line': v:val, 'path': v:val}")
endfunction
let g:startify_lists = [
2023-11-15 08:59:16 +01:00
\ { 'type': 'files', 'header': [' mru'] },
\ { 'type': 'dir', 'header': [' mru '. getcwd()] },
\ { 'type': 'sessions', 'header': [' sessions'] },
\ { 'type': 'bookmarks', 'header': [' bookmarks'] },
\ { 'type': function('s:gitmodified'), 'header': [' git modified']},
\ { 'type': function('s:gituntracked'), 'header': [' git untracked']},
\ { 'type': 'commands', 'header': [' commands'] },
2021-11-21 11:22:17 +01:00
\ ]
2021-12-21 22:38:56 +01:00
" ### quick-scope
2023-11-15 08:59:16 +01:00
" trigger a highlight in the appropriate direction only when pressing these keys:
2021-12-21 22:38:56 +01:00
let g:qs_highlight_on_keys = ['f', 'F', 't', 'T']
2023-03-27 14:20:01 +02:00
" wrap words with ``
" https://stackoverflow.com/questions/24555192/command-for-putting-backticks-around-the-current-word
nnoremap <F8> ciw``<C-r>"``<Esc>
xnoremap <F8> c``<C-r>"``<Esc>
2021-08-31 13:08:37 +02:00
" ### Keybindings
" markdown outline in split
nnoremap <F4> :Voom markdown<CR>
" deaktiviere Ex-Mode keybinding
2021-11-30 08:39:30 +01:00
nnoremap Q <Nop>
2021-08-31 13:08:37 +02:00
" Ctrl+S zum speichern
2021-11-30 08:39:30 +01:00
nnoremap <C-s> :w<CR>
2021-11-21 11:06:52 +01:00
" Navigate tabs
nnoremap <C-j> :bnext<CR>
nnoremap <C-k> :bprev<CR>
2021-11-30 08:39:30 +01:00
" strg+f sucht fuzzy nach dateien
nnoremap <C-f> :CtrlP<CR>
2023-02-16 07:34:07 +01:00
" format paragraphs as markdown table
nnoremap <Leader>mm Vap:EasyAlign *\|<cr><esc>
nnoremap <F7> Vap:EasyAlign *\|<cr><esc>
2023-08-31 08:21:53 +02:00
2022-01-09 14:55:42 +01:00
" lasse Y wie C oder D funktionieren
nmap Y y$
2022-07-31 09:46:13 +02:00
" Toggle NERDTree
2022-07-31 19:48:37 +02:00
nnoremap <F2> :call ToggleNERDTreeFind()<CR>
2023-11-15 08:59:16 +01:00
"
2023-01-07 12:00:59 +01:00
" toddle Undotree
nnoremap <F6> :UndotreeToggle<CR>
2023-05-14 21:34:38 +02:00
2023-08-31 14:42:58 +02:00
" U als un-undo und nicht als Großschreibung
nnoremap U :redo<Enter>
2021-11-30 08:50:10 +01:00
" ### Abbreviations
iabbrev ncicht nicht
iabbrev nciht nicht
2022-07-20 07:05:49 +02:00
" linenumbers
2023-11-15 08:59:16 +01:00
nnoremap <Leader>z :set nonumber! <CR>
2022-07-30 14:10:54 +02:00
2023-08-29 08:32:53 +02:00
" einzelne Aufräumfunktionen, bei F9 werden alle gecalled
" trailing whitespaces werden automatisch beim speichern entfernt
function! Whitespaces_trailing()
2023-08-14 09:13:41 +02:00
" Remove trailing whitespace
%s/\s\+$//e
2023-08-29 08:32:53 +02:00
endfunction
function! Whitespaces_consecutive()
2023-08-14 09:13:41 +02:00
" Replace consecutive spaces between words with a single space (only for .md files)
if &filetype == "markdown"
%s/\(\w\)\s\+\(\w\)/\1 \2/g
endif
2023-08-29 08:32:53 +02:00
endfunction
function! Whitespaces_lines()
2023-08-14 09:13:41 +02:00
" Run silent command to remove multiple consecutive empty lines (only for .md files)
if &filetype == "markdown"
silent %!cat -s
endif
endfunction
2023-08-29 08:32:53 +02:00
function! Whitespaces_all()
call Whitespaces_trailing()
call Whitespaces_consecutive()
call Whitespaces_lines()
endfunction
2023-08-14 09:13:41 +02:00
" Map F9 to execute the custom function
2023-08-29 08:32:53 +02:00
nnoremap <F9> :call Whitespaces_all()<CR>
" entferne trailing whitespaces beim speichern
autocmd BufWritePre * :call Whitespaces_trailing()
2022-07-31 09:46:13 +02:00
" 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
" NERDTree - show hidden files
let NERDTreeShowHidden=1
2022-07-31 19:48:37 +02:00
" NERDTREE - Find file or close
" https://stackoverflow.com/questions/14964020/is-it-possible-to-configure-behaviour-of-nerdtreetoggle-to-use-nerdtreefind-When
function! ToggleNERDTreeFind()
if g:NERDTree.IsOpen()
execute ':NERDTreeClose'
else
execute ':NERDTreeFind'
endif
endfunction
2023-08-30 13:26:19 +02:00
2023-12-15 10:34:51 +01:00
" timeouts
set timeoutlen=100
" set colorscheme for vimdiff
if &diff
colorscheme nord
endif
augroup spell
autocmd!
autocmd FileType * highlight SpellBad cterm=underline ctermfg=red ctermbg=NONE
autocmd FileType * set spellfile=~/dotfiles/vim/spell/own.add
autocmd FileType * set spellsuggest=fast,10
autocmd FileType * set spell spelllang=de_de,en
augroup END
" z= Korrektur
" ]s/[s gehe vor/zurück nächsten fehlerhaften wort
" zg add to dictionary
augroup yaml
autocmd!
autocmd FileType yml setlocal ai ts=2 sw=2 et
autocmd FileType yaml,yml setlocal ai ts=2 sw=2 et
augroup END