Skip to content

Instantly share code, notes, and snippets.

@krydos
Created November 23, 2020 14:08
Show Gist options
  • Save krydos/24484288f4b80a4d60c4135b62f2ee84 to your computer and use it in GitHub Desktop.
Save krydos/24484288f4b80a4d60c4135b62f2ee84 to your computer and use it in GitHub Desktop.
set nocompatible
set t_Co=256
" map leader key
let mapleader = " "
" use kj as esc
imap kj <Esc>
" set line numbers to hybrid
set number relativenumber
" better switching among 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>
" setup folding
set foldmethod=indent
set nofoldenable
"set foldlevelstart=1
"set fml=0 " fold even if there is only one line
" don't wrap lines
set nowrap
" start ag from project root
" for rking/ag.vim plugin
let g:ag_working_path_mode="r"
" open this file in split
nnoremap <leader>ce :e $MYVIMRC<cr>G
" all plugins
call plug#begin('~/.local/share/nvim/plugged')
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'
Plug 'terryma/vim-multiple-cursors'
Plug 'rafi/awesome-vim-colorschemes'
Plug 'scrooloose/nerdtree'
Plug 'tpope/vim-fugitive'
Plug 'rking/ag.vim'
Plug 'editorconfig/editorconfig-vim'
Plug 'dkprice/vim-easygrep'
Plug 'pangloss/vim-javascript'
Plug 'jiangmiao/auto-pairs'
Plug 'posva/vim-vue'
Plug 'zah/nim.vim'
Plug 'pangloss/vim-javascript'
Plug 'mxw/vim-jsx'
Plug 'easymotion/vim-easymotion'
Plug 'colepeters/spacemacs-theme.vim'
Plug 'vim-scripts/gtags.vim'
Plug 'milkypostman/vim-togglelist'
Plug 'jwalton512/vim-blade'
Plug 'tpope/vim-dadbod'
Plug 'robertmeta/nofrils'
Plug 'dense-analysis/ale'
Plug 'sk1418/QFGrep'
Plug 'vim-scripts/vim-php-namespace'
Plug 'zackhsi/fzf-tags'
call plug#end()
" php auto namespace
noremap <Leader>u :call PhpInsertUse()<CR>
" always use spaces
set expandtab
set shiftwidth=2
set softtabstop=2
" allow unsaved buffer switching
set hidden
" use more colors
"set termguicolors
" better search
set ignorecase
set smartcase
" reload file if it has been changed
set autoread
au CursorHold * checktime
" don't create swap files
set noswapfile
" fzf config (with neovim workaround to off screen popup)
map <C-b> :Buffers<CR><C-\><C-n>0i
map <leader>bd :bd!<CR>
nmap <C-p> :Files<CR><C-\><C-n>0i
map <leader>ft :BTags<CR><C-\><C-n>0i
let $FZF_DEFAULT_COMMAND = 'ag -g ""'
map <C-]> <Plug>(fzf_tags)
" nerdtree bingings
map <leader>tt :NERDTreeToggle<CR>
map <leader>tf :NERDTreeFind<CR>
" map togglelist
nmap <leader>q :call ToggleQuickfixList()<CR>
"ale config
let g:ale_linters = {'php': ['php', 'phpmd']}
let g:ale_php_phpmd_ruleset = 'unusedcode'
" EasyGrep should start from project root
let g:EasyGrepCommand="git"
let g:EasyGrepRoot="repository"
let g:EasyGrepJumpToMatch=0
let g:EasyGrepReplaceWindowMode=2
map <leader>vg :Grep<Space>
" make vue plugin faster
let g:vue_pre_processors = []
" turn auto pairs quick jump
let g:AutoPairsMultilineClose = 0
" color scheme
set background=dark
colorscheme challenger_deep
" abbreviations
" RN
iab rntb borderColor: 'red', borderWidth: 2,
" PHP
iab puf public function
iab prf private function
iab clog console.log()
" Git
map <leader>gs :Gstatus<CR>
map <leader>gb :Gblame<CR>
map <leader>gd :Gdiff<CR>
" tags
"map <C-]> :tj <C-R><C-W><CR>
" jump to previous file
map <leader>o :e#<CR>
nmap <C-g> <Esc>
vmap <C-g> <Esc>
" Cursor line
set cursorline
highlight CursorLine guibg=#363000 ctermbg=234
au WinEnter * setlocal cursorline
au WinLeave * setlocal nocursorline
" keep cursor position when switching buffers
au BufLeave * let b:winview = winsaveview()
au BufEnter * if(exists('b:winview')) | call winrestview(b:winview) | endif
" remove trailing whitespaces
fun! CleanExtraSpaces()
let save_cursor = getpos(".")
let old_query = getreg('/')
silent! %s/\s\+$//e
call setpos('.', save_cursor)
call setreg('/', old_query)
endfun
autocmd BufWritePre * :call CleanExtraSpaces()
" don't treat $ sign as part of a keyword
augroup PHP
autocmd!
autocmd FileType php setlocal iskeyword-=$
autocmd FileType blade setlocal iskeyword-=$
augroup END
" unfold git buffers
au FileType git normal zR
" read .vimlocal to override project specific variables
" this line has to be define before any variable a read
silent! so .vimlocal
" SQL helper
function! ExecQueryFile()
if expand('%:t') != "query.sql"
echoerr "query.sql file should be opened"
return
endif
if !exists('g:DB_URL')
echoerr "DB_URL variable is not defined"
return
endif
echo 'connecting to ' . g:DB_URL
execute 'DB ' . g:DB_URL . ' ' . join(getline(1, '$'), "\n")
endfunction
nnoremap <leader>r :call ExecQueryFile()<cr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment