This repository has been archived on 2019-01-25. You can view files and clone it, but cannot push or open issues or pull requests.
neostrophic/neostrophic.vim

380 lines
9.9 KiB
VimL

" mikroskeem's neovim config
" Toggle preview
function! s:preview_toggle()
if &completeopt =~# "preview"
setlocal completeopt-=preview
pc
silent execute "!echo -n Preview turned off"
else
setlocal completeopt+=preview
silent execute "!echo -n Preview turned on"
endif
endfunction
" Fake $MYVIMRC
function! s:fake_vimrc()
let $MYVIMRC=$HOME . "/.config/nvim/init.vim"
endfunction
" UpdateRemotePlugins wrapper (used in vim-plug)
function! URP(info)
if a:info.status == 'installed'
silent! call s:fake_vimrc()
silent! UpdateRemotePlugins
endif
endfunction
" Center text (for vim startify)
function! s:center_header(lines) abort
let longest_line = max(map(copy(a:lines), 'len(v:val)'))
let centered_lines = map(copy(a:lines),
\ 'repeat(" ", (&columns / 2) - (longest_line / 2)) . v:val')
return centered_lines
endfunction
" mkdir -p
function! s:mkdir_p(p)
if !isdirectory(expand(a:p))
call mkdir(expand(a:p), "p")
endif
endfunction
" Custom indendations
function! s:set_indent()
if &ft =~ 'yaml\|coffee\|vim\|jade'
set softtabstop=4 shiftwidth=4
endif
if &ft =~ 'make'
set shiftwidth=2 tabstop=2 noexpandtab
endif
endfunction
function! s:read_clangflags()
return split(join(readfile(getcwd() . "/.clang_complete"), "\n"))
endfunction
" --- Start
if(!has("python3"))
echo "You should install python neovim module. `pip install neovim`"
exec "qall"
end
" Plugins
call plug#begin('~/.config/nvim/neostrophic_plugins')
" --- Completion and syntax check engine
Plug 'Shougo/deoplete.nvim', {'do': function('URP')}
Plug 'neomake/neomake'
Plug 'ervandew/supertab'
Plug 'Shougo/echodoc.vim'
" --- Syntax and completion engine components
Plug 'Shougo/context_filetype.vim'
Plug 'Shougo/unite.vim'
Plug 'Shougo/vimproc.vim', {'do' : 'make'}
" C++
Plug 'Rip-Rip/clang_complete', {'for': ['c', 'cpp']}
Plug 'octol/vim-cpp-enhanced-highlight'
" Python
Plug 'zchee/deoplete-jedi', {'for': 'python'}
Plug 'jmcantrell/vim-virtualenv'
" Vimscript
Plug 'Shougo/neco-vim', {'for': 'vim'}
Plug 'Shougo/neco-syntax', {'for': 'vim'}
" JSON
Plug 'elzr/vim-json', {'for': 'json'}
" Java
"Plug 'artur-shaik/vim-javacomplete2', {'for': 'java'}
" Markdown
Plug 'gabrielelana/vim-markdown'
" Misc
Plug 'vim-scripts/nginx.vim', {'for': 'nginx'}
Plug 'Matt-Deacalion/vim-systemd-syntax', {'for': 'systemd'}
Plug 'PotatoesMaster/i3-vim-syntax', {'for': 'i3'}
" --- Git
Plug 'airblade/vim-gitgutter'
Plug 'tpope/vim-fugitive'
" --- Themes
"Plug 'crater2150/vim-theme-chroma'
Plug 'justinmk/molokai'
" --- Workflow
" Startup screen
Plug 'mhinz/vim-startify'
" Remove trailing whitespace
Plug 'thirtythreeforty/lessspace.vim'
" Automatic pathenses
Plug 'jiangmiao/auto-pairs'
" Undo tree
Plug 'sjl/gundo.vim'
" Status line
Plug 'itchyny/lightline.vim'
" Pathenses
Plug 'luochen1990/rainbow'
" Indendation aids
Plug 'Yggdroot/indentLine'
Plug 'godlygeek/tabular'
" Distraction-free
Plug 'junegunn/goyo.vim', {'on': 'Goyo'}
Plug 'junegunn/limelight.vim', {'on': 'Limelight'}
call plug#end()
" Apply color scheme
colorscheme molokai
" --- Neovim options
set updatetime=250
set wildmode=longest,list,full
set shortmess+=cI
set noshowmode
set nostartofline
set wrap
set textwidth=0
set wrapmargin=0
" Our leader is comma
let mapleader = ","
" Show line numbers
set number
set numberwidth=3
" Disable preview by default, because it is annoying imo
set completeopt-=preview
" Use X11 clipboard and set up other display related settings
if $DISPLAY != ''
set clipboard+=unnamedplus
set mouse+=a
endif
" Search options
set showmatch
set smartcase
set ignorecase
" Backup, undo and viminfo
set backup
set undofile
set undoreload=100
set viminfo+=n$HOME/.config/nvim/tmp/viminfo
set backupdir=$HOME/.config/nvim/tmp/backup/
set undodir=$HOME/.config/nvim/tmp/undo/
set directory=$HOME/.config/nvim/tmp/swap/
" Create missing directories
silent! call s:mkdir_p(&undodir)
silent! call s:mkdir_p(&backupdir)
silent! call s:mkdir_p(&directory)
set title
set cursorline
set showtabline=0
" Terminal tweaks
function! s:on_terminal_open()
setlocal nocursorline
endfunction
autocmd TermOpen * nested call <SID>on_terminal_open()
" Default indendation settings
set softtabstop=4
set shiftwidth=4
set expandtab
set shiftround
set autoindent
set copyindent
" Function call below overrides previous options
" if opened filetype was defined in function
autocmd! FileType * call s:set_indent()
" Neovim python
" Note: Read https://github.com/zchee/deoplete-jedi#virtual-environments
let g:python_host_prog = '/usr/bin/python2'
let g:python3_host_prog = '/usr/bin/python3'
" --- Plugin configurations
" Deoplete and echodoc
let g:deoplete#enable_at_startup = 1
let g:deoplete#enable_camel_case = 1
let g:echodoc_enable_at_startup = 1
" Rainbow
let g:rainbow_active = 1
let g:rainbow_conf = {'ctermfgs': ['red', 'lightgreen', 'lightred', 'lightblue', 'yellow']}
" Gitgutter
let g:gitgutter_map_keys = 0
let g:gitgutter_highlight_lines = 0
" indentLine
let g:indentLine_char = '┆'
" Startify
let g:startify_session_dir = '~/.config/nvim/startify-session'
let g:startify_custom_header = s:center_header(map(split(system('fortune | cowsay'), '\n'), '" ". v:val') + ['',''])
" Neomake
let g:neomake_makeclean_maker = { 'exe': 'make', 'args': ['clean'] }
autocmd! BufReadPost * Neomake
autocmd! BufWritePost * Neomake
" Lightline
let g:lightline_buffer_readonly_icon = 'R'
let g:lightline_buffer_modified_icon = '+'
let g:lightline_buffer_active_buffer_left_icon = '['
let g:lightline_buffer_active_buffer_right_icon = ']'
let g:lightline_buffer_separator_icon = ''
let g:lightline_buffer_show_bufnr = 0
let g:lightline_buffer_rotate = 0
let g:lightline_buffer_fname_mod = ':t'
let g:lightline_buffer_excludes = ['vimfiler']
let g:lightline_buffer_maxflen = 30
let g:lightline_buffer_maxfextlen = 3
let g:lightline_buffer_minflen = 16
let g:lightline_buffer_minfextlen = 3
let g:lightline_buffer_reservelen = 20
let g:lightline = {
\ 'active': {
\ 'left': [['mode', 'paste'], ['filename', 'readonly', 'modified', 'fugitive']],
\ },
\ 'component_function': {
\ 'fugitive': 'LlFugitive',
\ },
\ 'separator': { 'left': '>', 'right': '<' },
\ 'subseparator': { 'left': '>', 'right': '<' }
\ }
function! LlFugitive()
return exists('*fugitive#head') ? fugitive#head() : ''
endfunction
" Goyo & Lightline
function! s:on_goyo_enter()
setlocal nocursorline
Limelight
endfunction
function! s:on_goyo_leave()
setlocal cursorline
Limelight!
endfunction
autocmd! User GoyoEnter nested call <SID>on_goyo_enter()
autocmd! User GoyoLeave nested call <SID>on_goyo_leave()
" Markdown
let g:markdown_include_jekyll_support = 0
" Own Unite menu
" Thanks to: http://vi.stackexchange.com/a/591
if !exists('g:unite_source_menu_menus')
let g:unite_source_menu_menus = {}
endif
let g:unite_source_menu_menus.neostrophic_menu = {'description': 'Neostrophic menu'}
function! g:unite_source_menu_menus.neostrophic_menu.map(key, value)
return {
\ 'word': a:key,
\ 'kind': 'command',
\ 'action__command': a:value
\ }
endfunction
let g:unite_source_menu_menus.neostrophic_menu.command_candidates = [
\ ['▷ Neomake: make clean <none>', 'Neomake! makeclean'],
\ ['▷ Neostrophic: grep for TODOs <none>', 'grep TODO'],
\ ['▷ Git: preview hunk ,hp', 'GitGutterPreviewHunk'],
\ ['▷ Git: stage hunk <none>', 'GitGutterStageHunk'],
\ ['▷ Git: undo hunk ,hr', 'GitGutterUndoHunk'],
\ ['▷ Git: move to next changed hunk <none>', 'GitGutterNextHunk'],
\ ['▷ Git: move to previous changed hunk ,hr', 'GitGutterPrevHunk'],
\ ['▷ Git: blame <none>', 'Gblame'],
\ ['▷ Git: pull <none>', 'Gpull'],
\ ['▷ Git: diff <none>', 'Gdiff'],
\ ['▷ Git: status <none>', 'Gstatus'],
\ ['▷ Undo: show tree F6', 'GundoToggle'],
\ ['▷ Goyo: toggle F8', 'Goyo'],
\]
nnoremap <Leader>m :Unite menu:neostrophic_menu -start-insert -ignorecase<CR>
" SuperTab
let g:SuperTabDefaultCompletionType = "<c-n>"
" LessSpace
let g:lessspace_blacklist = ['markdown']
" Neomake
let s:default_clang_args = ['-std=c++14', '-fsyntax-only', '-Wall', '-Wextra']
let g:neomake_cpp_clang_maker = {
\'args': s:default_clang_args
\ }
let g:neomake_cpp_enabled_makers = ['clang']
function! s:build_clang_args()
if filereadable(getcwd() . "/.clang_complete")
" Read flags
let newflags = s:default_clang_args + s:read_clangflags()
" Build list with no duplicates for sure
let g:neomake_cpp_clang_maker.args = filter(copy(newflags), 'index(newflags, v:val, v:key+1)==-1')
endif
endfunction
autocmd! FileType cpp nested call s:build_clang_args()
" --- Keymaps
" Commonly used commands
nnoremap <silent> <C-z> :u<CR>
nnoremap <silent> <C-o> :w<CR>
nnoremap <silent> <C-x> :q<CR>
nnoremap <silent> <C-A-x> :q!<CR>
nnoremap <silent> <C-A-a> :noh<CR>
nnoremap <silent> <Leader>p :call <SID>preview_toggle()<CR>
" F-line
nnoremap <F5> :so %<CR>
nnoremap <F6> :GundoToggle<CR>
nnoremap <F7> :term<CR>
nnoremap <F8> :Goyo<CR>
" Git
nmap <Leader>hr <Plug>GitGutterUndoHunk
nmap <Leader>hp <Plug>GitGutterPreviewHunk
" Shut up annoying stuff
nnoremap <silent> <C-A-f> :SyntasticToggleMode<CR>
nnoremap <silent> <Leader>p :call <SID>preview_toggle()<CR>
" Increase/decrease numbers with Alt key and A/X
nnoremap <A-a> <C-a>
nnoremap <A-x> <C-x>
" Terminal
tnoremap <A-q> <C-\><C-n>