Skip to content

Instantly share code, notes, and snippets.

@alisanie
Last active March 25, 2020 16:03
Show Gist options
  • Save alisanie/2737983d44057ca53f87950b32e284c8 to your computer and use it in GitHub Desktop.
Save alisanie/2737983d44057ca53f87950b32e284c8 to your computer and use it in GitHub Desktop.
vimrc for linux
"----------General-Configure----------"
set encoding=utf-8
set nocompatible "We want the latest Vim Settings/options
syntax enable "Enable Syntax
set backspace=indent,eol,start "Make backspace behave like every other editor
let mapleader="," "The default leader is \,but I prefer comma
set number "Let's Active the line number
set visualbell t_vb= "Make Macvim Silent
set ic "Make search case insensitive
"set spell "Enable spell checking in vim
set spelllang=en_us "Set English default language
set complete=.,w,b,u "set auto completion on
set nofoldenable "I hate folding
"----------Command---------"
"Change : to \ faster result
nmap ; :
"----------Visual----------"
set t_CO=256 "Force iterm/Terminal using 2 56 color
set guifont=inconsolata:h20
"Make Macvim Beautiful
if has("gui_running")
set macligatures
set fu "Make macvim run full screen by default
endif
set guioptions-=e "Fix Tab Issues
set linespace=15 "Macvim Specific line-height
set guioptions-=l "Macvim Hide Gui Scroll
set guioptions-=L
set guioptions-=r
set guioptions-=R
"remove Split Background
hi vertsplit guifg=bg guibg=bg
"----------Search---------"
set hlsearch "Enable highlight when searching
set incsearch "Enable incremental searching
nmap <Leader><space> :nohlsearch<cr> "For deselect highlight
"----------Split-Management---------"
set splitbelow "Make sure that split under each other
set splitright "Make sure split happened in right side
nmap <C-J> <C-W><C-J>
nmap <C-K> <C-W><C-K>
nmap <C-L> <C-W><C-L>
nmap <C-H> <C-W><C-H>
"----------General-Mapping----------"
"Make editing vimrc really easy
nmap <Leader>ev :tabedit $MYVIMRC<cr> "Edit vimrc in new tab
nmap <Leader>q :q<cr> "quit using ,v
nmap <Leader>fq :q!<cr> "quit with out save
nmap <Leader>ep :tabedit ~/.vim/plugins.vim<cr> "Edit plugin faster
nmap <Leader>pi :PluginInstall<cr> "Install PluginInstall
nmap <S-o> o<Esc> "Making new line without insert
nmap <Leader>f :tag<space>
nmap <Leader>w :w<cr> "Quick save file
nmap r <C-R> "Redo faster
nmap <Leader>co :copen<cr> "open copen log
nmap <Leader>bd :bd<cr> "delet buffer
"edit snippets
nmap <leader>es :tabedit ~/.vim/snippets/
"edit lab
nmap <leader>el :e ~/Desktop/lab/
"----------Base-Mapping----------"
imap jk <Esc> "Add j j for escap in inset mode for making everything fast
"==========Plugin-Settings=========="
"----------Ctrlp-Settings----------"
nmap <D-r> :CtrlPBufTag<cr> "Show All Method
"Show CtrlP buy using Command
nmap <D-p> :CtrlP<cr>
nmap <D-e> :CtrlPMRUFiles<cr> "MRUFiles in CtrlP
"ignore files/folder
let g:ctrlp_custom_ignore = 'node_modules\|DS_Store\|git'
let g:ctrlp_match_window='top,order:ttb,min:1,max:30,result:30'
"Clear ctrlp catch
let g:ctrlp_use_caching = 1
let g:ctrlp_clear_cache_on_exit = 0
"----------NerdTree-Settings----------"
let NERDTreeHijackNetrw=0 "Fix Vinegar Issues with NerdTree
nmap <D-1> :NERDTreeToggle<cr> "Show NerdTree using Cmd+1
"----------Greplace-Settings----------"
set grepprg=ag "using AG for the search
let g:grep_cmd_opts='--line-numbers --noheading'
"---------Snipmate-vim--------"
nmap <Leader>sr :call ReloadAllSnippets()<cr> "Reload Snippet
"----------vim-php-name-space--------"
function! IPhpInsertUse()
call PhpInsertUse()
call feedkeys('a', 'n')
endfunction
autocmd FileType php inoremap <Leader>n <Esc>:call IPhpInsertUse()<CR>
autocmd FileType php noremap <Leader>n :call PhpInsertUse()<CR>
"Make name space full path
function! IPhpExpandClass()
call PhpExpandClass()
call feedkeys('a', 'n')
endfunction
autocmd FileType php inoremap <Leader>nf <Esc>:call IPhpExpandClass()<CR>
autocmd FileType php noremap <Leader>nf :call PhpExpandClass()<CR>
"Sort PHP use statements
"http://stackoverflow.com/questions/11531073/how-do-you-sort-a-range-of-lines-by-length
vmap <Leader>su ! awk '{ print length(), $0 \| "sort -n \| cut -d\\ -f2-" }'<cr>
"----------PSR-Fixer--------"
let g:php_cs_fixer_level = "psr2" " Formatting psr2
let g:php_cs_fixer_verbose = 0 "No output after fix PSR
nnoremap <C-t> :call PhpCsFixerFixFile()<CR>
"----------Laravel-Special--------"
nmap <Leader>lr :e app/Http/routes.php<cr>
nmap <Leader>mv :e resources/views
"----------Fix-rtl-Keyboard---------"
nmap <Leader>lrl :set rl<cr> "Change to rtl
nmap <Leader>llr :set rl!<cr> "Change to ltr
"----------Auto-command----------"
"Automatically source the Vimrc file on save
augroup vimSaveAndSource
autocmd!
autocmd BufWritePost .vimrc so %
augroup END
"Fix Parent Save
function s:MkNonExDir(file, buf)
if empty(getbufvar(a:buf, '&buftype')) && a:file!~#'\v^\w+\:\/'
let dir=fnamemodify(a:file, ':h')
if !isdirectory(dir)
call mkdir(dir, 'p')
endif
endif
endfunction
augroup BWCCreateDir
autocmd!
autocmd BufWritePre * :call s:MkNonExDir(expand('<afile>'), +expand('<abuf>'))
augroup END
" CtrlP auto cache clearing.
" ----------------------------------------------------------------------------
function! SetupCtrlP()
if exists("g:loaded_ctrlp") && g:loaded_ctrlp
augroup CtrlPExtension
autocmd!
autocmd FocusGained * CtrlPClearCache
autocmd BufWritePost * CtrlPClearCache
augroup END
endif
endfunction
if has("autocmd")
autocmd VimEnter * :call SetupCtrlP()
endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment