From 7acf8f37600ee86fa41673ffebc4478cc8c9e80b Mon Sep 17 00:00:00 2001 From: Valentin Brandl Date: Sat, 11 Feb 2017 11:06:28 +0100 Subject: [PATCH] Initial commit. Adding vim configuration --- .gitmodules | 4 + editors/vim/README.md | 4 + editors/vim/autoload/functions.vim | 61 +++++ editors/vim/bundle/Vundle.vim | 1 + editors/vim/plugins.vim | 48 ++++ editors/vim/vimrc | 355 +++++++++++++++++++++++++++++ 6 files changed, 473 insertions(+) create mode 100644 .gitmodules create mode 100644 editors/vim/README.md create mode 100644 editors/vim/autoload/functions.vim create mode 160000 editors/vim/bundle/Vundle.vim create mode 100644 editors/vim/plugins.vim create mode 100644 editors/vim/vimrc diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..68d68a4 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,4 @@ +[submodule "editors/vim/bundle/Vundle.vim"] + path = editors/vim/bundle/Vundle.vim + url = git@github.com:VundleVim/Vundle.vim.git + branch = master diff --git a/editors/vim/README.md b/editors/vim/README.md new file mode 100644 index 0000000..a3f8c1b --- /dev/null +++ b/editors/vim/README.md @@ -0,0 +1,4 @@ +# vim configuration + +* use gvim to make yanking in the systemclipboard working +> vim: set filetype=markdown ts=4 sw=4 tw=120 noet : diff --git a/editors/vim/autoload/functions.vim b/editors/vim/autoload/functions.vim new file mode 100644 index 0000000..36ab790 --- /dev/null +++ b/editors/vim/autoload/functions.vim @@ -0,0 +1,61 @@ +" Window movement shortcuts +" move to the window in the direction shown, or create a new window +function! functions#WinMove(key) + let t:curwin = winnr() + exec "wincmd ".a:key + if (t:curwin == winnr()) + if (match(a:key,'[jk]')) + wincmd v + else + wincmd s + endif + exec "wincmd ".a:key + endif +endfunction + +" smart tab completion +function! functions#Smart_TabComplete() + let line = getline('.') " current line + + let substr = strpart(line, -1, col('.')+1) " from the start of the current + " line to one character right + " of the cursor + let substr = matchstr(substr, '[^ \t]*$') " word till cursor + if (strlen(substr)==0) " nothing to match on empty string + return '\' + endif + let has_period = match(substr, '\.') != -1 " position of period, if any + let has_slash = match(substr, '\/') != -1 " position of slash, if any + if (!has_period && !has_slash) + return '\\' " existing text matching + elseif ( has_slash ) + return '\\' " file matching + else + return '\\' " plugin matching + endif +endfunction + +" execute a custom command +function! functions#RunCustomCommand() + up + if g:silent_custom_command + execute 'silent !' . s:customcommand + else + execute '!' . s:customcommand + endif +endfunction + +function! functions#SetCustomCommand() + let s:customcommand = input('Enter Custom Command$ ') +endfunction + +function! functions#TrimWhiteSpace() + %s/\s\+$//e +endfunction + +function! functions#HtmlUnEscape() + silent s/<//eg + silent s/&/\&/eg +endfunction + diff --git a/editors/vim/bundle/Vundle.vim b/editors/vim/bundle/Vundle.vim new file mode 160000 index 0000000..88688fe --- /dev/null +++ b/editors/vim/bundle/Vundle.vim @@ -0,0 +1 @@ +Subproject commit 88688fe453038ac1ac26e31646cfbec50fca2fb7 diff --git a/editors/vim/plugins.vim b/editors/vim/plugins.vim new file mode 100644 index 0000000..752c553 --- /dev/null +++ b/editors/vim/plugins.vim @@ -0,0 +1,48 @@ +call vundle#begin() + +" vundle needs to handle itself +Plugin 'VundleVim/Vundle.vim' + +Plugin 'vim-airline/vim-airline' +Plugin 'vim-airline/vim-airline-themes' + +" colorschemes +" Plug 'dracula/vim' +Plugin 'joshdick/onedark.vim' + +Plugin 'editorconfig/editorconfig-vim' + +Plugin 'w0rp/ale' " syntax checking +Plugin 'ervandew/supertab' +Plugin 'tpope/vim-commentary' +Plugin 'tpope/vim-surround' +Plugin 'vim-scripts/ReplaceWithRegister' +Plugin 'mattn/vim-maketable' " create tables from selection +Plugin 'dhruvasagar/vim-table-mode' " handle tables +Plugin 'mattn/webapi-vim' " web api +Plugin 'mattn/gist-vim' " create gist from within vim +Plugin 'michaeljsmith/vim-indent-object' " indent as textobject +Plugin 'Raimondi/delimitMate' " autoclose quotes and brackets +"Plugin 'SirVer/ultisnips' " snippets +Plugin 'tpope/vim-fugitive' +Plugin 'scrooloose/nerdtree', { 'on': ['NERDTreeToggle', 'NERDTreeFind'] } | Plugin 'Xuyuanp/nerdtree-git-plugin' | Plugin 'ryanoasis/vim-devicons' +Plugin 'ctrlpvim/ctrlp.vim' +Plugin 'neomake/neomake' +Plugin 'benmills/vimux' +Plugin 'AndrewRadev/splitjoin.vim' +Plugin 'tpope/vim-sleuth' " autodetect indent style (tabs vs. spaces) +Plugin 'sickill/vim-pasta' " context aware pasting +Plugin 'elzr/vim-json' " JSON support +Plugin 'davidhalter/jedi-vim' " python autocomplete +Plugin 'junegunn/goyo.vim' " distraction free writing + +" Rust plugins +Plugin 'racer-rust/vim-racer' " rust autocomplete +Plugin 'rust-lang/rust.vim' " rust syntax, error checking, etc + +" LaTeX +Plugin 'lervag/vimtex' + +call vundle#end() + +" vim: set filetype=vim ts=4 sw=4 tw=120 noet : diff --git a/editors/vim/vimrc b/editors/vim/vimrc new file mode 100644 index 0000000..c4d7dd3 --- /dev/null +++ b/editors/vim/vimrc @@ -0,0 +1,355 @@ +" vundle +" set vIM mode +set nocompatible +filetype off +set rtp+=~/.vim/bundle/Vundle.vim + +source ~/.vim/plugins.vim + +filetype plugin indent on + +" Get the defaults that most users want. +source $VIMRUNTIME/defaults.vim + +if has("vms") + set nobackup +else + " set backup + if has('persistent_undo') + set undofile + endif +endif + +" encrypt files using blowfish +set cryptmethod=blowfish2 + +syntax on +colorscheme onedark + +" files and backups +" set backupdir=~/.vim-tmp,~/.tmp,~/tmp,/var/tmp,/tmp +" set directory=~/.vim-tmp,~/.tmp,~/tmp,/var/tmp,/tmp +set directory=$HOME/.vim/swapfiles// +" set backupdir=$HOME/.vim/backupdir// +set undodir=$HOME/.vim/undofiles// + +set clipboard=unnamedplus " yank into system clipboard +" Only do this part when compiled with support for autocommands. +if has("autocmd") + + " Put these in an autocmd group, so that we can delete them easily. + augroup vimrcEx + au! + + " For all text files set 'textwidth' to 78 characters. + autocmd FileType text setlocal textwidth=78 + + augroup END + + " remember curser position + autocmd BufReadPost * + \ if line("'\"") > 1 && line("'\"") <= line("$") | + \ exe "normal! g`\"" | + \ endif + +endif " has("autocmd") + +" Add optional packages. +" +" The matchit plugin makes the % command work better, but it is not backwards +" compatible. +if has('syntax') && has('eval') + packadd matchit +endif + +set autoindent " always set autoindenting on +set smartindent " smart indent; stop indent when closing brackets etc + +" searching +set hlsearch " highlight search result +set ignorecase " ignore case +set smartcase " case-sensitive if expression contains capital letters +set incsearch " incremental search +set nolazyredraw + +" delete whitespace, line break and char using +set backspace=indent,eol,start +set ruler " always show curser position +set history=1000 " keep 1000 lines of history +" set textwidth=120 +set number " display absolute number of current line +set relativenumber " display relative line numbers +" encoding +set fileencoding=utf-8 +" break at last word instead of last char +set linebreak + +" tab control +set noexpandtab " insert tabs +set smarttab +set tabstop=4 +set softtabstop=4 +set shiftwidth=4 +set shiftround +set completeopt+=longest + +" invisible characters +set list +set listchars=tab:→\ ,eol:¬,trail:⋅,extends:❯,precedes:❮ +set showbreak=↪ + +" code folding settings +set foldmethod=syntax " fold based on indent +set foldnestmax=10 " deepest fold is 10 levels +set nofoldenable " don't fold by default +set foldlevel=1 + +set ttyfast " faster redrawing +set diffopt+=vertical +set laststatus=2 " show the status line all the time +set so=7 " set 7 lines to the cursors - when moving vertical +set wildmenu " enhanced command line completion +" Search down into subfolders +" Provides tab-completion for all file-related tasks +set path+=** +set hidden " current buffer can be put into background +set showcmd " show incomplete commands +set noshowmode " don't show which mode disabled for PowerLine +set wildmode=list:longest " complete files like a shell +set scrolloff=3 " lines of text around cursor +set shell=$SHELL +set cmdheight=1 " command bar height +set title " set terminal title + +set magic " set magic on, for regex + +set showmatch " show matching braces +set mat=2 " how many tenths of a second to blink +set complete +=kspell " autocomplete from the dictionary when spellchecking is enabled +set spelllang=de,en " set spell langs + +" user commands + +" create tags file +" ^] jump to tag under cursor +" g^] for ambiguous tags +" ^t jump back in the tag stack +command! MakeTags !ctags -R . + +" error bells +set noerrorbells +set visualbell +set t_vb= +set tm=500 + +" turn on manpages (:Man) +runtime ftplugin/man.vim + +" make comments and HTML attributes italic +highlight Comment cterm=italic +highlight htmlArg cterm=italic + +" set a map leader for more key combos +let mapleader = ',' + +" clear highlighted search +" nnoremap :set hlsearch! hlsearch? +noremap :nohlsearch + +" enable . command in visual mode +vnoremap . :normal . + +map :call functions#WinMove('h') +map :call functions#WinMove('j') +map :call functions#WinMove('k') +map :call functions#WinMove('l') + +" count wraped lines as one line when doing relative jumps +noremap j (v:count == 0 ? 'gj' : 'j') +noremap k (v:count == 0 ? 'gk' : 'k') + +" scroll the viewport faster +nnoremap 3 +nnoremap 3 + +" moving up and down work as you would expect +nnoremap j gj +nnoremap k gk +nnoremap ^ g^ +nnoremap $ g$ + +" cool resizing +nnoremap :vertical resize +2 +nnoremap :vertical resize -2 +nnoremap :resize -2 +nnoremap :resize +2 + +" search for word under the cursor +nnoremap / "fyiw :/f + +" helpers for dealing with other people's code +nmap \t :set ts=4 sts=4 sw=4 noet +nmap \s :set ts=4 sts=4 sw=4 et + +" highlight conflicts +match ErrorMsg '^\(<\|=\|>\)\{7\}\([^=].\+\)\?$' + +" make the highlighting of tabs and other non-text less annoying +highlight SpecialKey ctermbg=none ctermfg=8 +highlight NonText ctermbg=none ctermfg=8 + +" Section AutoGroups {{{ +" file type specific settings +augroup configgroup + autocmd! + + " automatically resize panes on resize + autocmd VimResized * exe 'normal! \=' + autocmd BufWritePost .vimrc,.vimrc.local,init.vim source % + autocmd BufWritePost .vimrc.local source % + " save all files on focus lost, ignoring warnings about untitled buffers + autocmd FocusLost * silent! wa + + " make quickfix windows take all the lower section of the screen + " when there are multiple windows open + autocmd FileType qf wincmd J + + autocmd BufNewFile,BufReadPost *.md set filetype=markdown + let g:markdown_fenced_languages = ['css', 'javascript', 'js=javascript', 'json=javascript', 'stylus', 'html'] + + " autocmd! BufEnter * call functions#ApplyLocalSettings(expand(':p:h')) + + autocmd BufNewFile,BufRead,BufWrite *.md syntax match Comment /\%^---\_.\{-}---$/ + + autocmd! BufWritePost * Neomake +augroup END + +" }}} + +" detect filetypes, use filetype plugins and autoindent +filetype plugin indent on + + +" paste without indention +function! WrapForTmux(s) + if !exists('$TMUX') + return a:s + endif + + let tmux_start = "\Ptmux;" + let tmux_end = "\\\" + + return tmux_start . substitute(a:s, "\", "\\", 'g') . tmux_end +endfunction + +let &t_SI .= WrapForTmux("\[?2004h") +let &t_EI .= WrapForTmux("\[?2004l") + +function! XTermPasteBegin() + set pastetoggle=[201~ + set paste + return "" +endfunction + +inoremap [200~ XTermPasteBegin() + +" ctrlp +set runtimepath^=~/.vim/bundle/ctrlp.vim + +" make true colors in tmux work +" set t_8f=[38;2;%lu;%lu;%lum +" set t_8b=[48;2;%lu;%lu;%lum +" true color +set termguicolors +let &t_8f = "\[38;2;%lu;%lu;%lum" +let &t_8b = "\[48;2;%lu;%lu;%lum" + +highlight Normal ctermbg=NONE guibg=NONE +highlight NonText ctermbg=NONE guibg=NONE + +" airline options +if !exists('g:airline_symbols') + let g:airline_symbols = {} +endif +let g:airline_powerline_fonts=1 +let g:airline_left_sep = '' +let g:airline_left_alt_sep = '' +let g:airline_right_sep = '' +let g:airline_right_alt_sep = '' +let g:airline_theme='onedark' +let g:airline_symbols.branch = '' +let g:airline_symbols.readonly = '' +let g:airline_symbols.linenr = '' +let g:airline#extensions#tabline#enabled = 1 " enable airline tabline +let g:airline#extensions#tabline#tab_min_count = 2 " only show tabline if tabs are being used (more than 1 tab open) +let g:airline#extensions#tabline#show_buffers = 0 " do not show open buffers in tabline +let g:airline#extensions#tabline#show_splits = 0 + +" Toggle NERDTree +nmap k :NERDTreeToggle +" expand to the path of the file in the current buffer +nmap y :NERDTreeFind +" autocmd BufWinEnter * NERDTreeMirror + +let NERDTreeShowHidden=1 +let NERDTreeDirArrowExpandable = '▷' +let NERDTreeDirArrowCollapsible = '▼' + +" Append modeline after last line in buffer. +" Use substitute() instead of printf() to handle '%%s' modeline in LaTeX +" files. +function! AppendModeline() + let l:modeline = printf(" vim: set filetype=%s ts=%d sw=%d tw=%d %set :", + \ &filetype, &tabstop, &shiftwidth, &textwidth, &expandtab ? '' : 'no') + let l:modeline = substitute(&commentstring, "%s", l:modeline, "") + call append(line("$"), l:modeline) +endfunction +nnoremap ml :call AppendModeline() + +" delimate config +let delimitMate_expand_cr = 1 + +" set textwidth for mails +" au BufRead /tmp/mutt-* set tw=72 +autocmd FileType mail setlocal textwidth=72 + +" netrw settings +" (vim builtin filebrowser which ist also just a plugin bundled with vim) +let g:netrw_banner = 0 " disable banner +let g:netrw_browse_split= 4 " open in prior window +let g:netrw_altv = 1 " open splits to the right +let g:netrw_liststyle = 3 " treeview +let g:netrw_list_hide = netrw_gitignore#Hide() +let g:netrw_list_hide .= ',\(^\|\s\s\)\zs\.\S\+' + +" racer config (rust autocomplete) +let g:racer_cmd = "/home/me/.cargo/bin/racer" +let g:racer_experimental_completer = 1 +au FileType rust nmap gd (rust-def) +au FileType rust nmap gs (rust-def-split) +au FileType rust nmap gx (rust-def-vertical) +au FileType rust nmap gd (rust-doc) + +" close Goyo *and* vim with :q +function! s:goyo_enter() + let b:quitting = 0 + let b:quitting_bang = 0 + autocmd QuitPre let b:quitting = 1 + cabbrev q! let b:quitting_bang = 1 q! +endfunction + +function! s:goyo_leave() + " Quit Vim if this is the only remaining buffer + if b:quitting && len(filter(range(1, bufnr('$')), 'buflisted(v:val)')) == 1 + if b:quitting_bang + qa! + else + qa + endif + endif +endfunction + +autocmd! User GoyoEnter call goyo_enter() +autocmd! User GoyoLeave call goyo_leave() + +" vim: set filetype=vim ts=8 sw=2 tw=120 noet :