dotfiles

config files and scripts
git clone git://git.hanetzok.net/dotfiles
Log | Files | Refs

init.vim (4643B)


      1 let mapleader =" "
      2 
      3 if ! filereadable(system('echo -n "${XDG_CONFIG_HOME:-$HOME/.config}/nvim/autoload/plug.vim"'))
      4 	echo "Downloading junegunn/vim-plug to manage plugins..."
      5 	silent !mkdir -p ${XDG_CONFIG_HOME:-$HOME/.config}/nvim/autoload/
      6 	silent !curl "https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim" > ${XDG_CONFIG_HOME:-$HOME/.config}/nvim/autoload/plug.vim
      7 	autocmd VimEnter * PlugInstall
      8 endif
      9 
     10 map ,, :keepp /<++><CR>ca<
     11 imap ,, <esc>:keepp /<++><CR>ca<
     12 
     13 call plug#begin(system('echo -n "${XDG_CONFIG_HOME:-$HOME/.config}/nvim/plugged"'))
     14 Plug 'tpope/vim-surround'
     15 Plug 'preservim/nerdtree'
     16 Plug 'junegunn/goyo.vim'
     17 Plug 'jreybert/vimagit'
     18 Plug 'vimwiki/vimwiki'
     19 Plug 'vim-airline/vim-airline'
     20 Plug 'tpope/vim-commentary'
     21 Plug 'ap/vim-css-color'
     22 call plug#end()
     23 
     24 set title
     25 set bg=dark
     26 set go=a
     27 set mouse=a
     28 set nohlsearch
     29 set clipboard+=unnamedplus
     30 set noshowmode
     31 set noruler
     32 set laststatus=0
     33 set noshowcmd
     34 set tw=79
     35 set shiftwidth=2
     36 colorscheme elflord
     37 
     38 " ColorColumn
     39 nnoremap <leader>z :execute "set colorcolumn=" . (&colorcolumn == "" ? "80" : "")<CR>
     40 set colorcolumn=80
     41 highlight ColorColumn ctermbg=0 guibg=lightgrey
     42 
     43 " Some basics:
     44 	nnoremap c "_c
     45 	filetype plugin on
     46 	syntax on
     47 	set encoding=utf-8
     48 	set number relativenumber
     49 " Enable autocompletion:
     50 	set wildmode=longest,list,full
     51 " Disables automatic commenting on newline:
     52 	autocmd FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o
     53 " Perform dot commands over visual blocks:
     54 	vnoremap . :normal .<CR>
     55 " Goyo plugin makes text more readable when writing prose:
     56 	map <leader>f :Goyo \| set bg=dark \| set linebreak<CR>
     57 " Spell-check set to <leader>o, 'o' for 'orthography':
     58 	map <leader>o :setlocal spell! spelllang=de_de<CR>
     59 " Splits open at the bottom and right, which is non-retarded, unlike vim defaults.
     60 	set splitbelow splitright
     61 
     62 " Nerd tree
     63 	map <leader>q :NERDTreeToggle<CR>
     64 	autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
     65 	let NERDTreeBookmarksFile = stdpath('data') . '/NERDTreeBookmarks'
     66 
     67 " vim-airline
     68 	if !exists('g:airline_symbols')
     69 		let g:airline_symbols = {}
     70 	endif
     71 	let g:airline_symbols.colnr = ' C:'
     72 	let g:airline_symbols.linenr = ' L:'
     73 	let g:airline_symbols.maxlinenr = '☰ '
     74 
     75 " Shortcutting split navigation, saving a keypress:
     76 	map <C-h> <C-w>h
     77 	map <C-j> <C-w>j
     78 	map <C-k> <C-w>k
     79 	map <C-l> <C-w>l
     80 
     81 " Replace ex mode with gq
     82 	map Q gq
     83 
     84 " Check file in shellcheck:
     85 	map <leader>s :!clear && shellcheck -x %<CR>
     86 
     87 " Replace all is aliased to S.
     88 	nnoremap S :%s//g<Left><Left>
     89 
     90 " Compile document, be it groff/LaTeX/markdown/etc.
     91 	map <leader>c :w! \| !compiler "%:p"<CR>
     92 
     93 " Open corresponding .pdf/.html or preview
     94 	map <leader>p :!opout "%:p"<CR>
     95 
     96 " Runs a script that cleans out tex build files whenever I close out of a .tex file.
     97 	autocmd VimLeave *.tex !texclear %
     98 
     99 " Ensure files are read as what I want:
    100 	let g:vimwiki_ext2syntax = {'.Rmd': 'markdown', '.rmd': 'markdown','.md': 'markdown', '.markdown': 'markdown', '.mdown': 'markdown'}
    101 	map <leader>v :VimwikiIndex<CR>
    102 	let g:vimwiki_list = [{'path': '~/.local/share/nvim/vimwiki', 'syntax': 'markdown', 'ext': '.md'}]
    103 	autocmd BufRead,BufNewFile /tmp/calcurse*,~/.calcurse/notes/* set filetype=markdown
    104 	autocmd BufRead,BufNewFile *.ms,*.me,*.mom,*.man set filetype=groff
    105 	autocmd BufRead,BufNewFile *.tex set filetype=tex
    106 
    107 " Save file as sudo on files that require root permission
    108 	cabbrev w!! execute 'silent! write !sudo tee % >/dev/null' <bar> edit!
    109 
    110 " Automatically deletes all trailing whitespace and newlines at end of file on save. & reset cursor position
    111  	autocmd BufWritePre * let currPos = getpos(".")
    112 	autocmd BufWritePre * %s/\s\+$//e
    113 	autocmd BufWritePre * %s/\n\+\%$//e
    114   autocmd BufWritePre *.[ch] %s/\%$/\r/e " add trailing newline for ANSI C standard
    115   autocmd BufWritePre *neomutt* %s/^--$/-- /e " dash-dash-space signature delimiter in emails
    116   	autocmd BufWritePre * cal cursor(currPos[1], currPos[2])
    117 
    118 " Turns off highlighting on the bits of code that are changed, so the line that is changed is highlighted but the actual text that has changed stands out on the line and is readable.
    119 if &diff
    120     highlight! link DiffText MatchParen
    121 endif
    122 
    123 " Function for toggling the bottom statusbar:
    124 let s:hidden_all = 0
    125 function! ToggleHiddenAll()
    126     if s:hidden_all  == 0
    127         let s:hidden_all = 1
    128         set noshowmode
    129         set noruler
    130         set laststatus=0
    131         set noshowcmd
    132     else
    133         let s:hidden_all = 0
    134         set showmode
    135         set ruler
    136         set laststatus=2
    137         set showcmd
    138     endif
    139 endfunction
    140 nnoremap <leader>h :call ToggleHiddenAll()<CR>