1 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2 " Lot of stuff is from the Internetz, especially from
3 " https://github.com/s3rvac/dotfiles/blob/master/vim/.vimrc
5 " https://github.com/amix/vimrc/blob/master/vimrcs/basic.vim
6 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
8 set nocompatible " be iMproved, required
9 filetype off " required
11 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
12 let g:netrw_banner = 0 " disable banner
13 let g:netrw_liststyle = 3 " tree view
15 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
17 call plug#begin('~/.vim/plugged')
19 Plug 'prabirshrestha/async.vim'
20 Plug 'prabirshrestha/vim-lsp'
21 Plug 'ajh17/vimcompletesme'
22 Plug 'itchyny/lightline.vim'
23 Plug 'Townk/vim-autoclose'
25 " Initialize plugin system
28 if executable('clangd')
31 autocmd User lsp_setup call lsp#register_server({
33 \ 'cmd': {server_info->['clangd']},
34 \ 'whitelist': ['c', 'cpp', 'objc', 'objcpp'],
36 autocmd FileType c setlocal omnifunc=lsp#complete
37 autocmd FileType cpp setlocal omnifunc=lsp#complete
38 autocmd FileType objc setlocal omnifunc=lsp#complete
39 autocmd FileType objcpp setlocal omnifunc=lsp#complete
43 function! s:on_lsp_buffer_enabled() abort
44 setlocal omnifunc=lsp#complete
45 setlocal signcolumn=yes
46 if exists('+tagfunc') | setlocal tagfunc=lsp#tagfunc | endif
47 nmap <buffer> gd <plug>(lsp-definition)
48 nmap <buffer> gs <plug>(lsp-document-symbol-search)
49 nmap <buffer> gS <plug>(lsp-workspace-symbol-search)
50 nmap <buffer> gr <plug>(lsp-references)
51 nmap <buffer> gi <plug>(lsp-implementation)
52 nmap <buffer> gt <plug>(lsp-type-definition)
53 nmap <buffer> <leader>rn <plug>(lsp-rename)
54 nmap <buffer> [g <plug>(lsp-previous-diagnostic)
55 nmap <buffer> ]g <plug>(lsp-next-diagnostic)
56 nmap <buffer> K <plug>(lsp-hover)
57 inoremap <buffer> <expr><c-f> lsp#scroll(+4)
58 inoremap <buffer> <expr><c-d> lsp#scroll(-4)
60 let g:lsp_format_sync_timeout = 1000
61 autocmd! BufWritePre *.rs,*.go call execute('LspDocumentFormatSync')
63 nnoremap <Esc>d :LspDefinition<cr>
64 nnoremap <Esc>h :LspHover<cr>
65 nnoremap <Esc>rn :LspRename<cr>
66 nnoremap <Esc>rf :LspReference<cr>
67 nnoremap <Esc>ne :LspNextError<cr>
68 nnoremap <Esc>e :LspNextError<cr>
69 nnoremap <Esc>pe :LspPreviousError<cr>
70 nnoremap <Esc>ne :LspNextError<cr> " refer to doc to add more commands
73 " Bash like keys for the command line
80 " Use j/k to move virtual lines instead of physical ones
81 noremap <silent> <expr> j (v:count == 0 ? 'gj' : 'j')
82 noremap <silent> <expr> k (v:count == 0 ? 'gk' : 'k')
83 " Stay in visual mode when indenting. You will never have to run gv after
84 " performing an indentation.
88 " Make Ctrl-e jump to the end of the current line in the insert mode. This is
89 " handy when you are in the middle of a line and would like to go to its end
90 " without switching to the normal mode.
95 nnoremap <silent> <F4> :TlistToggle<CR>
96 let Tlist_Exist_OnlyWindow = 1 " if you are the last, kill yourself
97 "let Tlist_Use_Right_Window = 1 " split to the right side of the screen
98 let Tlist_GainFocus_On_ToggleOpen = 1 " Jump to taglist window on open.
99 let Tlist_File_Fold_Auto_Close = 1
102 " Hitting space in normal/visual mode will make the current search disappear.
103 noremap <silent> <Space> :silent nohlsearch<CR>
105 " Disable arrows keys (I use exclusively h/j/k/l).
109 noremap <Right> <Nop>
111 function! s:JoinWithoutSpaces()
113 " Remove any whitespace.
114 if matchstr(getline('.'), '\%' . col('.') . 'c.') =~ '\s'
118 noremap <silent> J :call <SID>JoinWithoutSpaces()<CR>
120 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
121 set nocompatible " Disable vi compatibility.
122 set undolevels=200 " Number of undo levels.
123 set ttyfast " Improves redrawing for newer computers.
124 set nobackup " Disable backup files.
125 set noswapfile " Disable swap files.
128 set splitright " Open new vertical panes in the right rather than left.
129 set splitbelow " Open new horizontal panes in the bottom rather than top.
131 set secure " Forbid loading of .vimrc under $PWD.
132 set nomodeline " Modelines have been a source of vulnerabilities.
134 set autoindent " Indent a new line according to the previous one.
135 set copyindent " Copy (exact) indention from the previous line.
136 set nopreserveindent " Do not try to preserve indention when indenting.
137 set nosmartindent " Turn off smartindent.
138 set nocindent " Turn off C-style indent.
139 set fo+=q " Allow formatting of comments with "gq".
140 set fo-=r fo-=o " Turn off automatic insertion of comment characters.
141 set fo+=j " Remove a comment leader when joining comment lines.
143 set gcr=n:blinkon0 " turn off blinking cursor
146 set tabstop=4 " Number of spaces a tab counts for.
147 set shiftwidth=4 " Number of spaces to use for each step of indent.
148 set shiftround " Round indent to multiple of shiftwidth.
149 set noexpandtab " Do not expand tab with spaces.
150 set path+=** " Enable recursive path
151 set wrapscan " Wrap search around
153 set go-=T " Hide the toolbar:
156 set hlsearch " Highlight search matches.
157 set incsearch " Incremental search.
158 " Case-smart searching (make /-style searches case-sensitive only if there
159 " is a capital letter in the search expression).
163 " Show trailing whitespace
164 match ErrorMsg '\s\+$'
166 " When editing a file, always jump to the last cursor position
168 \ if ! exists("g:leave_my_cursor_position_alone") |
169 \ if line("'\"") > 0 && line ("'\"") <= line("$") |
170 \ exe "normal g'\"" |
174 set statusline=%<%1*(%M%R)%f(%F)%=\ [%n]%1*%-19(%2*\ %03lx%02c(%p%%)\ %1*%)%O'%3*%02b%1*'
175 " now set it up to change the status line based on mode
176 au InsertEnter * hi User1 term=inverse,bold ctermbg=darkblue ctermfg=cyan guibg=#18163e guifg=grey
177 au InsertLeave * hi User1 term=inverse,bold ctermbg=cyan ctermfg=darkblue guibg=grey guifg=#0d0c22
179 " Toggle copy and paste modus with <F2>
180 nnoremap <F2> :set invpaste paste?<CR>
184 colorscheme vombatidae
185 " set color scheme for GUI mode
186 if has("gui_running")
187 set guifont=Monospace\ 10 " use this font
188 set lines=30 " height = 50 lines
189 set columns=100 " width = 100 columns
190 "set selectmode=key,cmd
194 " forget current search term
195 nmap <silent> <C-n> :noh<CR>
197 " rebuild cscope and tags db in current directory
198 map <C-X> <ESC>:!ectags -R<CR><CR>:!cscope -kcbqR<CR><CR>
199 map <C-Y> <ESC>:!ectags -R<CR><CR>
200 map <C-A> <ESC>:cs add ./cscope.out
202 set showmatch " Show matching brackets
203 set errorformat=%A%f:%l:\ %m,%-Z%p^,%-C%.%#
208 " set dark background
210 syntax on " Enable syntax highlighting
214 set spellfile=~/.vim/spellfile.add
215 set wildmenu " Enable wildmenu
216 " Ignore compiled files
217 set wildignore=*.o,*~,*.pyc,*/.git/*,*/.hg/*,*/.svn/*,*/.DS_Store
219 autocmd BufNewFile,BufRead COMMIT_EDITMSG set filetype=gitcommit
222 map <F6> <Esc>:setlocal spell spelllang=en<CR>
223 map <F7> <Esc>:setlocal nospell<CR>
224 setlocal spell spelllang=en
226 " Set utf8 as standard encoding and en_US as the standard language
229 " Disable highlight when <leader><cr> is pressed
230 map <silent> <leader><cr> :noh<cr>
232 " Absatz auf textwidth runterbrechen
234 " Ganzes Dokument auf textwidth runterbrechen
239 hi SpellBad term=reverse ctermfg=white ctermbg=darkred guifg=#ffffff guibg=#7f0000 gui=underline
240 "hi SpellCap guifg=#ffffff guibg=#7f007f
241 "hi SpellRare guifg=#ffffff guibg=#00007f gui=underline
242 hi SpellLocal term=reverse ctermfg=black ctermbg=darkgreen guifg=#ffffff guibg=#7f0000 gui=underline
244 " Rechtschreibkorrektur mit <esc>-l zwischen en und de umschalten
246 let spellst = ["de", "en"]
248 let g:langcnt = (g:langcnt+1) % len(g:spellst)
249 let lang = g:spellst[g:langcnt]
250 echo "language " . lang . " selected"
251 exe "set spelllang=" . lang
254 nmap <Esc>l :call Sel_lang()<CR>
255 " spell checking off by default
258 nmap <Esc>o :set bg=dark<CR>
259 nmap <Esc>p :set bg=light<CR>
261 " Use silver_searcher with Ack
263 let g:ackprg = 'ag --vimgrep'
268 autocmd BufNewFile,BufRead ferm.conf setf ferm
269 autocmd BufNewFile,BufRead *.ferm setf ferm
271 hi mailHeader ctermfg=Gray
272 hi mailSubject ctermfg=Red
273 hi mailEmail ctermfg=Blue
274 hi mailSignature ctermfg=DarkRed
275 hi mailQuoted1 ctermfg=Darkyellow
276 hi mailQuoted2 ctermfg=Green
278 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
281 " Show relative number
283 " Show the current line
287 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
289 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
290 " Jump to the previous/next tab.
293 " Close tabs with Ctrl + w
294 noremap <leader>w :tabclose<cr>
296 noremap <leader>s :w<cr>
298 noremap <leader>t :tabnew<cr>
300 noremap <leader>q :quitall<cr>