Skip to content

Instantly share code, notes, and snippets.

@fladd
Last active March 7, 2021 21:42
Show Gist options
  • Save fladd/9ea7136426e90b3b7abd0bab3a2066c3 to your computer and use it in GitHub Desktop.
Save fladd/9ea7136426e90b3b7abd0bab3a2066c3 to your computer and use it in GitHub Desktop.
" Title: .vimrc
" Author: Florian Krause <[email protected]>
" Date: 2021-03-07
" " GLOBAL SETTINGS
"
if has('win32') || has ('win64')
let $VIMHOME = $HOME."/vimfiles"
else
let $VIMHOME = $HOME."/.vim"
endif
let truecolor = 0
" " GUI SETTINGS
"
if has("gui_running")
" Set the GUI font
if has("gui_gtk2")
set guifont=Monospace\ 10
elseif has("x11")
set guifont=*-lucidatypewriter-medium-r-normal-*-*-180-*-*-m-*-*
elseif has("gui_win32")
set guifont=Consolas:h11
set guioptions-=t
elseif has("gui_macvim")
try
set guifont=Source\ Code\ Pro:h13
catch
set guifont=Monaco:h13
endtry
endif
" Set line number amd cursorline
set number
set cursorline
" Misc
set lines=45
set columns=85
set guioptions-=T " No toolbar
let truecolor = 1
endif
" " GENERAL SETTINGS
"
set nocompatible
" " Remapping keys
inoremap fd <ESC>
nnoremap <F9> "=strftime("%a, %d %b %Y")<CR>P
inoremap <F9> <C-R>=strftime("%a, %d %b %Y")<CR>
nnoremap <F10> "=strftime("%H:%M%:%S")<CR>P
inoremap <F10> <C-R>=strftime("%H:%M:%S")<CR>
"let mapleader = "\<Space>"
inoremap <C-U> <C-G>u<C-U>
" " Plugins (vim-plug)
if empty(glob($VIMHOME . '/autoload/plug.vim'))
silent execute '!curl -fLo ' . $VIMHOME .
\ '/autoload/plug.vim --create-dirs ' .
\ '"https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim"'
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
"if !has("win32") && !has("win64")
" if empty(glob('~/.vim/autoload/plug.vim'))
" silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
" \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
" autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
" endif
"endif
" on Windows install with PowerShell:
"md ~\vimfiles\autoload
"$uri = 'https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
"(New-Object Net.WebClient).DownloadFile(
" $uri,
" $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath(
" "~\vimfiles\autoload\plug.vim"
" )
")
call plug#begin($VIMHOME.'/plugged')
Plug 'vimwiki/vimwiki'
Plug 'mattn/calendar-vim'
"Plug 'danielwe/base16-vim' "Plug 'chriskempson/base16-vim'
"Plug 'fladd/vim256-color'
"Plug 'nightsense/snow'
"Plug 'cormacrelf/vim-colors-github'
Plug 'romainl/Apprentice'
"Plug 'romainl/vim-dichromatic'
Plug 'lifepillar/vim-solarized8'
Plug 'lifepillar/vim-gruvbox8'
Plug 'ap/vim-css-color'
Plug 'Vimjas/vim-python-pep8-indent'
Plug 'tell-k/vim-autopep8'
call plug#end()
" " Turn on syntax highlighting and set the colours
if has('syntax') && !exists('g:syntax_on')
syntax enable
endif
" Enable true colors if terminal and Vim version support it
let colorterm=$COLORTERM
if has("termguicolors") && (colorterm =~# 'truecolor' || colorterm =~# '24bit')
set termguicolors
" Also set escape characters for true colors, if needed
if &term =~# '^screen'
let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
endif
let truecolor=1
endif
set background=dark
let g:solarized_enable_extra_hi_groups = 1
let g:solarized_old_cursor_style=1
let g:gruvbox_filetype_hi_groups = 1
let g:gruvbox_plugin_hi_groups = 1
if truecolor =~# 1
colorscheme gruvbox8 "solarized8
else
colorscheme gruvbox8 "solarized8
endif
" " Use modeline
set modeline
set modelines=5 " Check the upper 5 lines
" " Turn on autoindenting
set autoindent
set smartindent
" " Tabs are expanded to 4 spaces
set tabstop=4
set shiftwidth=4
set expandtab
set smarttab
" " Text is automatically wrapped after 79 lines
"set textwidth=79
set colorcolumn=79
set display+=lastline
" " Search behaviour
set incsearch
set hlsearch
" Use <C-L> to clear the highlighting of :set hlsearch.
if maparg('<C-L>', 'n') ==# ''
nnoremap <silent> <C-L> :nohlsearch<C-R>=has('diff')?'<Bar>diffupdate':''<CR><CR><C-L>
endif
" " Finding files
set path+=**
set wildmenu
" " File browsing
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 " tree view
let g:netrw_list_hide=netrw_gitignore#Hide()
" " Swap, backup, undo
if !isdirectory($VIMHOME.'/swap')
silent call mkdir ($VIMHOME.'/swap', 'p')
endif
if !isdirectory($VIMHOME.'/backup')
silent call mkdir ($VIMHOME.'/backup', 'p')
endif
if !isdirectory($VIMHOME.'/undo')
silent call mkdir ($VIMHOME.'/undo', 'p')
endif
let $VIMSWAPDIR = $VIMHOME.'/swap//'
let $VIMBACKUPDIR = $VIMHOME.'/backup//'
let $VIMUNDODIR = $VIMHOME.'/undo//'
" protect changes between writes.
set swapfile
set directory^=$VIMSWAPDIR
" protect against crash-during-write
set writebackup
" but do not persist backup after successful write
set nobackup
" use rename-and-write-new method whenever safe
set backupcopy=auto
" patch required to honor double slash at end
if has("patch-8.1.0251")
" consolidate the writebackups -- not a big
" deal either way, since they usually get deleted
set backupdir^=$VIMBACKUPDIR
end
" persist the undo tree for each file
set undofile
set undodir^=$VIMUNDODIR
" " Misc
set ruler
set showcmd
set laststatus=2 " Always show status line
set backspace=indent,eol,start
set autochdir " Change working directory to directory of current file
set scrolloff=1
set sidescrolloff=5
set nrformats-=octal
if has('mouse')
set mouse=a
endif
if &encoding ==# 'latin1' && has('gui_running')
set encoding=utf-8
endif
if &listchars ==# 'eol:$'
set listchars=tab:>\ ,trail:-,extends:>,precedes:<,nbsp:+
endif
if v:version > 703 || v:version == 703 && has("patch541")
set formatoptions+=j " Delete comment character when joining commented lines
endif
" Load matchit.vim, but only if the user hasn't installed a newer version.
if !exists('g:loaded_matchit') && findfile('plugin/matchit.vim', &rtp) ==# ''
runtime! macros/matchit.vim
endif
" Convenient command to see the difference between the current buffer and the
" file it was loaded from, thus the changes you made.
" Only define it when not defined already.
" Revert with: ":delcommand DiffOrig".
if !exists(":DiffOrig")
command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis
\ | wincmd p | diffthis
endif
" Get highlight group under cursor
function! Syn()
for id in synstack(line("."), col("."))
echo synIDattr(id, "name")
endfor
endfunction
command! -nargs=0 Syn call Syn()
" Create a scratch buffer
function! MakeScratchBuffer(...)
if a:0 > 0
let n = a:1 . ' [SCRATCH]'
else
let n = '[No Name] [SCRATCH]'
end
execute 'tabnew' n
setlocal buftype=nofile
setlocal bufhidden=hide
setlocal noswapfile
endfunction
command! -nargs=? Scratch call MakeScratchBuffer(<f-args>)
" " SPECIFIC SETTINGS
"
" " Python
"au BufNewFile,BufRead *.py,*pyw set filetype=python
"autocmd FileType python set omnifunc=pythoncomplete#Complete
"au FileType python map <f5> :w\|!ipython -c %run %
let g:python_highlight_all=1
"au FileType python let g:python_highlight_all=1
au FileType python syn keyword pythonStatement class nextgroup=pythonClass skipwhite
au FileType python syn match pythonClass "[a-zA-Z_][a-zA-Z0-9_]*" display contained
au FileType python hi link pythonClass Type
au FileType python syn clear pythonAttribute
"au FileType python syn keyword pythonBuiltinObj self
"au FileType python set foldmethod=indent
":au BufWritePre *.py exe "norm mz"|exe '%s/\(__date__ = \).*/\1'''.strftime("%c'")."/e"|norm `z
"au FileType python let g:pymode_rope_lookup_project = 0
"au FileType python let g:pymode_rope_completion = 1
"au FileType python let g:pymode_rope_complete_on_dot = 1
" " Markdown
let g:markdown_fenced_languages = ['html', 'python', 'bash=sh']
let g:markdown_minlines = 100
" " VimWiki
au FileType vimwiki set syntax=markdown
let g:vimwiki_list = [{'path': '~/Dropbox/vimwiki/work/', 'syntax': 'markdown', 'ext': '.md'},
\{'path': '~/Dropbox/vimwiki/personal/', 'syntax': 'markdown', 'ext': '.md'}]
let g:vimwiki_folding='expr'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment