Skip to content

Instantly share code, notes, and snippets.

@guimaluf
Created December 4, 2019 11:01
Show Gist options
  • Save guimaluf/7160416e842b15c97de0f45532053df0 to your computer and use it in GitHub Desktop.
Save guimaluf/7160416e842b15c97de0f45532053df0 to your computer and use it in GitHub Desktop.
if empty(glob('~/.vim/autoload/plug.vim'))
silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
call plug#begin('~/.vim/plugged')
Plug 'airblade/vim-gitgutter'
Plug 'godlygeek/tabular'
Plug 'hashivim/vim-terraform'
Plug 'huawenyu/vim-log-syntax'
Plug 'jiangmiao/auto-pairs'
Plug 'michaeljsmith/vim-indent-object'
Plug 'pearofducks/ansible-vim'
Plug 'rodjek/vim-puppet'
Plug 'sheerun/vim-polyglot'
Plug 'tpope/vim-endwise'
Plug 'tpope/vim-eunuch'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-surround'
Plug 'wellle/targets.vim'
call plug#end()
filetype plugin indent on
colorscheme murphy
syntax on
" spellchecking
set spelllang=pt,en
" enconding
set encoding=utf8
" highlight search pattern
set hlsearch
" do incremental search
set incsearch
" ignore case in the search pattern
set ignorecase
" search with regexp
set magic
" mouse
set mouse=a
" avoid paste errors
set pastetoggle=<F2>
" use backspace to delete text
set backspace=indent,start,eol
" use auto indentation
set autoindent
set smartindent
" dont user tab chars, use four spaces
set expandtab
set smarttab
set tabstop=2
set softtabstop=2
set shiftwidth=2
set textwidth=80
" scrolling settings
set scrolloff=3
set sidescrolloff=7
set sidescroll=1
" don't make backup file
set nobackup
set nowb
set noswapfile
" the history size
set history=10000
"undoing time
set undofile
set undolevels=1000
set undoreload=10000
"last line info options
set showcmd
" show what mode you are in
set showmode
" cursor position info
set ruler
" show current line number and others relative
set number
set relativenumber
"
" confirm bash as shell
set shell=/bin/bash
"IgnoreCase, IncrementedSearch, SmartCaSe
set ignorecase incsearch smartcase
"ShowMatch
set showmatch
set matchtime=2
" auto complete in cmd mode
set wildmenu
set wildmode=full
set wildignore=*.swp,*.bak,*.pyc,*.class,*.o,*.un~
"speed boosters
set lazyredraw
set ttyfast
" folding
set foldmethod=indent
set nofoldenable
"Always show the status line
set laststatus=2
"statusline
set statusline= " clear the statusline for when vimrc is reloaded
set statusline+=%-3.3n\ " buffer number
set statusline+=%f\ " file name
set statusline+=%h%m%r%w " flags
set statusline+=[%{strlen(&ft)?&ft:'none'}, " filetype
set statusline+=%{strlen(&fenc)?&fenc:&enc}, " encoding
set statusline+=%{&fileformat}] " file format
set statusline+=\ [%{getcwd()}] " current dir
set statusline+=%*
set statusline+=%= " right align
set statusline+=%b,0x%-8B\ " current char
set statusline+=%-14.(%l,%c%V%)\ %<%P " offset
" Visual mode pressing * or # searches for the current selection
" Super useful! From an idea by Michael Naumann
vnoremap <silent> * :call VisualSelection('f')<CR>
vnoremap <silent> # :call VisualSelection('b')<CR>
"using grep on vim
map <Leader>p :cp<CR>zz
map <Leader>n :cn<CR>zz
" save file using sudo
cmap w!! w !sudo tee %
"space include spaces
nmap <Space> i<Space><Esc>
" move through split
nnoremap <C-H> <C-w>h
nnoremap <C-L> <C-w>l
nnoremap <C-J> <C-w>j
nnoremap <C-K> <C-w>k
"tab walking
nmap <left> :tabprev<CR>
nmap <right> :tabnext<CR>
nmap <Leader>h :tabprev<CR>
nmap <Leader>l :tabnext<CR>
""buffer walking
nmap <Leader>k :bn <CR>zz
nmap <Leader>j :bp <CR>zz
nmap <up> :bn <CR>zz
nmap <down> :bp <CR>zz
"clean highlight search
nmap <C-c> <ESC>:nohlsearch<CR>
"Search
" faz os resultados da busca aparecerem no meio da tela
nmap n nzz
nmap N Nzz
nmap * *zz
nmap # #zz
nmap g* g*zz
nmap g# g#zz
"Dir/files navigation
nmap <Leader>- :Explore<CR>
nmap <Leader>v- :Vexplore<CR>
nmap <Leader>s- :Sexplore<CR>
nmap <Leader>t- :Texplore<CR>
"Dir grep navigation
nmap <Leader>-/ :Explore **//
nmap <Leader>v-/ :Vexplore **//
nmap <Leader>s-/ :Sexplore **//
nmap <Leader>t-/ :Texplore **//
"split
nmap <Leader>v <C-w>v
nmap <Leader>s <C-w>s
nmap <Leader>t :tabnew<CR>
nmap <BS> <C-W>h
setlocal expandtab
"neovim terminal
tnoremap <Esc> <C-\><C-n>
tnoremap <C-H> <C-\><C-n><C-w>h
tnoremap <C-L> <C-\><C-n><C-w>l
tnoremap <C-J> <C-\><C-n><C-w>j
tnoremap <C-K> <C-\><C-n><C-w>k
" textobj-line
nmap vil ^vg_
"Color
hi Search ctermbg=green ctermfg=black
hi IncSearch ctermbg=black ctermfg=cyan
hi TabLineSel ctermfg=red ctermbg=grey
hi statusline guibg=Cyan ctermfg=6 guifg=Black ctermbg=0
hi MatchParen cterm=bold ctermbg=none ctermfg=3
autocmd BufNewFile,BufRead \*.{md,mdwn,mkd,mkdn,mark\*} set filetype=markdown
augroup BufWritePre_
autocmd!
autocmd BufWritePre * :call s:MkNonExDir(expand('<afile>'), +expand('<abuf>'))
autocmd BufWritePre * :call <SID>StripTrailingWhitespaces()
augroup END
augroup Filetype
autocmd!
autocmd FileType gitcommit set tw=72
augroup END
" Put these in an autocmd group, so that we can delete them easily.
augroup BufReadPost_
au!
" When editing a file, always jump to the last known cursor position.
" Don't do it when the position is invalid or when inside an event handler
" (happens when dropping a file on gvim).
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
augroup END
" Create path of non existing file
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
" Strip trailing whitespace
function! <SID>StripTrailingWhitespaces()
" Preparation save last search, and cursor position.
let _s=@/
let l = line(".")
let c = col(".")
" Do the business:
%s/\s\+$//e
" Clean up: restore previous search history, and cursor position
let @/=_s
call cursor(l, c)
endfunction
function! VisualSelection(direction) range
let l:saved_reg = @"
execute "normal! vgvy"
let l:pattern = escape(@", '\\/.*$^~[]')
let l:pattern = substitute(l:pattern, "\n$", "", "")
if a:direction == 'b'
execute "normal ?" . l:pattern . "^M"
elseif a:direction == 'gv'
call CmdLine("vimgrep " . '/'. l:pattern . '/' . ' **/*.')
elseif a:direction == 'replace'
call CmdLine("%s" . '/'. l:pattern . '/')
elseif a:direction == 'f'
execute "normal /" . l:pattern . "^M"
endif
let @/ = l:pattern
let @" = l:saved_reg
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment