|
" Cross-platform Vim Configuration goes in this file |
|
" |
|
" Contents |
|
" Main configuration |
|
" Visual Configuration |
|
" Shortcut Key Configuration |
|
" Fixes |
|
" Plugin Configuration |
|
" Private Configuration |
|
" |
|
|
|
" ----------- Main Configuration ---------------------------------- |
|
|
|
set nocompatible "don't need to keep compatibility with Vi |
|
filetype plugin indent on "enable detection, plugins and indenting in one step |
|
syntax on "Turn on syntax highlighting |
|
set encoding=utf-8 "Force UTF-8 encoding for special characters |
|
set ruler "Turn on the ruler |
|
set number "Show line numbers |
|
set scrolloff=10 "Keep 10 lines below cursor always |
|
set cursorline "underline the current line in the file |
|
set cursorcolumn "highlight the current column. Visible in GUI mode only. |
|
set colorcolumn=80 |
|
|
|
set background=dark "make vim use colors that look good on a dark background |
|
|
|
set showcmd "show incomplete cmds down the bottom |
|
set showmode "show current mode down the bottom |
|
set foldenable "enable folding |
|
set showmatch "set show matching parenthesis |
|
"set virtualedit=all "allow the cursor to go in to "invalid" places |
|
set incsearch "find the next match as we type the search |
|
set hlsearch "hilight searches by default |
|
set ignorecase "ignore case when searching |
|
|
|
set shiftwidth=2 "number of spaces to use in each autoindent step |
|
set tabstop=2 "two tab spaces |
|
set softtabstop=2 "number of spaces to skip or insert when <BS>ing or <Tab>ing |
|
set expandtab "spaces instead of tabs for better cross-editor compatibility |
|
set smarttab "use shiftwidth and softtabstop to insert or delete (on <BS>) blanks |
|
set shiftround "when at 3 spaces, and I hit > ... go to 4, not 5 |
|
set nowrap "no wrapping |
|
|
|
set backspace=indent,eol,start "allow backspacing over everything in insert mode |
|
"set cindent "recommended seting for automatic C-style indentation |
|
set autoindent "automatic indentation in non-C files |
|
"set copyindent "copy the previous indentation on autoindenting |
|
set smartindent |
|
|
|
set noerrorbells "don't make noise |
|
set wildmenu "make tab completion act more like bash |
|
set wildmode=list:longest "tab complete to longest common string, like bash |
|
|
|
"set mouse-=a "disable mouse automatically entering visual mode |
|
set mouse=a "enable mouse automatically entering visual mode |
|
set hidden "allow hiding buffers with unsaved changes |
|
set cmdheight=2 "make the command line a little taller to hide 'press enter to viem more' text |
|
|
|
set clipboard=unnamed,unnamedplus "Use system clipboard by default |
|
set splitright "splits open on the right. |
|
set splitbelow "splits open below existing window.. |
|
|
|
set exrc "enable per-directory .vimrc files |
|
set secure "disable unsafe stuff from local .vimrc files |
|
|
|
set laststatus=2 "always show status line |
|
set lazyredraw "Vim 8 syntax highlighting on macOS is slow. |
|
|
|
" Set up the backup directories to a central place. |
|
set backupdir=$HOME/tmp/backup// |
|
set directory=$HOME/tmp/backup// |
|
|
|
" ----------- Visual Configuration ---------------------------------- |
|
try |
|
colorscheme mycontrast |
|
catch |
|
colorscheme murphy |
|
endtry |
|
|
|
set statusline=%f%m%r%h%w[%l][%{&ff}]%y[%p%%][%04l,%04v][%n] |
|
" | | | | | | | | | | | | |
|
" | | | | | | | | | | | + current |
|
" | | | | | | | | | | | buffer |
|
" | | | | | | | | | | + current |
|
" | | | | | | | | | | column |
|
" | | | | | | | | | +-- current line |
|
" | | | | | | | | +-- current % into file |
|
" | | | | | | | +-- current syntax in |
|
" | | | | | | | square brackets |
|
" | | | | | | +-- current fileformat |
|
" | | | | | +-- number of lines |
|
" | | | | +-- preview flag in square brackets |
|
" | | | +-- help flag in square brackets |
|
" | | +-- readonly flag in square brackets |
|
" | +-- rodified flag in square brackets |
|
" +-- full path to file in the buffer |
|
|
|
" Use a bar-shaped cursor for insert mode, even through tmux. |
|
if has("gui_running") |
|
if exists('$TMUX') |
|
let &t_SI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=1\x7\<Esc>\\" |
|
let &t_EI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=0\x7\<Esc>\\" |
|
else |
|
let &t_SI = "\<Esc>]50;CursorShape=1\x7" |
|
let &t_EI = "\<Esc>]50;CursorShape=0\x7" |
|
endif |
|
endif |
|
|
|
" Use the same symbols as TextMate for tabstops and EOLs |
|
set listchars=tab:▸\ ,eol:¬ |
|
|
|
" ----------- Shortcut Key Configuration ---------------------------------- |
|
let mapleader = "," "remap leader to ',' which is much easier than '\' |
|
|
|
"Switch to previous file with ',spacebar' |
|
nmap <leader><SPACE> <C-^> |
|
|
|
" Open Taglist with [,s] |
|
map <Leader>s :TagbarToggle<CR> |
|
|
|
" Use leader x to remove the current line but not erase buffer |
|
map <Leader>x "_dd |
|
|
|
" Use leader l to rapidly toggle `set list` |
|
nmap <leader>l :set list!<CR> |
|
|
|
" Exit insert mode with jk |
|
imap jk <Esc> |
|
|
|
" Exit terminal mode with escape |
|
tnoremap <Leader><Esc> <C-w>N |
|
|
|
" reload configuration file |
|
map <Leader>r :so $MYVIMRC<CR> |
|
|
|
" ctags |
|
map <Leader>ct :!ctags -R --exclude=.git --exclude=db/dumps --exclude=tmp --exclude=coverage --exclude=log --exclude=.svn --verbose=yes * <CR> |
|
|
|
" Exit insert mode and save with jj |
|
imap jj <Esc>:w<CR> |
|
|
|
|
|
" visual indent with reselct |
|
vnoremap <Right> >gv |
|
vnoremap <Left> <gv |
|
|
|
" mapping to make movements operate on 1 screen line in wrap mode |
|
function! ScreenMovement(movement) |
|
if &wrap |
|
return "g" . a:movement |
|
else |
|
return a:movement |
|
endif |
|
endfunction |
|
onoremap <silent> <expr> j ScreenMovement("j") |
|
onoremap <silent> <expr> k ScreenMovement("k") |
|
onoremap <silent> <expr> 0 ScreenMovement("0") |
|
onoremap <silent> <expr> ^ ScreenMovement("^") |
|
onoremap <silent> <expr> $ ScreenMovement("$") |
|
nnoremap <silent> <expr> j ScreenMovement("j") |
|
nnoremap <silent> <expr> k ScreenMovement("k") |
|
nnoremap <silent> <expr> 0 ScreenMovement("0") |
|
nnoremap <silent> <expr> ^ ScreenMovement("^") |
|
nnoremap <silent> <expr> $ ScreenMovement("$") |
|
|
|
" Supports pasting in from the clipboard in the terminal |
|
" https://coderwall.com/p/if9mda/automatically-set-paste-mode-in-vim-when-pasting-in-insert-mode |
|
let &t_SI .= "\<Esc>[?2004h" |
|
let &t_EI .= "\<Esc>[?2004l" |
|
|
|
inoremap <special> <expr> <Esc>[200~ XTermPasteBegin() |
|
|
|
function! XTermPasteBegin() |
|
set pastetoggle=<Esc>[201~ |
|
set paste |
|
return "" |
|
endfunction |
|
|
|
" pastetoggle just in case |
|
set pastetoggle=<F2> |
|
|
|
|
|
" Navigate tabs |
|
map <leader>1 :tabp<CR> |
|
map <leader>2 :tabn<CR> |
|
|
|
" Turn text search highlight on/off with F5 key |
|
map <F5> :set hls!<bar>set hls?<CR> |
|
|
|
" double percentage sign in command mode is expanded |
|
" to directory of current file - http://vimcasts.org/e/14 |
|
cnoremap %% <C-R>=expand('%:h').'/'<cr> |
|
|
|
" insert blank line above in Normal mode |
|
nnoremap <leader>O mzO<esc>`z |
|
|
|
" insert blank line below in Normal mode |
|
nnoremap <leader>o mzo<esc>`z |
|
|
|
" Sort CSS properties alphabetically |
|
nnoremap <leader>css :g#\({\n\)\@<=#.,/}/sort<cr> |
|
|
|
" -- Number toggling |
|
function! NumberToggle() |
|
if(&relativenumber == 1) |
|
set norelativenumber |
|
else |
|
set relativenumber |
|
endif |
|
endfunc |
|
|
|
nnoremap <F7> :call NumberToggle()<cr> |
|
|
|
" Toggle background color for light and dark. |
|
" Default is dark. |
|
function! ColorToggle() |
|
if(g:colors_name == "mycontrast") |
|
colorscheme zellner |
|
else |
|
colorscheme mycontrast |
|
endif |
|
endfunc |
|
|
|
nnoremap <F8> :call ColorToggle()<cr> |
|
|
|
" Spell check toggle |
|
map <leader>sp :setlocal spell! spelllang=en_us<CR> |
|
|
|
nmap <leader>msp :mkspell! ~/.vim/spell/en.utf-8.add<CR><CR> |
|
|
|
" ---- Syntax inspector via vimcasts |
|
|
|
" Show syntax highlighting groups for word under cursor with CtrlShiftR |
|
function! <SID>SynStack() |
|
if !exists("*synstack") |
|
return |
|
endif |
|
echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")') |
|
endfunc |
|
|
|
" nmap <C-S-R> :call <SID>SynStack()<CR> |
|
|
|
|
|
" ----------- Digraphs ------- |
|
|
|
silent! dig -. 8230 "U+2026=… HORIZONTAL ELLIPSIS |
|
|
|
" ----------- quickfix ------- |
|
|
|
" ,q to toggle quickfix window (where you have stuff like GitGrep) |
|
" ,oq to open it back up (rare) |
|
nmap <silent> ,cq :cclose<CR> |
|
nmap <silent> ,co :copen<CR> |
|
|
|
" ----------- Fixes ---------------------------------- |
|
" |
|
" html |
|
let g:html_indent_script1 = "inc" |
|
let g:html_indent_style1 = "inc" |
|
|
|
" fix syntax highlighting in Ruby by using the older regex engine for Ruby |
|
" files |
|
autocmd FileType ruby setlocal re=1 |
|
|
|
" ----------- Plugin Configuration ---------------------------------- |
|
|
|
" ---- NERDTree configuration |
|
|
|
" Open NERDTree with [,d] |
|
map <Leader>d :NERDTreeToggle<CR> |
|
|
|
let NERDTreeShowLineNumbers=1 |
|
let NERDTreeMinimalUI=1 |
|
let NERDTreeShowHidden=1 |
|
let g:nerdtree_tabs_focus_on_files=1 |
|
let g:nerdtree_tabs_open_on_console_startup=1 |
|
let g:NERDTreeWinPos = "left" |
|
|
|
" ---- Commenter ---- |
|
" For nerdcommenter, add one space after comment char |
|
let NERDSpaceDelims=1 |
|
|
|
" ---- Ragtag ----- |
|
let g:ragtag_global_maps = 1 |
|
|
|
" ---- CTRL-P configuration |
|
" Open fuzzy finder with leader,f |
|
map <Leader>f :CtrlP<CR> |
|
|
|
" Fuzzy finder for buffers |
|
map <Leader>b :CtrlPBuffer<CR> |
|
|
|
" Exclude files from ctrl-p finder |
|
let g:ctrlp_custom_ignore = '\.git$\|\.hg$\|\.svn$\|node_modules$' |
|
|
|
" ---- ack |
|
" Open ack and ackg |
|
map <Leader>A :AckG |
|
map <Leader>a :Ack |
|
|
|
" ---- Snipmate |
|
let g:snipMate = {} |
|
let g:snipMate.snippet_version = 1 |
|
|
|
" ---- wiki |
|
|
|
" only use wiki syntax under vimwiki folders |
|
let g:vimwiki_global_ext = 0 |
|
|
|
let g:vimwiki_list = [{'path': '~/vimwiki/', |
|
\ 'syntax': 'markdown', 'ext': '.md'}] |
|
|
|
" ---- markdown configs |
|
|
|
let g:vim_markdown_folding_disabled = 1 |
|
" highlight YAML frontmatter |
|
let g:vim_markdown_frontmatter = 1 |
|
|
|
" create links from clipboard |
|
|
|
" create link out of word using clipboard text as link destination |
|
autocmd FileType markdown nnoremap <Leader>4 "aciw[<C-r>"](<Esc>"*pli)<Esc> |
|
|
|
" create link out of selection using clipboard text as link destination |
|
autocmd FileType markdown vnoremap <Leader>4 "ac[<C-r>"](<Esc>"*pli)<Esc> |
|
|
|
" ---- vim-rooter configs |
|
let g:rooter_targets = '/,*' |
|
|
|
" ---- vimux configs |
|
|
|
let VimuxHeight = "33" "this is percentage |
|
|
|
" Inspect runner pane |
|
map <Leader>vi :VimuxInspectRunner<CR> |
|
|
|
" Close vim tmux runner opened by RunVimTmuxCommand |
|
map <Leader>vq :VimuxCloseRunner<CR> |
|
|
|
" If text is selected, save it in the v buffer and send that buffer it to tmux |
|
vmap <Leader>vs "vy :call VimuxRunCommand(@v . "\n", 0)<CR> |
|
|
|
" Select current paragraph and send it to tmux |
|
nmap <Leader>vs vip<LocalLeader>vs<CR> |
|
|
|
" ----------- Mustache / Handlebars --------------------------------- |
|
let g:mustache_abbreviations = 1 |
|
|
|
" ----------- ALE configs --------------------------------------- |
|
let g:ale_sign_column_always = 1 |
|
let g:ale_sign_error = '>>' |
|
let g:ale_sign_warning = '--' |
|
let g:ale_open_list = 0 |
|
let g:ale_keep_list_window_open = 0 |
|
let g:ale_list_vertical = 0 |
|
let g:ale_lint_on_enter = 1 |
|
" let g:ale_completion_enabled = 1 |
|
" set omnifunc=ale#completion#OmniFunc |
|
|
|
" Map keys to navigate between lines with errors and warnings. |
|
nnoremap <leader>an :ALENextWrap<cr> |
|
nnoremap <leader>ap :ALEPreviousWrap<cr> |
|
|
|
" ----------- vue configs ------------------- |
|
" limit preprocessors to speed up vim. |
|
let g:vue_pre_processors = ["scss"] |
|
|
|
" ----------- Dispatch configs --------------------------------------- |
|
|
|
autocmd FileType coffee let b:dispatch = 'coffee -c %' |
|
autocmd BufEnter *_test.exs let b:dispatch = 'mix test %' |
|
|
|
nnoremap <Leader>e :Dispatch<CR> |
|
|
|
" ----------- quoting ----------- |
|
augroup textobj_quote |
|
autocmd! |
|
autocmd FileType markdown call textobj#quote#init() |
|
autocmd FileType textile call textobj#quote#init() |
|
augroup END |
|
|
|
" ---------- Go ------- |
|
autocmd FileType go setlocal ts=4 sts=4 sw=4 noexpandtab |
|
|
|
" ---------- EEX Elixir templates ------- |
|
autocmd BufRead,BufNewFile *.eex set ft=eex.html |
|
|
|
" ----------- Launch configs --------------------------------------- |
|
if has('win32') || has ('win64') |
|
let $CLEAR_COMMAND="cls" |
|
else |
|
let $CLEAR_COMMAND="clear" |
|
endif |
|
|
|
autocmd FileType ruby nmap <Leader>g :!"$CLEAR_COMMAND"; ruby "%"<cr> |
|
autocmd filetype java nmap <Leader>g :!"$CLEAR_COMMAND"; javac "%" && java "%:r"<cr> |
|
|
|
if has('win32') || has ('win64') |
|
autocmd FileType html nmap <Leader>g :silent ! start firefox "%"<cr> |
|
elseif has('mac') |
|
autocmd FileType html nmap <Leader>g :!open "%"<cr><cr> |
|
endif |
|
|
|
autocmd FileType javascript nmap <Leader>g :!"$CLEAR_COMMAND"; node "%"<cr> |
|
autocmd FileType coffee nmap <Leader>g :!"$CLEAR_COMMAND"; coffee "%"<cr> |
|
autocmd FileType markdown nmap <Leader>g :!mark "%"<cr><cr> |
|
autocmd FileType groovy nmap <Leader>g :!"$CLEAR_COMMAND"; groovy "%"<cr> |
|
autocmd FileType sh nmap <Leader>g :!"$CLEAR_COMMAND"; sh "%"<cr> |
|
autocmd FileType python nmap <Leader>g :!"$CLEAR_COMMAND"; python3 "%"<cr> |
|
autocmd FileType elixir nmap <Leader>g :!"$CLEAR_COMMAND"; elixir "%"<cr> |
|
autocmd FileType elixir nmap <Leader>t :!"$CLEAR_COMMAND"; mix test<cr> |
|
autocmd FileType elm nmap <Leader>g :!"$CLEAR_COMMAND"; elm make "%" --output "%:t:r.html" && open "%:t:r.html"<cr><cr> |
|
" Elixir tests should run mix |
|
autocmd BufEnter *_test.exs nmap <Leader>g :!"$CLEAR_COMMAND"; mix test<cr> |
|
|
|
" run :GoBuild or :GoTestCompile based on the go file |
|
function! s:build_go_files() |
|
let l:file = expand('%') |
|
if l:file =~# '^\f\+_test\.go$' |
|
call go#test#Test(0, 1) |
|
elseif l:file =~# '^\f\+\.go$' |
|
call go#cmd#Build(0) |
|
endif |
|
endfunction |
|
|
|
autocmd FileType go nmap <leader>b :<C-u>call <SID>build_go_files()<CR> |
|
autocmd FileType go nmap <leader>t <Plug>(go-test) |
|
autocmd FileType go nmap <leader>g <Plug>(go-run) |
|
|
|
" ----------- Private Configuration ---------------------------------- |
|
|
|
try |
|
source ~/.vim/vimrc_private |
|
catch |
|
" no file. |
|
endtry |
That is.... tidy. Very. Tidy. very. tidy.