Skip to content

Instantly share code, notes, and snippets.

@sahibalejandro
Last active October 17, 2018 04:42
Show Gist options
  • Save sahibalejandro/53e920b9a9812fad35ac6faa5169db55 to your computer and use it in GitHub Desktop.
Save sahibalejandro/53e920b9a9812fad35ac6faa5169db55 to your computer and use it in GitHub Desktop.
nvim config file
call plug#begin()
" Editing
Plug 'mattn/emmet-vim'
Plug 'tpope/vim-surround'
Plug 'jiangmiao/auto-pairs'
Plug 'easymotion/vim-easymotion'
Plug 'sgur/vim-editorconfig'
" Code completion
Plug 'sahibalejandro/vim-php'
Plug 'SirVer/ultisnips'
" User Interface
Plug 'scrooloose/nerdtree'
Plug 'airblade/vim-gitgutter'
Plug 'itchyny/lightline.vim'
" File Searching
Plug 'mileszs/ack.vim'
Plug 'ctrlpvim/ctrlp.vim'
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install' }
" Syntax Highlighting
Plug 'sheerun/vim-polyglot'
" Linters
Plug 'w0rp/ale'
" Color Themes
Plug 'chriskempson/base16-vim'
" VCS Stuff
Plug 'tpope/vim-fugitive'
call plug#end()
" ---------- General
set nowrap
set undofile
set undodir=/tmp
set noswapfile
set nobackup
set autowrite
set mouse=a
" ---------- Search
set ignorecase
set smartcase
" ---------- Indentation
set expandtab
set tabstop=4
set shiftwidth=4
" ---------- Visuals
if (has("termguicolors"))
set termguicolors
endif
set background=dark
set signcolumn=yes
set number
set scrolloff=5
colorscheme base16-material
if (has("termguicolors"))
highlight LineNr guibg=bg
highlight SignColumn guibg=bg
highlight GitGutterAdd guibg=bg guifg=green
highlight GitGutterChange guibg=bg guifg=orange
highlight GitGutterDelete guibg=bg guifg=red
highlight GitGutterChangeDelete guibg=bg guifg=red
endif
" ---------- Mappings
let mapleader = ','
inoremap jk <esc>
nnoremap <leader>v :e ~/.vimrc<cr>
nnoremap <leader>c :nohl<cr>
nnoremap <leader>w :bd<cr>
" Instead of using a plugin that simulate multiple
" cursors like Sublime, these mappings can help
" to change same word in different locations
vnoremap <leader>d y/<c-r>"<cr>N
nnoremap <leader>d cgn
" Mappings for saving files.
inoremap <c-s> <esc>:w<cr>l
nnoremap <c-s> :w<cr>
" ---------- ctrlp.vim
nnoremap <leader>e :CtrlPBuff<cr>
nnoremap <leader>r :CtrlPBufTag<cr>
" ---------- FZF
let $FZF_DEFAULT_COMMAND = 'ag --nocolor --hidden --skip-vcs-ignores --ignore ".git/*" --ignore "node_modules/*" -g ""'
nnoremap <leader>p :FZF<cr>
" Hide statusline when FZF opens in a terminal buffer.
autocmd! FileType fzf
autocmd FileType fzf set laststatus=0 noshowmode noruler | autocmd BufLeave <buffer> set laststatus=2 showmode ruler
" ---------- Ack
let g:ackprg = 'ag --hidden --skip-vcs-ignores --vimgrep --smart-case --nocolor --hidden --ignore ".git/*" --ignore "node_modules/*"'
nnoremap <leader>f :Ack
" ---------- NERDTree
nnoremap <leader>1 :NERDTreeToggle<cr>
nnoremap <leader>2 :NERDTreeFind<cr>
let NERDTreeQuitOnOpen = 1
let NERDTreeAutoDeleteBuffer = 1
let NERDTreeMinimalUI = 1
let NERDTreeNaturalSort = 1
let NERDTreeHighlightCursorline = 0
" ---------- Emmet
let g:user_emmet_leader_key='<C-Z>'
" ---------- UltiSnips
let g:UltiSnipsSnippetDirectories=[$HOME.'/.config/nvim/UltiSnips']
" ---------- Git Gutter
let g:gitgutter_override_sign_column_highlight = 0
set updatetime=150
" ---------- Ale
let g:ale_linters = { 'php': ['phpcs'] }
let g:ale_php_phpcs_standard = 'PSR2'
" ---------- Vim Vue
let g:vue_disable_pre_processors = 1
" ---------- Lightline
let g:lightline = {
\ 'active': {
\ 'left': [[], ['cwd', 'filename', 'modified', 'readonlreadonly'], ['branch']],
\ 'right': [['lineinfo'], ['percent'], ['linter', 'filetype', 'fileformat', 'fileencoding']]
\ },
\ 'component': {
\ 'cwd': '%{split(getcwd(), "/")[-1]}'
\ },
\ 'component_function': {
\ 'branch': 'fugitive#head'
\ }
\ }
" ---------- Vim PHP
augroup vimphp
autocmd!
autocmd FileType php nnoremap <leader>u :PHPImportClass<cr>
autocmd FileType php nnoremap <leader>x :PHPExpandFQCN<cr>
autocmd FileType php nnoremap <leader>X :PHPExpandFQCNAbsolute<cr>
augroup END
" ---------- Laravel Artisan
function! s:Artisan(args)
execute 'terminal php artisan ' . a:args
endfunction
command! -nargs=1 Art call s:Artisan(<f-args>)
" ---------- PHP CTags
function! s:UpdateCTags()
call jobstart('ctags --recurse --languages=php --kinds-php=ctif --exclude="node_modules/*"')
endfunction
command! Ctags call s:UpdateCTags()
" ---------- PHPUnit
nnoremap <leader>t :terminal './vendor/bin/phpunit'<cr>
" ---------- Load configuration per project
function! s:LoadProjectConfig()
if (filereadable('.project.vim'))
source .project.vim
echom 'Project configuration loaded.'
endif
endfunction
function! s:VimEnter()
:call s:LoadProjectConfig()
endfunction
" ---------- General commands group
augroup vimrc
autocmd!
autocmd BufWritePost .vimrc :source %
autocmd BufWritePost .project.vim :source %
autocmd BufReadPost *.vue :syntax sync fromstart
autocmd BufWritePost *.php :call s:UpdateCTags()
autocmd VimEnter * :call s:VimEnter()
augroup END
" ---------- Save config as gist
command! SaveConfig terminal savenvimcfg
command! LoadConfig terminal loadnvimcfg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment