Created
November 27, 2018 10:43
-
-
Save al3rez/ec4162ba5ea6f86e9b57edb346ca0280 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unlet! skip_defaults_vim | |
source $VIMRUNTIME/defaults.vim | |
filetype indent on | |
set backspace=indent,eol,start | |
set number | |
set nobackup | |
set noswapfile | |
autocmd! | |
autocmd BufWritePost *.go silent :!goimports -w % | |
autocmd FileType ruby set ts=2 sts=2 sw=2 et | |
autocmd FileType go set ts=4 sts=4 sw=4 | |
autocmd FileType python set ts=4 sts=4 sw=4 | |
autocmd FileType eruby set ts=2 sts=2 sw=2 et | |
autocmd FileType haml set ts=2 sts=2 sw=2 et | |
autocmd FileType vim set ts=2 sts=2 sw=2 et | |
set autoread | |
set laststatus=2 | |
set statusline=%<%f\ (%{&ft})\ %-4(%m%)%=%-19(%3l,%02c%03V%) | |
syntax on | |
colorscheme solarized | |
let mapleader="," | |
function! FzyCommand(choice_command, vim_command) | |
try | |
let output = system(a:choice_command . " | fzy ") | |
catch /Vim:Interrupt/ | |
" Swallow errors from ^C, allow redraw! below | |
endtry | |
redraw! | |
if v:shell_error == 0 && !empty(output) | |
exec a:vim_command . ' ' . output | |
endif | |
endfunction | |
nnoremap <leader>p :call FzyCommand("git ls-files --cached --exclude-standard --others", ":e")<cr> | |
cnoremap <expr> %% expand('%:h').'/' | |
map <leader>e :edit %% | |
inoremap jk <Esc> | |
xnoremap jk <Esc> | |
cnoremap jk <C-c> | |
" Use ag over grep | |
set grepprg=rg\ --vimgrep\ --color=never\ --no-heading | |
set grepformat=%f:%l:%c:%m,%f:%l:%m | |
" bind K to grep word under cursor | |
nnoremap K :grep "\b<C-R><C-W>\b"<CR>topleft cwindow<CR> | |
" bind \ (backward slash) to grep shortcut | |
command -nargs=+ -complete=file -bar Ag silent! grep! <args>|topleft cwindow|redraw! | |
nnoremap \ :Ag<SPACE> | |
nnoremap ]q :cnext<cr>zz | |
nnoremap [q :cprev<cr>zz | |
nnoremap ]l :lnext<cr>zz | |
nnoremap [l :lprev<cr>zz | |
function! GetBufferList() | |
redir =>buflist | |
silent! ls | |
redir END | |
return buflist | |
endfunction | |
function! BufferIsOpen(bufname) | |
let buflist = GetBufferList() | |
for bufnum in map(filter(split(buflist, '\n'), 'v:val =~ "'.a:bufname.'"'), 'str2nr(matchstr(v:val, "\\d\\+"))') | |
if bufwinnr(bufnum) != -1 | |
return 1 | |
endif | |
endfor | |
return 0 | |
endfunction | |
function! ToggleQuickfix() | |
if BufferIsOpen("Quickfix List") | |
cclose | |
else | |
call OpenQuickfix() | |
endif | |
endfunction | |
function! OpenQuickfix() | |
silent! cgetfile tmp/quickfix | |
topleft cwindow | |
if &ft == "qf" | |
cc | |
endif | |
endfunction | |
nnoremap <leader>q :call ToggleQuickfix()<cr> | |
function! RenameFile() | |
let old_name = expand('%') | |
let new_name = input('New file name: ', expand('%'), 'file') | |
if new_name != '' && new_name != old_name | |
exec ':saveas ' . new_name | |
exec ':silent !rm ' . old_name | |
redraw! | |
endif | |
endfunction | |
map <leader>n :call RenameFile()<cr> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Latest!