227 lines
6.9 KiB
VimL

"Many ideas from https://github.com/nicknisi/dotfiles/blob/master/config/nvim/init.vim
"https://github.com/mhartington/dotfiles/blob/master/vimrc
"and https://dougblack.io/words/a-good-vimrc.html
" Plugins
call plug#begin('~/.config/nvim/plugged')
Plug 'NLKNguyen/papercolor-theme' " PaperColor Theme (old: [vim-colors-solarized])
Plug 'itchyny/lightline.vim'
Plug 'scrooloose/nerdtree' " file tree browser
Plug 'ctrlpvim/ctrlp.vim' " fuzzy file finder
Plug 'bronson/vim-trailing-whitespace'
Plug 'ryanoasis/vim-devicons' " awesome icons
Plug 'tiagofumo/vim-nerdtree-syntax-highlight'
Plug 'ashisha/image.vim' " Display images in vim
Plug 'Yggdroot/indentLine' " Display indent line
Plug 'neomake/neomake' " asynchronous make functionality :NeoMake!
Plug 'Shougo/deoplete.nvim' " autocomplete function
"Plug 'Shougo/neocomplcache.vim'
"Plug 'terryma/vim-multiple-cursors' "Sublime multiple cursor support
Plug 'Shougo/neosnippet.vim' " snippet manager
Plug 'Shougo/neosnippet-snippets' " default snippets
Plug 'Raimondi/delimitMate' " automatic closing of quotes, parenthesis, brackets, etc.
Plug 'tpope/vim-commentary' " comment stuff out
Plug 'tpope/vim-ragtag' " endings for html, xml, etc. - ehances surround
Plug 'tpope/vim-surround' " mappings to easily delete, change and add such
Plug 'tpope/vim-fugitive' " Git support
Plug 'airblade/vim-gitgutter' " show git diff in gutter
" surroundings in pairs, such as quotes, parens, etc.
Plug 'simnalamburt/vim-mundo' " undo tree visualizer DOESN'T WORK ATM
"Plug 'junegunn/limelight.vim', { 'on': 'Limelight' } " focus tool. Dim text. Good for presentating with vim
"language-specific plugins
" html
Plug 'gregsexton/MatchTag' "highlight the current tag
" latex
Plug 'lervag/vimtex'
call plug#end()
" Theme
syntax enable
colorscheme PaperColor
" set dark/light background based on time
if (strftime("%H") < 20 && strftime("%H") > 7 )
set background=light
else
set background=dark
endif
" always light background if gui is running
if has('gui_running')
set background=light
endif
"deoplete settings
let g:deoplete#enable_at_startup = 1
let g:deoplete#ignore_sources = {}
"let g:deoplete#ignore_sources._ = ["neosnippet"]
" I want to use my tab more smarter. If we are inside a completion menu jump
" to the next item. Otherwise check if there is any snippet to expand, if yes
" expand it. Also if inside a snippet and we need to jump tab jumps. If none
" of the above matches we just call our usual 'tab'.
function! s:neosnippet_complete()
if pumvisible()
return "\<c-n>"
else
if neosnippet#expandable_or_jumpable()
return "\<Plug>(neosnippet_expand_or_jump)"
endif
return "\<tab>"
endif
endfunction
imap <expr><TAB> <SID>neosnippet_complete()
:inoremap <lt>/ </<C-X><C-O>
" nerdtree setting
" start with vim if no file is specified
if has("autocmd")
autocmd StdinReadPre * let s:std_in=1
"autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTree | endif
" close vim if only nerd tree is open
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
endif
map <C-n> :NERDTreeToggle<CR>
" Highlight full name (not only icons)
let g:NERDTreeFileExtensionHighlightFullName = 1
let g:NERDTreeExactMatchHighlightFullName = 1
let g:NERDTreePatternMatchHighlightFullName = 1
" Disable uncommon file extensions highlighting (good idea if lag when scrolling)
let g:NERDTreeLimitedSyntax = 1
" after a re-source, fix syntax matching issues (concealing brackets):
if exists('g:loaded_webdevicons')
call webdevicons#refresh()
endif
" toggle gundo
nnoremap <leader>u :MundoToggle<CR>
" general
set relativenumber
set number
set history=200 "set Ex command history
set autoread " detect when a file is changed
au FocusGained * :checktime "workaround for autoread: neovim/#1936
set cursorline
set mouse=a " mouse function
set backspace=indent,eol,start " backspace multiple lines
" enable global undo
set undofile
set undodir=~/.config/nvim/undo
" jump to the last position when reopening a file
if has("autocmd")
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
endif
set shortmess=I "disable intro message
" Tab control
set expandtab " insert spaces rather than tabs for <Tab> [noexpandtab for invert]
set smarttab " tab respects 'tabstop', 'shiftwidth', and 'softtabstop'
set tabstop=2 " the visible width of tabs
set softtabstop=2 " edit as if the tabs are 4 characters wide
set shiftwidth=2 " number of spaces to use for indent and unindent
set shiftround " round indent to a multiple of 'shiftwidth'
set completeopt+=longest
" Vim Splits
set splitbelow
set splitright
" substitute live preview
set inccommand=nosplit
" Key Bindings
"ReMap leader key
let mapleader = ","
" for learning: disable arrow keys
" noremap <Up> <NOP>
" noremap <Down> <NOP>
" noremap <Left> <NOP>
" noremap <Right> <NOP>
" better movement in Vim Splits
nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>
" enable copy to clipboard
map <Leader>y "+y
map <Leader>p "*p
" move vertically by visual line
" if there is a very long line that gets visually wrapped to two lines, wouldn't skip over the "fake" part of the visual line
nnoremap <UP> gk
nnoremap <DOWN> gj
nnoremap j gj
nnoremap k gk
" fast movement
map J 5j
map K 5k
" cursor to begin or end of line
nnoremap B ^
nnoremap E $
" Align block of text and keep them selected
vmap < <gv
vmap > >gv
" Faster delete.
nmap <C-BS> <C-W>
nmap <C-h> db
nmap <C-Del> dw
imap <C-Del> <ESC>dwi
" turn off last search highlight
map <esc> :noh<cr>
" highlight last inserted text
nnoremap gV `[v`]
" jk is escape
inoremap jk <ESC>
" Toggle background dark/light
map <F5> :let &background = ( &background == "dark"? "light" : "dark" )<CR>
" Toggle number lines
map <F6> :set number!<CR>:set relativenumber!<CR>
" Toggle | for indent lines
map <F7> :IndentLinesToggle<CR>
" lightline
let g:lightline = { 'colorscheme': 'PaperColor' }
" vim-airline (old, now using lightline)
"let g:airline_theme='papercolor'
"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_symbols_branch = ''
"let g:airline_symbols_readonly = ''
"let g:airline_symbols_linenr = ''
"let g:airline_powerline_fonts = 1 "required for devicons
" Enable Airline Tabbar
"let g:airline#extensions#tabline#enabled = 1
set encoding=utf8
set guifont=DroidSansMonoForPowerline\ Nerd\ Font
" EOF