Skip to content

Instantly share code, notes, and snippets.

@fn-alves
Created October 9, 2017 15:14
Show Gist options
  • Save fn-alves/b8e1bb9ef35d06026e9602b1694dddcd to your computer and use it in GitHub Desktop.
Save fn-alves/b8e1bb9ef35d06026e9602b1694dddcd to your computer and use it in GitHub Desktop.
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Set leader key & Python bin (neovim only) "
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let mapleader="\<Space>"
if has('nvim')
let g:python_host_prog = '/home/fNxONE/.virtualenvs/neovim3/bin/python'
endif
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" NeoBundle "
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" install and init NeoBundle
if has('vim_starting')
if &compatible
set nocompatible
endif
set runtimepath+=~/.vim/bundle/neobundle.vim/
endif
let neobundle_readme=expand('~/.vim/bundle/neobundle.vim/README.md')
if !filereadable(neobundle_readme)
echo "Installing NeoBundle..."
echo ""
silent !mkdir -p ~/.vim/bundle
silent !git clone https://github.com/Shougo/neobundle.vim ~/.vim/bundle/neobundle.vim/
endif
call neobundle#begin(expand('~/.vim/bundle/'))
NeoBundleFetch 'Shougo/neobundle.vim'
" syntax, completion & file types
NeoBundle 'cakebaker/scss-syntax.vim'
NeoBundle 'dagwieers/asciidoc-vim'
NeoBundle 'davidhalter/jedi-vim'
NeoBundle 'elmcast/elm-vim'
NeoBundle 'google/yapf' " eg.: <leader> =
NeoBundle 'gorodinskiy/vim-coloresque'
NeoBundle 'hail2u/vim-css3-syntax'
NeoBundle 'hdima/python-syntax'
NeoBundle 'jelera/vim-javascript-syntax'
NeoBundle 'jmcantrell/vim-virtualenv'
NeoBundle 'klen/python-mode'
NeoBundle 'mattn/emmet-vim' " eg.: html:5 <c-y>,
NeoBundle 'sheerun/vim-polyglot'
NeoBundle 'tpope/vim-commentary' " eg.: gc
NeoBundle 'tpope/vim-haml'
" navigation
NeoBundle 'ctrlpvim/ctrlp.vim'
NeoBundle 'easymotion/vim-easymotion' " eg.: <leader><leader>w
NeoBundle 'jistr/vim-nerdtree-tabs'
NeoBundle 'majutsushi/tagbar' " mapped to <leader><leader>t
NeoBundle 'scrooloose/nerdtree'
NeoBundle 'terryma/vim-expand-region' " eg.: vv to select word
" visual enhancements
NeoBundle 'NLKNguyen/papercolor-theme'
NeoBundle 'Valloric/MatchTagAlways'
NeoBundle 'unblevable/quick-scope'
NeoBundle 'vim-airline/vim-airline'
NeoBundle 'vim-airline/vim-airline-themes'
" tools
NeoBundle 'Yggdroot/indentLine'
NeoBundle 'airblade/vim-gitgutter'
NeoBundle 'bronson/vim-trailing-whitespace' " eg.: :FixWhitespace
NeoBundle 'fisadev/vim-isort' " eg.: :Isort
NeoBundle 'godlygeek/csapprox'
NeoBundle 'ktonga/vim-follow-my-lead' " eg.: <leader>fml to see mapped aliases/shortcuts
NeoBundle 'mileszs/ack.vim' " eg.: :Ack
NeoBundle 'rizzatti/dash.vim' " eg.: :Dash foobar
NeoBundle 'vim-scripts/greplace.vim' " eg.: :Gsearch and :Greplace
if has("nvim")
NeoBundle 'floobits/floobits-neovim'
endif
if version >= 800
NeoBundle 'w0rp/ale'
else
NeoBundle 'scrooloose/syntastic'
endif
call neobundle#end()
filetype plugin indent on
NeoBundleCheck
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Plugins configuration "
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" ack (use the_silver_searcher)
let g:ackprg = 'ag --nogroup --nocolor --column'
" airline
set laststatus=2
let g:airline_theme = 'papercolor'
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#left_sep = ' '
let g:airline#extensions#tabline#left_alt_sep = '|'
let g:airline#extensions#tabline#buffer_idx_mode = 1
" CtrlP loads only files outside .gitignore
let g:ctrlp_user_command = ['.git/', 'git --git-dir=%s/.git ls-files -oc --exclude-standard']
nnoremap <leader>o :CtrlP<CR>
nnoremap <leader>t :CtrlPBuffer<CR>
nnoremap <leader>O :CtrlPClearAllCaches<CR>
" IndentLine
let g:indentLine_enabled = 1
let g:indentLine_concealcursor = 0
let g:indentLine_char = '┆'
let g:indentLine_faster = 1
" vim-polyglot
let g:polyglot_disabled = ['elm']
" elm-vim
let g:elm_setup_keybindings = 0
let g:elm_format_autosave = 1
if version < 800
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
let g:elm_syntastic_show_warnings = 1
endif
" isort
autocmd FileType python nnoremap <leader>i :!isort %<CR><CR>
" NERDTree
let NERDTreeShowHidden=1
let NERDTreeIgnore=['\.pyc$', '__pycache__', '.git', '.vagrant', '.DS_Store', '.idea', '.ropeproject', '.coverage', 'cover/']
noremap <silent> <leader>nt :NERDTreeTabsToggle<CR>
" quick-scope (only enable highlighting when using the f/F/t/T movements)
function! Quick_scope_selective(movement)
let needs_disabling = 0
if !g:qs_enable
QuickScopeToggle
redraw
let needs_disabling = 1
endif
let letter = nr2char(getchar())
if needs_disabling
QuickScopeToggle
endif
return a:movement . letter
endfunction
let g:qs_enable = 0
nnoremap <expr> <silent> f Quick_scope_selective('f')
nnoremap <expr> <silent> F Quick_scope_selective('F')
nnoremap <expr> <silent> t Quick_scope_selective('t')
nnoremap <expr> <silent> T Quick_scope_selective('T')
vnoremap <expr> <silent> f Quick_scope_selective('f')
vnoremap <expr> <silent> F Quick_scope_selective('F')
vnoremap <expr> <silent> t Quick_scope_selective('t')
vnoremap <expr> <silent> T Quick_scope_selective('T')
" TagBar
noremap <silent> <leader><leader>t :TagbarToggle<CR>
" vim-expand-region
vmap v <Plug>(expand_region_expand)
vmap <C-v> <Plug>(expand_region_shrink)
" yapf
autocmd FileType python nnoremap <LocalLeader>= :0,$!yapf<CR>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Visual settings "
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" show line numbers and highlight current
set number
set relativenumber
set cursorline
" use virtual lines when there's no number prefix
" noremap <silent> <expr> j (v:count == 0 ? 'gj' : 'j')
" noremap <silent> <expr> k (v:count == 0 ? 'gk' : 'k')
"enable color syntax highlight
syntax on
" detect file type and load plugins for them
filetype on
filetype plugin on
filetype plugin indent on
" enable mouse
set mouse=a
" disable code folding
set nofoldenable
" color scheme
highlight pythonBoolean ctermfg=2 cterm=bold
set background=dark
colorscheme PaperColor
" set font and color column
set colorcolumn=80
if has("gui_running")
set macligatures
set guifont=Fira\ Code\ Retina:h13
if has("gui_gtk2")
set guifont=Hack\ 13
endif
endif
" hide gui elements & maximize gvim
if has("gui_gtk2")
set guioptions-=m "remove menu bar
set guioptions-=T "remove toolbar
set lines=999 columns=999
endif
" search and highlight as you type
set incsearch
set hlsearch
" when scrolling, keep cursor visible within 3 lines
set scrolloff=3
" show pending operator
set showcmd
" highlight extra spaces
highlight BadWhitespace ctermbg=red guibg=red
" remove blink
set gcr=a:blinkon0
" status bar
set statusline=%F%m%r%h%w%=(%{&ff}/%Y)\ (line\ %l\/%L,\ col\ %c)\
" window title
set title
set titleold="Terminal"
set titlestring=%F
" split windows below and right instead of above and left
set splitbelow splitright
" .md to .markdown and .adoc to .asciidoctor
autocmd BufNewFile,BufRead *.md setlocal ft=markdown " .md ->markdown
autocmd BufNewFile,BufRead *.adoc setlocal ft=asciidoc " .adoc ->asciidoc
" use block cursor in cygwin
if system('uname') =~ 'CYGWIN_NT-6.1'
let &t_ti.="\e[1 q"
let &t_SI.="\e[5 q"
let &t_EI.="\e[1 q"
let &t_te.="\e[0 q"
endif
" prevent vim from wrap inserted text
set textwidth=0
set wrapmargin=0
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Shortcuts & aliases "
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" disable search highlights
noremap <silent> <leader>, :nohl<CR>
" splits
noremap <silent> <leader>h :split<CR>
noremap <silent> <leader>v :vsplit<CR>
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>
" save
noremap <silent> <leader>w :w<CR>
" cleanup
noremap <silent> <leader>fw :FixWhitespace<CR>
" word count
noremap <silent> <leader>c g<C-g><CR>
" indent and keep in visual mode
map < <gv
map > >gv
" disable arrows navigation
" noremap <up> <nop> " alternative to real lines (vs. virtual ones)
" noremap <down> <nop> " alternative to real lines (vs. virtual ones)
noremap <left> <nop>
noremap <right> <nop>
" inoremap <up> <nop> " navigate through jedi
" inoremap <down> <nop> " navigate through jedi
inoremap <left> <nop>
inoremap <right> <nop>
" use c-j c-k in command mode
cmap <c-j> <down>
cmap <c-k> <up>
" use clipboard for Y/P/X
if has('unnamedplus')
set clipboard=unnamed,unnamedplus
endif
noremap YY "+y<CR>
noremap P "+gP<CR>
noremap XX "+x<CR>
" stop c, s and d from yanking
nnoremap c "_c
xnoremap c "_c
nnoremap s "_s
xnoremap s "_s
nnoremap d "_d
xnoremap d "_d
" stop p from overwtitting the register (by re-yanking it)
xnoremap p pgvy
" buffer nav
noremap <leader>z :bp<CR>
noremap <leader>x :bn<CR>
noremap <leader>q :bd<CR>
noremap <leader>qa :bufdo bd<CR>
" no one is really happy until you have this shortcuts
cnoreabbrev W w
cnoreabbrev W! w!
cnoreabbrev Q q
cnoreabbrev Q! q!
cnoreabbrev Qa qa
cnoreabbrev Qa! qa!
cnoreabbrev Wq wq
cnoreabbrev Wa wa
cnoreabbrev WQ wq
cnoreabbrev Wqa wqa
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Word processor mode "
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function! AsciiDocFold()
let line = getline(v:lnum)
if match(line, '^===') >= 0
return ">2"
elseif match(line, '^==') >= 0
return ">1"
endif
return "="
endfunction
function! AsciiDocFoldText()
let foldsize = (v:foldend-v:foldstart)
return getline(v:foldstart).' ('.foldsize.' lines)'
endfunction
function! WordProcessor()
if has("gui_macvim")
set guifont=Monaco:h12
endif
colorscheme PaperColor
set background=light
syntax on
set wrap
set linebreak
set nolist
set textwidth=0
set wrapmargin=0
set colorcolumn=0
set spell
set nocursorline
setlocal foldmethod=expr
setlocal foldexpr=AsciiDocFold()
setlocal foldtext=AsciiDocFoldText()
endfunction
autocmd BufNewFile,BufRead *.adoc call WordProcessor()
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Other customizations "
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" ignore certain type of files
set wildignore+=*/tmp/*,*.so,*.swp,*.zip,*.pyc,*.db,*.sqlite
" auto-reload external changes
set autoread
" line endings & other file chars settings
set encoding=utf-8
set fileencoding=utf-8
set fileformat=unix
set fileformats=unix,dos,mac
set binary
" indentation with 2 or 4 spaces
set expandtab " use spaces instead of tabs
set autoindent " autoindent based on line above
set smartindent " smarter indent for C-like languages
set shiftwidth=4 " when using Shift + > or <
set softtabstop=4 " in insert mode
set tabstop=4 " set the space occupied by a regular tab
" special files tabs, spaces etc.
function! FourSpacesStyle()
set tabstop=4
set softtabstop=4
set shiftwidth=4
set textwidth=79
set expandtab
set autoindent
set fileformat=unix
endfunction
function! TwoSpacesStyle()
set tabstop=2
set softtabstop=2
set shiftwidth=2
endfunction
au BufNewFile,BufRead *.elm call FourSpacesStyle()
au BufNewFile,BufRead *.py call FourSpacesStyle()
au BufNewFile,BufRead *.coffee call TwoSpacesStyle()
au BufNewFile,BufRead *.css call TwoSpacesStyle()
au BufNewFile,BufRead *.erb call TwoSpacesStyle()
au BufNewFile,BufRead *.html call TwoSpacesStyle()
au BufNewFile,BufRead *.jade call TwoSpacesStyle()
au BufNewFile,BufRead *.js call TwoSpacesStyle()
au BufNewFile,BufRead *.jsx call TwoSpacesStyle()
au BufNewFile,BufRead *.pug call TwoSpacesStyle()
au BufNewFile,BufRead *.rb call TwoSpacesStyle()
au BufNewFile,BufRead *.sass call TwoSpacesStyle()
au BufNewFile,BufRead *.scss call TwoSpacesStyle()
au BufNewFile,BufRead *.yaml call TwoSpacesStyle()
au BufNewFile,BufRead *.yml call TwoSpacesStyle()
" enable switch buffers without saving
set hidden
" allow non-case-sensitive case when using only lowercase
set ignorecase
set smartcase
" disable swaps and backups
set nobackup
set noswapfile
" fast rendering terminal
if has("neovim")
set ttyfast
endif
"
" disable annoying beeping
set noerrorbells
set vb t_vb=
if has("gui_running") " When the GUI starts, 't_vb' is reset
set noerrorbells
set vb t_vb=
endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment