Skip to content

Instantly share code, notes, and snippets.

@diego898
Created August 10, 2018 12:58
Show Gist options
  • Select an option

  • Save diego898/fe0fda5f95f999337d4b087b38dfd524 to your computer and use it in GitHub Desktop.

Select an option

Save diego898/fe0fda5f95f999337d4b087b38dfd524 to your computer and use it in GitHub Desktop.

Revisions

  1. diego898 created this gist Aug 10, 2018.
    252 changes: 252 additions & 0 deletions init.vim
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,252 @@
    " ----------------------------------------------------------------------------
    " GENERAL SETTINGS
    " ----------------------------------------------------------------------------
    scriptencoding utf-16 " allow emojis in vimrc
    set encoding=utf-8 " necessery encoding for powerline
    set nocompatible " vim, not vi
    syntax on " syntax highlighting
    filetype plugin indent on " try to recognize filetypes and load rel' plugins

    let mapleader = ',' " set the mapleaders before mappings!


    " ----------------------------------------------------------------------------
    " PLUGINS
    " ----------------------------------------------------------------------------
    call plug#begin()
    if has('nvim')
    Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
    endif
    Plug 'airblade/vim-gitgutter'
    Plug 'w0rp/ale'
    Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
    Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
    Plug 'junegunn/fzf.vim'
    Plug 'vim-airline/vim-airline'
    Plug 'tpope/vim-fugitive'
    Plug 'tpope/vim-commentary'
    Plug 'tpope/vim-surround'
    Plug 'mbbill/undotree', {'on': 'UndotreeToggle'}
    Plug 'easymotion/vim-easymotion'
    Plug 'townk/vim-autoclose'
    Plug 'sheerun/vim-polyglot'
    Plug 'tpope/vim-repeat'
    Plug 'mileszs/ack.vim'
    "Plug 'lifepillar/vim-solarized8'
    "Plug 'phanviet/vim-monokai-pro'
    "Plug 'rakr/vim-one'
    Plug 'morhetz/gruvbox'
    Plug 'tpope/vim-unimpaired'
    Plug 'qpkorr/vim-bufkill'
    Plug 'luochen1990/rainbow'
    Plug 'tiagofumo/vim-nerdtree-syntax-highlight'
    Plug 'ryanoasis/vim-devicons'
    Plug 'machakann/vim-highlightedyank'
    call plug#end()


    " ----------------------------------------------------------------------------
    " PLUGIN SETTINGS
    " ----------------------------------------------------------------------------

    " Colorschemed
    set termguicolors
    set background=dark
    colorscheme gruvbox
    let g:gruvbox_contrast_dark = 'hard'
    let g:gruvbox_improved_warnings = '1'

    " Undotree
    let g:undotree_SetFocusWhenToggle = '1'
    nmap <leader>u :UndotreeToggle<CR>

    " ALE
    " Error and warning signs.
    let g:ale_sign_error = ''
    let g:ale_sign_warning = ''
    " Enable integration with airline.
    let g:airline#extensions#ale#enabled = 1


    " Ack.vim
    " Tell ack.vim to use ag (the Silver Searcher) instead
    let g:ackprg = 'ag --vimgrep'

    " FZF
    nmap ; :Buffers<CR>
    nmap <Leader>f :Files<CR>
    nmap <Leader>t :Tags<CR>
    " Deoplete
    "let g:deoplete#enable_at_startup = 1

    " Airline
    let g:airline_powerline_fonts = 1
    let g:airline#extensions#tabline#enabled = 1

    " NERDTree
    " Close vim if nerdtree is the only window open
    autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif

    " Ignore .git directories
    let NERDTreeIgnore=['^\.git','^__']

    " Toggle NerdTree
    nmap <leader>b :NERDTreeToggle<CR>
    " Rainbow Parenthesis
    let g:rainbow_conf = {
    \ 'guifgs': ['royalblue3', 'darkorange3', 'seagreen3', 'firebrick'],
    \ 'ctermfgs': ['lightblue', 'lightyellow', 'lightcyan', 'lightmagenta'],
    \ 'operators': '_,_',
    \ 'parentheses': ['start=/(/ end=/)/ fold', 'start=/\[/ end=/\]/ fold', 'start=/{/ end=/}/ fold'],
    \ 'separately': {
    \ '*': {},
    \ 'tex': {
    \ 'parentheses': ['start=/(/ end=/)/', 'start=/\[/ end=/\]/'],
    \ },
    \ 'lisp': {
    \ 'guifgs': ['royalblue3', 'darkorange3', 'seagreen3', 'firebrick', 'darkorchid3'],
    \ },
    \ 'vim': {
    \ 'parentheses': ['start=/(/ end=/)/', 'start=/\[/ end=/\]/', 'start=/{/ end=/}/ fold', 'start=/(/ end=/)/ containedin=vimFuncBody', 'start=/\[/ end=/\]/ containedin=vimFuncBody', 'start=/{/ end=/}/ fold containedin=vimFuncBody'],
    \ },
    \ 'html': {
    \ 'parentheses': ['start=/\v\<((area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)[ >])@!\z([-_:a-zA-Z0-9]+)(\s+[-_:a-zA-Z0-9]+(\=("[^"]*"|'."'".'[^'."'".']*'."'".'|[^ '."'".'"><=`]*))?)*\>/ end=#</\z1># fold'],
    \ },
    \ 'css': 0,
    \ }
    \}


    " ----------------------------------------------------------------------------
    " KEY MAPS
    " ----------------------------------------------------------------------------

    " Move *visually* up and down
    nmap j gj
    nmap k gk
    " Make movement down(j)-up(k)-left(l)-right(;)
    "noremap l h
    "noremap ; l
    "noremap h ;

    " Marks should go to the column, not just the line. Why isn't this the default? See :h mark-motions
    nnoremap ' `
    " You don't know what you're missing if you don't use this.
    nmap <C-e> :e#<CR>
    " Move between open buffers.
    nmap <C-n> :bnext<CR>
    nmap <C-p> :bprev<CR>
    " Use the space key to toggle folds
    nnoremap <space> za
    vnoremap <space> zf
    " Super fast window movement shortcuts
    nmap <C-j> <C-W>j
    nmap <C-k> <C-W>k
    nmap <C-h> <C-W>h
    nmap <C-l> <C-W>l
    " Searches always operate in "Very Magic" mode
    nnoremap / /\v
    vnoremap / /\v
    " In normal and visua mode use tab to jump to matching braces
    nnoremap <tab> %
    vnoremap <tab> %
    " Use ESC to exit terminal mode
    tnoremap <Esc> <C-\><C-n>
    " Clear out search highlighting
    nnoremap <leader><space> :noh<cr>
    " Strip trailing whitespace - e prevents an error if none are found
    " note this moves the cursor to the last match and resets the last search term.
    " nnoremap <leader>w :%s/\s\+$//e<CR>
    " a better way is to save the window view to a variable, run it, and restore it.
    fun! TrimWhitespace()
    let l:save = winsaveview()
    %s/\s\+$//e
    call winrestview(l:save)
    endfun
    command! TrimWhitespace call TrimWhitespace()
    nnoremap <Leader>w :call TrimWhitespace()<CR>
    " easier quitting/closing
    nmap <leader>q <ESC>:q<CR>
    " focusing/closing all splits
    nmap <leader>o :only<CR>

    " ----------------------------------------------------------------------------
    " OPTIONS
    " ----------------------------------------------------------------------------
    set autoindent " Carry over indenting from previous line
    set autoread " Don't bother me hen a file changes
    set autowrite " Write on :next/:prev/^Z
    set backspace=indent,eol,start
    " Allow backspace beyond insertion point
    set cindent " Automatic program indenting
    set cinkeys-=0# " Comments don't fiddle with indenting

    set copyindent " Make autoindent use the same chars as prev line
    set directory-=. " Don't store temp files in cwd
    set expandtab " No tabs
    set formatoptions=tcqn1 " t - autowrap normal text
    " c - autowrap comments
    " q - gq formats comments
    " n - autowrap lists
    " 1 - break _before_ single-letter words
    set hidden " Don't prompt to save hidden windows until exit
    set history=200 " How many lines of history to save

    set hlsearch " Hilight searching
    set ignorecase " Case insensitive
    set inccommand=split " Live preview of substitutions
    set incsearch " Search as you type
    set infercase " Completion recognizes capitalization
    set laststatus=2 " Always show the status bar
    set matchtime=2 " Tenths of second to hilight matching paren
    set number " Line numbers to start
    set scrolloff=3 " Numbers of context lines while scrolling
    set showcmd " Show (partial) command in the last line of the screen (turn off if terminal is slow)
    set showmatch " Hilight matching braces/parens/etc.
    "set showmode " Always tell us what mode were in
    set noshowmode " Airline shows us the mode
    set smartcase " Lets you search for ALL CAPS
    set softtabstop=2 " Spaces 'feel' like tabs
    set suffixes+=.pyc " Ignore these files when tab-completing
    set tabstop=2 " The One True Tab
    set textwidth=100 " 100 is the new 80
    set ttyfast " Indicates fast terminal - more drawing
    set undofile " We want persistent undofiles
    set vb t_vb= " No visual bells
    set wildmenu " Enable command-line completion operates in an enhanced mode
    "set wildmode=longest:full,full " Setup completion
    set mouse=a " enable mouse (selection, resizing windows)

    " Make vim recogize 256 colors
    if $TERM == "xterm-256color" || $TERM == "screen-256color" || $COLORTERM == "gnome-terminal"
    set t_Co=256
    endif


    " ----------------------------------------------------------------------------
    " NOTES
    " ----------------------------------------------------------------------------
    " Config Files
    " * https://github.com/statico/dotfiles/blob/master/.vim/vimrc
    "
    " Resources:
    " * https://statico.github.io/vim.html
    " * https://statico.github.io/vim2.html
    " * https://statico.github.io/vim3.html
    " * https://github.com/mhinz/vim-galore