Skip to content

Instantly share code, notes, and snippets.

@tapickell
Created July 29, 2021 02:47
Show Gist options
  • Save tapickell/86e412dbd92bacd481a0dad6a59b2696 to your computer and use it in GitHub Desktop.
Save tapickell/86e412dbd92bacd481a0dad6a59b2696 to your computer and use it in GitHub Desktop.
osx_init.vim
"Plug 'tacahiroy/ctrlp-funky' This vimrc is "inspired" by @moonglum, @garybernhardt and @railsbros-dirk
" Thanks to all of you for letting me steal your stuff :)
" Activate Syntax Highlight
syntax enable
" set default encoding to UTF-8
set encoding=utf-8
" You will have bad experience for diagnostic messages when it's default 4000.
set updatetime=300
" Highlight search results
set hlsearch
" Incremental search, search as you type
set incsearch
" Ignore case when searching
set ignorecase smartcase
" Ignore case when searching lowercase
set smartcase
" Deactivate Wrapping
set nowrap
" Treat all numbers as decimal
set nrformats=
" I don't like Swapfiles
set noswapfile
" Don't make a backup before overwriting a file.
set nobackup
" And again.
set nowritebackup
" I prefer , to be the leader key
let mapleader = ","
" show line numbers
set number relativenumber
augroup numbertoggle
autocmd!
autocmd BufEnter,FocusGained,InsertLeave * set relativenumber
autocmd BufLeave,FocusLost,InsertEnter * set norelativenumber
augroup END
" MOAR colors
set t_Co=256
" Unselect the search result
map <Leader><Space> :noh<CR>
" Better buffer handling
set hidden
" hightlight cursor position
set cursorline
" enable mouse
set mouse=a
set inccommand=split
" Use the clipboard of Mac OS
if has('mac')
set clipboard=unnamed
else
set clipboard=unnamedplus
endif
" Set the title of the iterm tab
set title
set diffopt=vertical,filler
autocmd FileType git set nofoldenable
let g:python3_host_prog = '/Users/toddpickell/.asdf/shims/python3'
set nocompatible
call plug#begin('~/.config/nvim/plugged')
" CtrlP: Full path fuzzy finder
Plug 'ctrlpvim/ctrlp.vim'
Plug 'tacahiroy/ctrlp-funky'
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'elixir-lsp/coc-elixir', {'do': 'yarn install && yarn prepack'}
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
let g:fzf_history_dir = '~/.local/share/fzf-history'
" Use tab for trigger completion with characters ahead and navigate.
" Use command ':verbose imap <tab>' to make sure tab is not mapped by other plugin.
inoremap <silent><expr> <TAB>
\ pumvisible() ? "\<C-n>" :
\ <SID>check_back_space() ? "\<TAB>" :
\ coc#refresh()
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
" Use <c-space> to trigger completion.
inoremap <silent><expr> <c-space> coc#refresh()
" Use `[g` and `]g` to navigate diagnostics
nmap <silent> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <Plug>(coc-diagnostic-next)
" Remap keys for gotos
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)
" Use K to show documentation in preview window
nnoremap <silent> K :call <SID>show_documentation()<CR>
function! s:show_documentation()
if (index(['vim','help'], &filetype) >= 0)
execute 'h '.expand('<cword>')
else
call CocAction('doHover')
endif
endfunction
" Highlight symbol under cursor on CursorHold
" autocmd CursorHold * silent call CocActionAsync('highlight')
" Remap for rename current word
nmap <leader>rn <Plug>(coc-rename)
" Remap for format selected region
xmap <leader>f <Plug>(coc-format-selected)
nmap <leader>f <Plug>(coc-format-selected)
nmap <leader>gf :GFiles<CR>
nnoremap <leader>fz :call fzf#vim#grep("rg --column --line-number --no-heading --color=always --smart-case -- ".shellescape(expand("<cword>")), 1, fzf#vim#with_preview(), 0)<CR>
"search project files by lines of code
nnoremap <leader>o :Lines<cr>
"search project files by tags (requirs ctags to be installed)
nnoremap <leader>D :put =strftime(\"# %Y-%m-%d\n\n- \")<CR>$a
nnoremap <leader>s :Rg
nnoremap <Leader>fu :CtrlPFunky<Cr>
" narrow the list down with a word under cursor
nnoremap <Leader>fU :execute 'CtrlPFunky ' . expand('<cword>')<Cr>
let g:ctrlp_funky_matchtype = 'path'
let g:ctrlp_funky_syntax_highlight = 1
" Borrowed from @skwp
if executable('ag')
" Use ag in CtrlP for listing files. Lightning fast and respects .gitignore
let g:ctrlp_user_command =
\ 'ag %s --files-with-matches -g "" --ignore "\.git$\|\.hg$\|\.svn$"'
" ag is fast enough that CtrlP doesn't need to cache
let g:ctrlp_use_caching = 0
else
" Fall back to using git ls-files if Ag is not available
let g:ctrlp_custom_ignore = '\.git$\|\.hg$\|\.svn$'
let g:ctrlp_user_command = ['.git', 'cd %s && git ls-files . --cached --exclude-standard --others']
endif
let g:ctrlp_working_path_mode = 0
let g:ctrlp_switch_buffer = 'e'
tnoremap <Esc> <C-\><C-n>
noremap <C-b> :CtrlPBuffer<CR>
let g:ctrlp_dont_split = 'NERD_tree_2'
" Nerdtree
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
let NERDTreeIgnore=['\.pyc$', '\.pyo$', '\.rbc$', '\.rbo$', '\.class$', '\.o$', '\~$']
noremap <C-n> :NERDTreeToggle<CR>
noremap <leader>n :NERDTreeToggle<CR>
" Git marker for nerdtree
Plug 'Xuyuanp/nerdtree-git-plugin'
let g:NERDTreeShowIgnoredStatus=0
" Better statusbar
"Plug 'bling/vim-airline'
"let g:airline_powerline_fonts = 1
"let g:airline#extensions#branch#displayed_head_limit = 17
"let g:airline#extensions#tabline#enabled = 1
"let g:airline_theme = 'tokyonight'
"let g:airline_section_z = airline#section#create(['windowswap', 'linenr', 'colnr'])
"call airline#parts#define_minwidth('branch', 120)
"set laststatus=2
"set statusline=%F%m%r%h%w[%L][%{&ff}]%y[%p%%][%04l,%04v]
Plug 'itchyny/lightline.vim'
" Color Theme
"Plug 'morhetz/gruvbox'
Plug 'NLKNguyen/papercolor-theme'
" Polyglot: A collection of language packs, loaded on demand
Plug 'sheerun/vim-polyglot'
" vue files need special handling because of their
" mix of different languages in one big file
autocmd FileType vue syntax sync fromstart
" ack.vim: ack integration
Plug 'mileszs/ack.vim'
if executable('rg')
let g:ackprg = 'rg --vimgrep -i'
endif
Plug 'tpope/vim-fugitive'
" Git Gutter: shows a git diff in the gutter
Plug 'airblade/vim-gitgutter'
" without any weird color
highlight clear SignColumn
" Better * search for selections.
" http://vimcasts.org/episodes/search-for-the-selected-text/
Plug 'nelstrom/vim-visual-star-search'
" Open Markdown files in Marked
Plug 'itspriddle/vim-marked'
noremap <leader>m :MarkedOpen<CR>
let g:marked_app = "Markoff"
" Toggle comment bloccks
Plug 'scrooloose/nerdcommenter'
" vue files have mixed content, so this
" informs nerdcommenter about that.
let g:ft = ''
function! NERDCommenter_before()
if &ft == 'vue'
let g:ft = 'vue'
let stack = synstack(line('.'), col('.'))
if len(stack) > 0
let syn = synIDattr((stack)[0], 'name')
if len(syn) > 0
exe 'setf ' . substitute(tolower(syn), '^vue_', '', '')
endif
endif
endif
endfunction
function! NERDCommenter_after()
if g:ft == 'vue'
setf vue
let g:ft = ''
endif
endfunction
Plug 'justinmk/vim-sneak'
Plug 'jeetsukumaran/vim-buffergator'
" create directory if it does not exist
Plug 'DataWraith/auto_mkdir'
" resize windows easily
Plug 'jimsei/winresizer'
" show git history in vim
Plug 'junegunn/gv.vim'
"Plug 'terryma/vim-multiple-cursors' deprecated
Plug 'mg979/vim-visual-multi', {'branch': 'master'}
" zoom current buffer
Plug 'troydm/zoomwintab.vim', { 'on': ['ZoomWinTabToggle', 'ZoomWinTabIn', 'ZoomWinTabOut'] }
nnoremap <silent> ,zz :ZoomWinTabToggle<cr>
" open files with vim file:123
Plug 'bogado/file-line'
" Tagging is all the rage
" TODO commented out on OSX fails on run could cause issue with lag
"Plug 'ludovicchabant/vim-gutentags'
"let g:gutentags_cache_dir = '~/.tags_cache'
function! DoRemote(arg)
UpdateRemotePlugins
endfunction
" the tab complete thing
"Plug 'Shougo/deoplete.nvim', { 'do': function('DoRemote'), 'tag': '*' }
"let g:deoplete#enable_at_startup = 1
"let g:deoplete#disable_auto_complete = 1
"inoremap <silent><expr> <TAB> pumvisible() ? "\<C-n>" : <SID>check_back_space() ? "\<TAB>" : deoplete#mappings#manual_complete()
function! s:check_back_space() abort "{{{
let col = col('.') - 1
return !col || getline('.')[col - 1] =~ '\s'
endfunction"}}}
" **[ experimental area - start ]************************************
Plug 'neomake/neomake'
autocmd! BufWritePost * Neomake
autocmd! BufReadPost * Neomake
let g:neomake_elixir_enabled_makers = ['mix']
"command Errors lopen
"
Plug 'jceb/vim-orgmode'
Plug 'honza/vim-snippets'
Plug 'junegunn/vim-easy-align'
Plug 'neovim/nvim-lspconfig'
Plug 'hrsh7th/nvim-compe'
Plug 'hrsh7th/vim-vsnip'
Plug 'hrsh7th/vim-vsnip-integ'
" Start interactive EasyAlign in visual mode (e.g. vipga)
xmap ga <Plug>(EasyAlign)
" Start interactive EasyAlign for a motion/text object (e.g. gaip)
nmap ga <Plug>(EasyAlign)
" Elixir
"Plug 'elixir-editors/vim-elixir'
Plug 'slashmili/alchemist.vim'
let g:alchemist_tag_disable = 1
Plug 'powerman/vim-plugin-AnsiEsc'
Plug 'c-brenn/phoenix.vim'
Plug 'tpope/vim-projectionist'
" github pull requests
Plug 'AndrewRadev/ginitpull.vim'
"Plug 'enricobacis/vim-airline-clock'
Plug 'janko-m/vim-test'
let test#strategy = "neovim"
nmap <leader>rn :TestNearest<CR>
nmap <leader>rf :TestFile<CR>
nmap <leader>ra :TestSuite<CR>
nmap <leader>rr :TestLast<CR>
nmap <leader>rv :TestVisit<CR>
Plug 'blueyed/vim-qf_resize'
Plug 'jreybert/vimagit'
nmap <silent> <leader>gs :Magit<CR>
"Plug 'Chiel92/vim-autoformat'
"let g:autoformat_autoindent = 0
"let g:autoformat_retab = 0
"let g:elixir_autoformat_enabled = 0
Plug 'mhinz/vim-mix-format'
let g:mix_format_on_save = 1
"Plug 'junegunn/rainbow_parentheses.vim'
"let g:rainbow#pairs = [['(', ')'], ['{', '}'], ['[', ']'], ['<<', '>>']]
Plug 'luochen1990/rainbow'
let g:rainbow_active = 1
Plug 'jiangmiao/auto-pairs'
Plug 'tpope/vim-abolish'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-endwise'
Plug 'junegunn/vim-peekaboo'
Plug 'ghifarit53/tokyonight-vim'
Plug 'rakr/vim-one'
call plug#end()
" COLORSCHEMES
set background=dark
" colorscheme Tomorrow-Night-Bright
"colorscheme gruvbox
"set background=light
"colorscheme PaperColor
if (has('nvim'))
let $NVIM_TUI_ENABLE_TRUE_COLOR=1
endif
if (has('termguicolors'))
set termguicolors
endif
let g:tokyonight_style = 'storm'
let g:tokyonight_enable_italic = 1
colorscheme tokyonight
"let g:one_allow_italics=1
"colorscheme one
" Show invisible characters:
" Tabs and trailing whitespace
set list
set listchars=tab:›\ ,trail:.
" Tabs should be 2 spaces
set tabstop=2
" Soft-Tabs should be 2 spaces
set softtabstop=2
" When shifting, use 2 spaces
set shiftwidth=2
" Use Soft-Tabs
set expandtab
" backspace through everything in insert mode
set backspace=indent,eol,start
" Makefiles require tabs
autocmd FileType make setlocal noexpandtab
" Highlight Characters that overstep the character limit
set colorcolumn=80
" Show the linebreak if wrapping is enabled
set showbreak=↪
" Automatically set the indent of a new line (local to buffer)
" from railsbros-dirk
set ai
" Disable output and VCS files
set wildignore+=*.o,*.out,*.obj,.git,*.rbc,*.rbo,*.class,.svn,*.gem
" Disable archive files
set wildignore+=*.zip,*.tar.gz,*.tar.bz2,*.rar,*.tar.xz
" Ignore bundler and sass cache
set wildignore+=*/vendor/gems/*,*/vendor/cache/*,*/.bundle/*,*/.sass-cache/*
" Disable temp and backup files
set wildignore+=*.swp,*~,._*
" Make sure all markdown files have the correct filetype
au BufRead,BufNewFile *.{md,markdown,mdown,mkd,mkdn,txt} set ft=markdown
au BufRead,BufNewFile *.{cehtml} set ft=html
" Set the Ruby filetype for a number of common Ruby files without .rb
au BufRead,BufNewFile {Berksfile,Vagrantfile,Procfile,config.ru,*.god,*.arb} set ft=ruby
" Treat JSON files like JavaScript
au BufNewFile,BufRead {*.json,*.jsm} set ft=javascript
" zsh themes are sh files
au BufNewFile,BufRead *.zsh-theme set ft=sh
" Added Javascript Template Support
au BufNewFile,BufRead *.ejs set filetype=jst
" Make cursor move by visual lines instead of file lines (when wrapping)
noremap k gk
noremap j gj
" upper/lower word
nnoremap <leader>u mQviwU`Q
nnoremap <leader>l mQviwu`Q
" upper/lower first char of word
nnoremap <leader>U mQgewvU`Q
nnoremap <leader>L mQgewvu`Q
" Convert snake_case to CamelCase
map <silent> <leader>+ :s/\(\%(\<\l\+\)\%(_\)\@=\)\\|_\(\l\)/\u\1\2/g<CR>
" Convert CamelCase to snake_case
map <silent> <leader>_ :s/\(\<\u\l\+\\|\l\+\)\(\u\)/\l\1_\l\2/g<CR>
" surround word with ?
nmap <leader>sw ysiw
" surround line with ?
nmap <leader>sl yss
" Move selected block
nnoremap <C-j> :m .+1<CR>==
nnoremap <C-k> :m .-2<CR>==
inoremap <C-j> <Esc>:m .+1<CR>==gi
inoremap <C-k> <Esc>:m .-2<CR>==gi
vnoremap <C-j> :m '>+1<CR>gv=gv
vnoremap <C-k> :m '<-2<CR>gv=gv
" ARROW KEYS ARE UNACCEPTABLE
"noremap <Left> <Nop>
"noremap <Right> <Nop>
"noremap <Up> <Nop>
"noremap <Down> <Nop>
" Show contents of registers and paste selected into the buffer
function! Reg()
reg
echo "Register: "
let char = nr2char(getchar())
if char != "\<Esc>"
execute "normal! \"".char."p"
endif
redraw
endfunction
command! -nargs=0 Reg call Reg()
" paste something using the paste mode
map <Leader>p :set paste<CR>o<esc>"*]p:set nopaste<cr>
" find merge conflict markers
nnoremap <silent> <leader>fc <ESC>/\v^[<=>]{7}( .*\|$)<CR>
" Replace selection with text in clipboard
vnoremap r "_dP
" Remember last location in file, but not for commit messages.
" see :help last-position-jump
au BufReadPost * if &filetype !~ '^git\c' && line("'\"") > 0 && line("'\"") <= line("$")
\| exe "normal! g`\"" | endif
" Spelling highlights in bright green
hi clear SpellBad
hi SpellBad ctermfg=red cterm=bold,underline
" Enable spell as default only for certain files
autocmd FileType markdown setlocal spell spelllang=en
autocmd BufNewFile,BufRead COMMIT_EDITMSG setlocal spell spelllang=en
" Switch spell checking language
command! American :set spelllang=en_us
" enable project based vimrc
set exrc
set secure
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment