vim - sample vimrc configurations for reference
Table of Contents
Reading material
- https://www.reddit.com/r/vim/comments/5yfodc/what_are_some_good_vimrc_boilerplates_for_noobs/
- https://www.freecodecamp.org/news/vimrc-configuration-guide-customize-your-vim-editor/
1
This is an overview of how I customize and use Vim to get great work done quickly! It’s a bit all over the place, but it covers the most powerful plugins and customizations I’ve found over nearly ten years to make people think I know what I’m doing.
Here’s my .vimrc: https://github.com/jeremyckahn/dotfiles/blob/master/.vimrc
2 VerzolaVimrc.txt
" verzola's .vimrc
" https://github.com/verzola/.vimrc
" released under the WTFPL v2 license
"
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" Plugins
call plug#begin('~/.local/share/nvim/plugged')
Plug 'airblade/vim-gitgutter' " Git diff in the gutter
Plug 'airblade/vim-rooter' " Find project root
Plug 'editorconfig/editorconfig-vim' " Editorconfig support
Plug 'jistr/vim-nerdtree-tabs' " NERDTree tabs
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } } " Fuzzy finder
Plug 'junegunn/fzf.vim' " Fuzzy finder vim integration
Plug 'mattn/emmet-vim' " Emmet
Plug 'mhinz/vim-startify' " Fancy start screen for Vim
Plug 'othree/html5.vim' " Better HTML5 support
Plug 'pangloss/vim-javascript' " Better JS support
Plug 'prettier/vim-prettier', { 'do': 'yarn install' } " Prettier support
Plug 'ryanoasis/vim-devicons' " Glyphs and icons
Plug 'scrooloose/nerdtree' " Tree explorer
Plug 'terryma/vim-multiple-cursors' " Multiple cursors support
Plug 'tpope/vim-commentary' " Fast commenter
Plug 'tpope/vim-fugitive' " Git wrapper
Plug 'tpope/vim-repeat' " Repeat plugin actions
Plug 'tpope/vim-surround' " Fast surround
Plug 'vim-airline/vim-airline' " Light tabline
Plug 'vim-airline/vim-airline-themes' " Light tabline themes
Plug 'w0rp/ale' " Async linter
Plug 'yggdroot/indentline' " Display indention levels
Plug 'tpope/vim-sensible' " Better defaults
" Not always used plugins
Plug 'stephpy/vim-php-cs-fixer'
Plug 'lumiliet/vim-twig'
Plug 'posva/vim-vue'
Plug 'mxw/vim-jsx' " JSX support
Plug 'jwalton512/vim-blade'
" Colorschemes
Plug 'dracula/vim', { 'as': 'dracula' } " Dracula colorscheme
Plug 'hashivim/vim-terraform'
Plug 'nathanaelkane/vim-indent-guides'
Plug 'junegunn/vim-emoji'
call plug#end()
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" Checks
" Create undo-dir if it does not exists
if !isdirectory($HOME."/.vim-undo")
call mkdir($HOME."/.vim-undo", "", 0700)
endif
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" Settings
" Colors
set background=dark " Use colors that suit a dark background
colorscheme dracula " Change colorscheme
set termguicolors " Enable 24-bit colors on terminal
syntax enable " Enable syntax highlighting
" Basic
"set display+=lastline " Always try to show a paragraph’s last line
set encoding=utf-8 " Set encoding to utf-8
set number " Show line numbers on the sidebar
" Maps
let mapleader = "," " Redefines leader key
set pastetoggle=<F12> " Key to toggle paste mode
" Autocomplete
"set complete-=i " Limit the files searched for auto-completes
set completeopt=longest,menuone " Show popup with completions
"set wildmenu " Autocomplete menu
set wildmode=list:longest,full " Autocomplete for commands
" Editting
"set autoread " Automatically re-read files if unmodified inside Vim
"set backspace=indent,eol,start " Allow backspacing over indention, line breaks and insertion start
set colorcolumn=0 " Set column rule
set cursorline " Highlight the line currently under cursor
set formatoptions+=j " Delete comment character when joining commented lines
set hidden " Hide files in the background instead of closing them
set list " Hightlight unwanted spaces
"set listchars=tab:>\ ,trail:-,extends:>,precedes:<,nbsp:+
"set nrformats-=octal " Interpret octal as decimal when incrementing numbers
set scrolloff=5 " The number of screen lines to keep above and below the cursor
set showmatch " Show matching delimitator
set sidescrolloff=5 " The number of screen columns to keep to the left and right of the cursor
set virtualedit=onemore " Allow cursor to go to end of line
" Status bar
set laststatus=0 " Do not show default status bar
set noruler " Do not show cursor position
set noshowcmd " Do not show commands letters
set noshowmode " Do not show actual mode
" Backup
set nobackup " Disable backup files
set noswapfile " Disable swap files
set nowritebackup " Disable backup files
" Undo
set undodir=~/.vim-undo " Set undofiles folder
set undofile " Create undo file to allow undo across exits
set undolevels=1000 " Size of undo history
" History
"set history=1000 " Increase the undo limit
" Bell
set belloff=all " Remove annoying bell
" Mouse
set mouse=a " Enable mouse for scrolling and resizing
set mousehide " Hide mouse when typing
" Split
set splitbelow " Create horizontal split on the bottom
set splitright " Create vertical split on the right
" Indentation
"filetype plugin indent on " Enable indentation rules that are file-type specific
"set autoindent " New lines inherit the indentation of previous lines.
set copyindent " Copy indentation from existing lines
set expandtab " Convert tabs to spaces
set linebreak " Avoid wrapping a line in the middle of a word
set shiftround " When shifting lines, round the indentation to the nearest multiple of “shiftwidth.”
set shiftwidth=2 " When shifting, indent using four spaces
set smartindent " Smart indent
"set smarttab " Insert “tabstop” number of spaces when the “tab” key is pressed
set softtabstop=2 " Indentation setting
set tabstop=2 " Indent using four spaces
set nowrap " Disable line wrapping
" Search
set hlsearch " Enable search highlighting
set ignorecase " Ignore case when searching
"set incsearch " Incremental search that shows partial matches
set smartcase " Automatically switch search to case-sensitive when search query contains an uppercase letter
" Performance
set lazyredraw " Don’t update screen during macro and script execution
set updatetime=250 " The length of time Vim waits after you stop typing before it triggers the plugin
" Vim only settings
"set ttimeout
"set ttimeoutlen=100
set ttyfast " Fast terminal connection (only for vim)
" GUI-only options
if has("gui_running")
set guioptions-=m " Remove menu bar
set guioptions-=T " Remove toolbar
set guioptions-=r " Remove right-hand scroll bar
set guioptions-=L " Remove left-hand scroll bar
" Set font
if has('win32')
set guifont=FantasqueSansMono\ Nerd\ Font\ Mon:h11:cANSI:qDRAFT
endif
if has('unix')
set guifont=FantasqueSansMono\ NF\ 12
endif
endif
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" Mappings
" Edit my .vimrc
nnoremap <leader>ev :vsplit $MYVIMRC<CR>
" Source my .vimrc
nnoremap <leader>sv :source $MYVIMRC<CR>
" Clear search
"nnoremap <silent> <C-L> :nohlsearch<C-R>=has('diff')?'<Bar>diffupdate':''<CR><CR><C-L>
" Remove arrow keys
inoremap <Up> <nop>
inoremap <Down> <nop>
inoremap <Left> <nop>
inoremap <Right> <nop>
vnoremap <Up> <nop>
vnoremap <Down> <nop>
vnoremap <Left> <nop>
vnoremap <Right> <nop>
" Map arrow keys to scroll
noremap <Down> <c-e>
noremap <Up> <c-y>
noremap <Right> <c-e>
noremap <Left> <c-y>
" System clipboard mappings
vmap <leader>y "+y
vmap <leader>p "+p
vmap <leader>P "+P
vmap <leader>d "+d
nmap <leader>p "+p
nmap <leader>P "+P
" Fast write
nnoremap <leader>w :w!<CR>
" Trip all trailing whitespace in the current file
nnoremap <leader>W :%s/\s\+$//<cr>:let @/=''<CR>
" Fast quit
nnoremap <leader>q :q!<CR>
" Fast write & quit
nnoremap <leader>x :x<CR>
" Force save as sudo
cmap w!! w !sudo tee % >/dev/null
" Move to the next buffer
nmap <leader>l :bnext<CR>
nnoremap <PageDown> :bnext<CR>
" Move to the previous buffer
nmap <leader>k :bprevious<CR>
nnoremap <PageUp> :bprevious<CR>
" Close the current buffer and move to the previous one
nmap <leader>bq :bp <BAR> bd #<CR>
" Remap tab to bracket in normal mode
nnoremap <tab> %
" Remap tab to match in visual mode
vnoremap <tab> %
" Shortcut to fast exit insert mode
inoremap jk <esc>
" Relative numbering
nnoremap <leader>r :set relativenumber!<CR>
" Map to sort in visual mode
vnoremap <leader>s :'<,'>sort<CR>
" Easier moving of code blocks
vnoremap < <gv
vnoremap > >gv
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" Abbreviations
ab :ok: ✅
ab :no: ❌
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" Auto commands
" Remember last line on file
autocmd BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
" Indentation settings for typescript
autocmd FileType typescript set tabstop=2|set shiftwidth=2|set expandtab
autocmd FileType javascript set tabstop=2|set shiftwidth=2|set expandtab
autocmd FileType php set tabstop=4|set shiftwidth=4|set expandtab
" Auto insert mode if terminal
autocmd BufEnter * if &buftype == 'terminal' | :startinsert | endif
" transparent bg
autocmd vimenter * hi Normal guibg=NONE ctermbg=NONE
" For Vim<8, replace EndOfBuffer by NonText
autocmd vimenter * hi EndOfBuffer guibg=NONE ctermbg=NONE
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" NERDTree
let g:NERDTreeAutoDeleteBuffer = 1 " Automatically delete the buffer of the file you just deleted with NERDTree:
let g:NERDTreeMinimalUI = 1 " Change to minimal UI
let g:NERDTreeDirArrows = 1
let g:NERDTreeDirArrowExpandable = ''
let g:NERDTreeDirArrowCollapsible = ''
let g:NERDTreeQuitOnOpen = 1 " Quit NERDTree after open file
let g:NERDTreeShowBookmarks = 1 " Show bookmarks on NERDTree
let g:NERDTreeShowHidden = 1 " Show hidden files on NERDTree
let g:NERDTreeShowLineNumbers = 1 " Show line numbers on NERDTree
let g:nerdtree_tabs_open_on_gui_startup = 0 " Do not show NERDTree on startup
" Auto close NERDTree if it is the only left
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
" Toggle NERDtree
noremap <C-e> :NERDTreeMirrorToggle<CR>
" Bookmark file/folder in NERDTree
nnoremap <leader>nb :Bookmark<CR>
" Find current file on NERDTree
noremap <silent> <leader>nf :NERDTreeFind<CR>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" Airline
let g:airline#extensions#tabline#enabled = 1 " Enable airline because it is disabled by default
let g:airline#extensions#tabline#fnamemod = ':t' " Show full file name instead of abbreviations
let g:airline_powerline_fonts = 1 " Use powerline fonts for airline
let g:airline_theme='dracula' " Match airline theme with vim colorscheme
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" DevIcons
let g:webdevicons_conceal_nerdtree_brackets = 1 " Do not show brackets around icons in NERDTree
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" Emmet
let g:user_emmet_leader_key='<Tab>' " Use tab to expand emmet expressions
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" Ale
let g:ale_fixers = {}
let g:ale_fixers.javascript = ['eslint']
let g:ale_sign_error = '' " Less aggressive than the default '>>'
let g:ale_sign_warning = ''
let g:ale_lint_on_enter = 0 " Less distracting when opening a new file
let g:ale_fix_on_save = 1
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" Fugitive
nnoremap <leader>ga :Git add %:p<CR><CR>
nnoremap <leader>gs :Gstatus<CR>
nnoremap <leader>gc :Gcommit -v -q<CR>
nnoremap <leader>gd :Gdiff<CR>
nnoremap <leader>gp :Gpush<CR>
nnoremap <leader>gu :Gpull<CR>
nnoremap <leader>gbl :Gblame<CR>
nnoremap <leader>gl :silent! Glog<CR>:bot copen<CR>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" Vim plug
" Install plugins
nnoremap <leader>pi :PlugInstall<CR>
" Update plugins
nnoremap <leader>pu :PlugUpdate<CR>
" Clean removed plugins
nnoremap <leader>pc :PlugClean<CR>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" Fzf
" Open fzf using ctrlp shortcut
nmap <C-p> :Files<CR>
imap <C-p> <Esc>:Files<CR>
vmap <C-p> <Esc>:Files<CR>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" Startify
" Startify on new tab
autocmd! TabNew * Startify
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" Nvim
" Split terminal (nvim only)
if has('nvim')
" Open terminal horizontally
nmap <leader>t :split term://zsh<CR>
" Open terminal vertically
nmap <leader>vt :vsplit term://zsh<CR>
" Map Esc to leave terminal mode
tnoremap <Esc> <C-\><C-n>
" Navigate splits with Alt+hjkl
tnoremap <A-h> <C-\><C-N><C-w>h
tnoremap <A-j> <C-\><C-N><C-w>j
tnoremap <A-k> <C-\><C-N><C-w>k
tnoremap <A-l> <C-\><C-N><C-w>l
inoremap <A-h> <C-\><C-N><C-w>h
inoremap <A-j> <C-\><C-N><C-w>j
inoremap <A-k> <C-\><C-N><C-w>k
inoremap <A-l> <C-\><C-N><C-w>l
nnoremap <A-h> <C-w>h
nnoremap <A-j> <C-w>j
nnoremap <A-k> <C-w>k
nnoremap <A-l> <C-w>l
else
map <C-j> <C-W>j
map <C-k> <C-W>k
map <C-h> <C-W>h
map <C-l> <C-W>l
endif
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" Devicons
hi Normal guibg=NONE ctermbg=NONE
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" Emoji
set completefunc=emoji#complete
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" Git Gutter
let g:gitgutter_sign_added = emoji#for('small_blue_diamond')
let g:gitgutter_sign_modified = emoji#for('small_orange_diamond')
let g:gitgutter_sign_removed = emoji#for('small_red_triangle')
let g:gitgutter_sign_modified_removed = emoji#for('collision')
3 thoughtstream_DamianConway_Vim_Setup.md
https://github.com/thoughtstream/Damian-Conway-s-Vim-Setup
---------------------------------------------------------------
"=====[ Avoid modeline vulnerability ]===========================
set nomodeline
"=====[ Not a fan of mapleader mappings ]===========================
let mapleader = '_'
"=====[ Convert to Unicode defaults ]===============================
setglobal termencoding=utf-8 fileencodings=
scriptencoding utf-8
set encoding=utf-8
autocmd BufNewFile,BufRead * try
autocmd BufNewFile,BufRead * set encoding=utf-8
autocmd BufNewFile,BufRead * endtry
"====[ Ensure autodoc'd plugins are supported ]===========
runtime plugin/_autodoc.vim
"====[ Work out what kind of file this is ]========
filetype plugin indent on
augroup FiletypeInference
autocmd!
autocmd BufNewFile,BufRead *.t setfiletype perl
autocmd BufNewFile,BufRead *.pod setfiletype pod
autocmd BufNewFile,BufRead *.itn setfiletype itn
autocmd BufNewFile,BufRead * call s:infer_filetype()
augroup END
function! s:infer_filetype ()
for line in getline(1,20)
if line =~ '^\s*use\s*v\?5\.\S\+\s*;\s*$'
setfiletype perl
return
elseif line =~ '^\s*use\s*v\?6\s*;\s*$'
setfiletype perl6
return
endif
endfor
endfunction
"=====[ Comments are important ]==================
highlight Comment term=bold cterm=italic ctermfg=white gui=italic guifg=white
"=====[ Enable Nmap command for documented mappings ]================
runtime plugin/documap.vim
"====[ Escape insert mode via 'jj' ]=============================
imap jj <ESC>
"====[ Edit and auto-update this config file and plugins ]==========
augroup VimReload
autocmd!
autocmd BufWritePost $MYVIMRC source $MYVIMRC
augroup END
Nmap <silent> ;v [Edit .vimrc] :next $MYVIMRC<CR>
Nmap ;vv [Edit .vim/plugin/...] :next ~/.vim/plugin/
"====[ Edit my temporary working files ]====================
Nmap tt [Edit temporary files] :next ~/tmp/temporary_file
"=====[ Edit files in local bin directory ]========
Nmap ;b [Edit ~/bin/...] :next ~/bin/
"=====[ Some of Vim's defaults are just annoying ]============
" :read and :write shouldn't set #
set cpo-=aA
" Make /g the default on :s/.../../ commands (use /gg to disable)
"set gdefault
" Prefer vertical orientation when using :diffsplit
set diffopt+=vertical
"====[ Go back to alternate file (but retain other g<whatever> mappings)]====
nmap g :w<CR>:e #<CR>
function! s:conditional_nnoremap ( name )
if maparg(a:name, 'n') == ""
execute 'nnoremap <unique> ' . a:name . ' ' . a:name
endif
endfunction
call s:conditional_nnoremap( 'g,' )
call s:conditional_nnoremap( 'g;' )
call s:conditional_nnoremap( 'g~' )
call s:conditional_nnoremap( 'g~~' )
call s:conditional_nnoremap( 'g~g~' )
call s:conditional_nnoremap( 'g#' )
call s:conditional_nnoremap( 'g$' )
call s:conditional_nnoremap( 'g&' )
call s:conditional_nnoremap( "g'" )
call s:conditional_nnoremap( 'g*' )
call s:conditional_nnoremap( 'g0' )
call s:conditional_nnoremap( 'g8' )
call s:conditional_nnoremap( 'g<' )
call s:conditional_nnoremap( 'g<C-G>' )
call s:conditional_nnoremap( 'g<C-H>' )
call s:conditional_nnoremap( 'g<C-]>' )
call s:conditional_nnoremap( 'g<Down>' )
call s:conditional_nnoremap( 'g<End>' )
call s:conditional_nnoremap( 'g<Home>' )
call s:conditional_nnoremap( 'g<LeftMouse>' )
call s:conditional_nnoremap( 'g<MiddleMouse>' )
call s:conditional_nnoremap( 'g<RightMouse>' )
call s:conditional_nnoremap( 'g<Up>' )
call s:conditional_nnoremap( 'g?' )
call s:conditional_nnoremap( 'g??' )
call s:conditional_nnoremap( 'g?g?' )
call s:conditional_nnoremap( 'g@' )
call s:conditional_nnoremap( 'gD' )
call s:conditional_nnoremap( 'gE' )
call s:conditional_nnoremap( 'gF' )
call s:conditional_nnoremap( 'gH' )
call s:conditional_nnoremap( 'gI' )
call s:conditional_nnoremap( 'gJ' )
call s:conditional_nnoremap( 'gP' )
call s:conditional_nnoremap( 'gR' )
call s:conditional_nnoremap( 'gU' )
call s:conditional_nnoremap( 'gUU' )
call s:conditional_nnoremap( 'gUgU' )
call s:conditional_nnoremap( 'gV' )
call s:conditional_nnoremap( 'g]' )
call s:conditional_nnoremap( 'g^' )
call s:conditional_nnoremap( 'g`' )
call s:conditional_nnoremap( 'ga' )
call s:conditional_nnoremap( 'gd' )
call s:conditional_nnoremap( 'ge' )
call s:conditional_nnoremap( 'gf' )
call s:conditional_nnoremap( 'gg' )
call s:conditional_nnoremap( 'gh' )
call s:conditional_nnoremap( 'gi' )
call s:conditional_nnoremap( 'gj' )
call s:conditional_nnoremap( 'gk' )
call s:conditional_nnoremap( 'gm' )
call s:conditional_nnoremap( 'go' )
call s:conditional_nnoremap( 'gp' )
call s:conditional_nnoremap( 'gq' )
call s:conditional_nnoremap( 'gr' )
call s:conditional_nnoremap( 'gs' )
call s:conditional_nnoremap( 'gu' )
call s:conditional_nnoremap( 'gugu' )
call s:conditional_nnoremap( 'guu' )
call s:conditional_nnoremap( 'gv' )
call s:conditional_nnoremap( 'gw' )
"call s:conditional_nnoremap( 'gx' )
" Make gn jump into visual block mode, instead if plain visual mode
nnoremap gn gn<C-V>
"====[ Use persistent undo ]=================
if has('persistent_undo')
" Save all undo files in a single location (less messy, more risky)...
set undodir=$HOME/.VIM_UNDO_FILES
" Save a lot of back-history...
set undolevels=5000
" Actually switch on persistent undo
set undofile
endif
"====[ Goto last location in non-empty files ]=======
autocmd BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$")
\| exe "normal! g`\""
\| endif
"====[ I'm sick of typing :%s/.../.../g ]=======
Nmap S [Shortcut for :s///g] :%s//g<LEFT><LEFT>
xmap S :s//g<LEFT><LEFT>
Nmap <expr> M [Shortcut for :s/<last match>//g] ':%s/' . @/ . '//g<LEFT><LEFT>'
xmap <expr> M ':s/' . @/ . '//g<LEFT><LEFT>'
"====[ Toggle visibility of naughty characters ]============
" Make naughty characters visible...
" (uBB is right double angle, uB7 is middle dot)
set lcs=tab:»·,trail:␣,nbsp:˷
highlight InvisibleSpaces ctermfg=Black ctermbg=Black
call matchadd('InvisibleSpaces', '\S\@<=\s\+\%#\ze\s*$')
augroup VisibleNaughtiness
autocmd!
autocmd BufEnter * set list
autocmd BufEnter * set list
autocmd BufEnter *.txt set nolist
autocmd BufEnter *.vp* set nolist
autocmd BufEnter * if !&modifiable
autocmd BufEnter * set nolist
autocmd BufEnter * endif
augroup END
"====[ Set up smarter search behaviour ]=======================
set incsearch "Lookahead as search pattern is specified
set ignorecase "Ignore case in all searches...
set smartcase "...unless uppercase letters used
set hlsearch "Highlight all matches
highlight clear Search
highlight Search ctermfg=White ctermbg=Black cterm=bold
highlight IncSearch ctermfg=White ctermbg=Red cterm=bold
" Absolute direction for n and N...
nnoremap <silent><expr> n 'Nn'[v:searchforward] . ":call HLNext()\<CR>"
nnoremap <silent><expr> N 'nN'[v:searchforward] . ":call HLNext()\<CR>"
"Delete in normal mode to switch off highlighting till next search and clear messages...
Nmap <silent> <BS> [Cancel highlighting] :call HLNextOff() <BAR> :nohlsearch <BAR> :call VG_Show_CursorColumn('off')<CR>::HierClear<CR>
"Double-delete to remove trailing whitespace...
Nmap <silent> <BS><BS> [Remove trailing whitespace] mz:call TrimTrailingWS()<CR>`z
function! TrimTrailingWS ()
if search('\s\+$', 'cnw')
:%s/\s\+$//g
endif
endfunction
"====[ Set background hint (if possible) ]=============
"if $VIMBACKGROUND != ""
" exec 'set background=' . $VIMBACKGROUND
"else
" set background=dark
"endif
set background=dark
"=====[ Enable smartwrapping ]==================================
" No smartwrapping in any of these files...
"let g:SW_IGNORE_FILES = '.vimrc,*.vim,*.pl,*.pm,**/bin/**'
" set comments-=s1:/*,mb:*,ex:*/ "Don't recognize C comments
" set comments-=:XCOMM "Don't recognize lmake comments
" set comments-=:% "Don't recognize PostScript comments
" set comments-=:# "Don't recognize Perl/shell comments
" set comments+=fb:* "Star-space is a bullet
" set comments+=fb:- "Dash-space is a bullets
set formatoptions-=cro
set formatoptions+=j " Remove comment introducers when joining comment lines
set wrapmargin=2 "Wrap 2 characters from the edge of the window
"set cinwords = "" "But not for C-like keywords
set cinoptions+=#1
set cinkeys-=0#
"=======[ Fix smartindent stupidities ]============
set autoindent "Retain indentation on next line
set smartindent "Turn on autoindenting of blocks
let g:vim_indent_cont = 0 " No magic shifts on Vim line continuations
"And no shift magic on comments...
nmap <silent> >> <Plug>ShiftLine
nnoremap <Plug>ShiftLine :call ShiftLine()<CR>
function! ShiftLine() range
set nosmartindent
exec "normal! " . v:count . ">>"
set smartindent
silent! call repeat#set( "\<Plug>ShiftLine" )
endfunction
"====[ I hate modelines ]===================
set modelines=0
"=====[ Quicker access to Ex commands ]==================
nmap ; :
xmap ; :
"=====[ Make Visual modes work better ]==================
" Visual Block mode is far more useful that Visual mode (so swap the commands)...
nnoremap v <C-V>
nnoremap <C-V> v
xnoremap v <C-V>
xnoremap <C-V> v
"Square up visual selections...
set virtualedit=block
" Make BS/DEL work as expected in visual modes (i.e. delete the selected text)...
xmap <BS> x
" Make vaa select the entire file...
xmap aa VGo1G
" Make q extend to the surrounding string...
xmap q "_y:call ExtendVisualString()<CR>
let s:closematch = [ '', '', '}', ']', ')', '>', '/', "'", '"', '`' ]
let s:ldelim = '\< \%(q [qwrx]\= \| [smy] \| tr \) \s*
\ \%(
\ \({\) \| \(\[\) \| \((\) \| \(<\) \| \(/\)
\ \)
\ \|
\ \(''\) \| \("\) \| \(`\)
\'
let s:ldelim = substitute(s:ldelim, '\s\+', '', 'g')
function! ExtendVisualString ()
let [lline, lcol, lmatch] = searchpos(s:ldelim, 'bWp')
if lline == 0
return
endif
let rdelim = s:closematch[lmatch]
normal `>
let rmatch = searchpos(rdelim, 'W')
normal! v
call cursor(lline, lcol)
endfunction
"=====[ Make arrow keys move visual blocks around ]======================
xmap <up> <Plug>SchleppUp
xmap <down> <Plug>SchleppDown
xmap <left> <Plug>SchleppLeft
xmap <right> <Plug>SchleppRight
xmap D <Plug>SchleppDupLeft
xmap <C-D> <Plug>SchleppDupLeft
"=====[ Demo vim commands ]==============================
highlight WHITE_ON_BLACK ctermfg=white
Nmap <silent> ;; [Demonstrate Vimscript block] :call DemoCommand()<CR>
xnoremap <silent> ;; :<C-U>call DemoCommand(1)<CR>
function! DemoCommand (...)
" Remember how everything was before we did this...
let orig_buffer = getline('w0','w$')
let orig_match = matcharg(1)
" Select either the visual region, or the current paragraph...
if a:0
let @@ = join(getline("'<","'>"), "\n")
else
silent normal vipy
endif
" Highlight the selection in red to give feedback...
let matchid = matchadd('WHITE_ON_RED','\%V')
redraw
sleep 500m
" Remove continuations and convert shell commands, then execute...
let command = @@
let command = substitute(command, '^\s*".\{-}\n', '', 'g')
let command = substitute(command, '\n\s*\\', ' ', 'g')
let command = substitute(command, '^\s*>\s', ':! ', '' )
execute command
" If the buffer changed, hold the highlighting an extra second...
if getline('w0','w$') != orig_buffer
redraw
sleep 1000m
endif
" Remove the highlighting...
call matchdelete(matchid)
endfunction
"=====[ Configure % key (via matchit plugin) ]==============================
" Match angle brackets...
set matchpairs+=<:>,«:»,「:」
"=====[ Miscellaneous features (mainly options) ]=====================
set title "Show filename in titlebar of window
set titleold=
"set titlestring=%t%(\ %M%)%(\ (%{expand(\"%:~:.:h\")})%)%(\ %a%)
set title titlestring=
set nomore "Don't page long listings
set cpoptions-=a "Don't set # after a :read
set autowrite "Save buffer automatically when changing files
set autoread "Always reload buffer when external changes detected
" +--Disable hlsearch while loading viminfo
" | +--Remember marks for last 500 files
" | | +--Remember up to 10000 lines in each register
" | | | +--Remember up to 1MB in each register
" | | | | +--Remember last 1000 search patterns
" | | | | | +---Remember last 1000 commands
" | | | | | |
" v v v v v v
set viminfo=h,'500,<10000,s1000,/1000,:1000
set backspace=indent,eol,start "BS past autoindents, line boundaries,
" and even the start of insertion
set fileformats=unix,mac,dos "Handle Mac and DOS line-endings
"but prefer Unix endings
set wildignorecase "Case-insensitive completions
set wildmode=list:longest,full "Show list of completions
" and complete as much as possible,
" then iterate full completions
set complete-=t " I don't use tags, so no need to search for them
set infercase "Adjust completions to match case
set noshowmode "Suppress mode change messages
set updatecount=10 "Save buffer every 10 chars typed
" Keycodes and maps timeout in 3/10 sec...
set timeout timeoutlen=300 ttimeoutlen=300
" "idleness" is 2 sec
set updatetime=2000
set thesaurus+=~/Documents/thesaurus "Add thesaurus file for ^X^T
set dictionary+=~/Documents/dictionary "Add dictionary file for ^X^K
set scrolloff=2 "Scroll when 3 lines from top/bottom
"====[ Simplify textfile backups ]============================================
" Back up the current file
Nmap BB [Back up current file] :!bak -q %<CR><CR>:echomsg "Backed up" expand('%')<CR>
"=====[ Remap various keys to something more useful ]========================
" Use space to jump down a page (like browsers do)...
nnoremap <Space> <PageDown>
xnoremap <Space> <PageDown>
" Format file with autoformat (capitalize to specify options)...
nmap F !Gformat -T4 -
nmap <silent> f !Gformat -T4<CR>
nmap ff r<CR>fgej
xmap F :!format -T4 -all -
xmap <silent> f :!format -T4 -all<CR>
" Install current file and swap to alternate file...
Nmap IP [Install current file and swap to alternate] :!install -f %<CR>
" Add *** as **/* on command-line...
cmap *** **/*
" Shift-Tab in visual mode to number lines...
xnoremap <S-TAB> :s/\%V/0<C-V><TAB>/<CR>gvg<C-A>gv:retab<ESC>gvI<C-G>u<ESC>gv/ <CR>:s/\%V /./<CR>
" Take off and nuke the entire buffer contents from space
" (It's the only way to be sure)...
nnoremap <expr> XX ClearBuffer()
function! ClearBuffer ()
if &filetype =~ 'perl'
return "1Gj}dGA\<CR>\<CR>\<ESC>"
else
return '1GdG'
endif
endfunction
" Replace the current buffer with a copy of the most recent file...
nmap RR 1GdG:0r#<CR><C-G>
" Insert cut marks...
nmap -- A<CR><CR><CR><ESC>k6i-----cut-----<ESC><CR>
" Indent/outdent current block...
nmap %% $>i}``
nmap $$ $<i}``
" =====[ Perl programming support ]===========================
" Execute Perl file...
nmap <silent> W :!clear;echo;echo;(script -q ~/tmp/script_$$ motleyperl %; if (-s ~/tmp/script_$$) then; alert; echo; echo; echo; getraw; endif; rm -f ~/tmp/script_$$ )<CR><CR>
" Execute Perl file (output to pager)...
nmap E :!motleyperl -m %<CR>
augroup PerlTestFile
autocmd!
autocmd BufEnter *.t nmap <silent><buffer> W :!clear;echo;echo;(script -q ~/tmp/script_$$ polyperl %; if (-s ~/tmp/script_$$) then; alert; echo; echo; echo; getraw; endif; rm -f ~/tmp/script_$$ )<CR><CR>
autocmd BufEnter *.t nmap <silent><buffer> E :!polyperl -m %<CR>
augroup END
" Execute Perl file (in debugger)...
nmap Q :!polyperl -d %<CR>
" Execute Perl file (in regex debugger)...
nmap ;r :!rxrx %<CR>
" Format file with perltidy...
Nmap ;p [Perltidy the current buffer] 1G!Gperltidy<CR>
" Show what changes perltidy would make...
Nmap ;pp [Perltidy to the current buffer (as a diff)] :call Perltidy_diff()<CR>
function! Perltidy_diff ()
" Work out what the tidied file will be called...
let perl_file = expand( '%' )
let tidy_file = perl_file . '.tdy'
call system( 'perltidy -nst ' . perl_file . ' -o ' . tidy_file )
" Add the diff to the right of the current window...
set splitright
exe ":vertical diffsplit " . tidy_file
" Clean up the tidied version...
call delete(tidy_file)
endfunction
" Run perldoc with smarter completion...
Nmap <expr> ?? [Go to documentation] CallPerldoc()
set keywordprg=pd
function! CallPerldoc ()
" When editing Vim files, revert to :help...
if &filetype == 'vim' || &buftype == 'help'
return ":help "
" Otherwise use Perldoc...
else
let target = matchstr(expand('<cfile>'), '\w\+\(::\w\+\)*')
set wildmode=list:full
return ":Perldoc "
endif
endfunction
"Complete perldoc requests with names of installed Perl modules
command! -nargs=? -complete=customlist,CompletePerlModuleNames Perldoc call Perldoc_impl(<q-args>)
"Undo the special wildmoding and then execute the requested perdoc lookup...
function! Perldoc_impl (args)
set wildmode=list:longest,full
if empty(a:args)
exec '!pd %'
else
exec '!pd ' . a:args
endif
endfunction
" Compile the list of installed Perl modules (and include the name under the cursor)...
let s:module_files = readfile($HOME.'/.vim/perlmodules')
function! CompletePerlModuleNames(prefix, cmdline, curpos)
let cfile = expand('<cfile>')
let prefix = a:prefix
if prefix == cfile
let prefix = ""
endif
if empty(prefix) && cfile =~ '^\w\+\(::\w\+\)*$'
return [cfile] + filter(copy(s:module_files), 'v:val =~ ''\c\_^' . prefix. "'")
else
return filter(copy(s:module_files), 'v:val =~ ''\c\_^' . prefix. "'")
endif
endfunction
" Handle Perl include files better...
"set include=^\\s*use\\s\\+\\zs\\k\\+\\ze
"set includeexpr=substitute(v:fname,'::','/','g')
"set suffixesadd=.pm
"execute 'set path+=' . substitute($PERL5LIB, ':', ',', 'g')
"Adjust keyword characters to match Perlish identifiers...
set iskeyword+=$
set iskeyword+=%
set iskeyword+=@-@
set iskeyword+=:
set iskeyword-=,
" Insert common Perl code structures...
iab udx use Data::Dx; Dx
nmap dx A<CR>use Data::Dx; Dx;<LEFT>
iab udd use Data::Dump 'ddx'; ddx
iab uds use Data::Show; show
iab urd use Regexp::Debugger;
iab udv use Dumpvalue;<CR>Dumpvalue->new->dumpValues();<ESC>hi
iab uds use Data::Show;<CR>show
iab ubm use Benchmark qw( cmpthese );<CR><CR>cmpthese -10, {<CR>};<ESC>O
iab usc use Smart::Comments;<CR>###
iab uts use Test::Simple 'no_plan';
iab utm use Test::More 'no_plan';
iab dbs $DB::single = 1;<ESC>
"=====[ Emphasize typical mistakes in Vim and Perl files ]=========
" Add a new high-visibility highlight combination...
highlight WHITE_ON_RED ctermfg=White ctermbg=Red cterm=bold
" Emphasize typical mistakes a Perl hacker makes in .vim files...
let g:VimMistakes
\ = '\_^\s*\zs\%(my\s\+\)\?\%(\k:\)\?\k\+\%(\[.\{-}\]\)\?\s*[+-.]\?=[=>~]\@!'
\ . '\|'
\ . '\_^\s*\zselsif'
\ . '\|'
\ . ';\s*\_$'
\ . '\|'
\ . '\_^\s*\zs#.*'
\ . '\|'
\ . '\_^\s*\zs\k\+('
let g:Mistakes = {
\ 'vim' : g:VimMistakes,
\}
let g:MistakesID = 668
augroup Mistakes
autocmd!
autocmd BufEnter *.vim,*.vimrc call s:Mistakes_AddMatch()
autocmd BufLeave * call s:Mistakes_ClearMatch()
augroup END
function! s:Mistakes_AddMatch ()
try | call matchadd('WHITE_ON_RED',g:Mistakes[&filetype],10,g:MistakesID) | catch | endtry
endfunction
function! s:Mistakes_ClearMatch ()
try | call matchdelete(g:MistakesID) | catch | endtry
endfunction
"=====[ Call :make and then perltests from within a Perl buffer ]========
let &errorformat .= ",%f:%l %tarning:%m,%f:%l:%m"
set makeprg=polyperl\ -vc\ %\ $*
function! RunPerlTests ()
if !empty(filter(getqflist(),{idx, val -> get(val,'type',"") == ''}))
echohl WarningMsg
echo "Errors detected, so won't run tests."
echohl NONE
silent cc 1
return
endif
" Start in the current directory...
let dir = expand('%:h')
" Walk up through parent directories, looking for a test directory...
for n in range(g:PerlTests_search_height)
" When found...
if isdirectory(dir . g:PerlTests_test_dir)
" Go there...
silent exec 'cd ' . dir
" Run the tests...
exec ':!' . g:PerlTests_program
" Return to the previous directory...
silent cd -
return
endif
" Otherwise, keep looking up the directory tree...
let dir = dir . '/..'
endfor
" If not found, report the failure...
echohl WarningMsg
echomsg "Couldn't find a suitable" g:PerlTests_test_dir '(tried' g:PerlTests_search_height 'levels up)'
echohl None
endfunction
"autocmd BufEnter *.p[lm],*.t call SetupPerlTesting()
"function! SetupPerlTesting ()
"endfunction
autocmd BufEnter *.p[lm],*.t let g:PerlTests_program = 'perltests'
autocmd BufEnter *.pm6,*.p6 let g:PerlTests_program = 'prove6'
let g:PerlTests_search_height = 5 " ...How far up the file hierarchy to search
let g:PerlTests_test_dir = '/t' " ...Where to look for tests
augroup PerlMake
autocmd!
autocmd BufReadPost quickfix setlocal number
\ | setlocal nowrap
\ | setlocal modifiable
\ | silent! %s/^[^|]*\//.../
\ | setlocal nomodifiable
augroup END
Nmap <silent> ;t [Test this code] :call RunPerlTests()<CR>
"=====[ Configure Hier for error highlighting ]===================
highlight HierError ctermfg=red cterm=bold
highlight HierWarning ctermfg=magenta cterm=bold
let g:hier_highlight_group_qf = 'HierError'
let g:hier_highlight_group_qfw = 'HierWarning'
let g:hier_highlight_group_loc = 'Normal'
let g:hier_highlight_group_locw = 'HierWarning'
let g:hier_highlight_group_loci = 'Normal'
"=====[ Placeholder data for templates (for the file_templates.vim plugin) ]=====
let g:FileTemplatesInfo = {
\ 'AUTHOR' : 'Damian Conway',
\ 'EMAIL' : 'DCONWAY@cpan.org',
\}
"=====[ Proper syntax highlighting for Rakudo files ]===========
autocmd BufNewFile,BufRead * :call CheckForPerl6()
function! CheckForPerl6 ()
if getline(1) =~ 'rakudo'
setfiletype perl6
endif
if expand('<afile>:e') == 'pod6'
setfiletype pod6
endif
endfunction
" =====[ Smart completion via <TAB> and <S-TAB> ]=============
runtime plugin/smartcom.vim
" Add extra completions (mainly for Perl programming)...
let ANYTHING = ""
let NOTHING = ""
let EOL = '\s*$'
" Left Right Insert Reset cursor
" ===== ===== =============================== ============
call SmartcomAdd( '<<', ANYTHING, "\<BS>\<BS>«" )
call SmartcomAdd( '>>', ANYTHING, "\<BS>\<BS>»" )
call SmartcomAdd( '?', ANYTHING, '?', {'restore':1} )
call SmartcomAdd( '?', '?', "\<CR>\<ESC>O\<TAB>" )
call SmartcomAdd( '{{', ANYTHING, '}}', {'restore':1} )
call SmartcomAdd( '{{', '}}', NOTHING, )
call SmartcomAdd( 'qr{', ANYTHING, '}xms', {'restore':1} )
call SmartcomAdd( 'qr{', '}xms', "\<CR>\<C-D>\<ESC>O\<C-D>\<TAB>" )
call SmartcomAdd( 'm{', ANYTHING, '}xms', {'restore':1} )
call SmartcomAdd( 'm{', '}xms', "\<CR>\<C-D>\<ESC>O\<C-D>\<TAB>", )
call SmartcomAdd( 's{', ANYTHING, '}{}xms', {'restore':1} )
call SmartcomAdd( 's{', '}{}xms', "\<CR>\<C-D>\<ESC>O\<C-D>\<TAB>", )
call SmartcomAdd( '\*\*', ANYTHING, '**', {'restore':1} )
call SmartcomAdd( '\*\*', '\*\*', NOTHING, )
" Handle single : correctly...
call SmartcomAdd( '^:\|[^:]:', EOL, "\<TAB>" )
" In the middle of a keyword: delete the rest of the keyword before completing...
" Left Right Insert
" ===== ===== =======================
"call SmartcomAdd( '\k', '\k\+\%(\k\|\n\)\@!', "\<C-O>cw\<C-X>\<C-N>", )
"call SmartcomAdd( '\k', '\k\+\_$', "\<C-O>cw\<C-X>\<C-N>", )
"After an alignable, align...
function! AlignOnPat (pat)
return "\<ESC>:call EQAS_Align('nmap',{'pattern':'" . a:pat . "'})\<CR>A"
endfunction
" Left Right Insert
" ========== ===== =============================
call SmartcomAdd( '=', ANYTHING, "\<ESC>:call EQAS_Align('nmap')\<CR>A")
call SmartcomAdd( '=>', ANYTHING, AlignOnPat('=>') )
call SmartcomAdd( '\s#', ANYTHING, AlignOnPat('\%(\S\s*\)\@<= #') )
call SmartcomAdd( '[''"]\s*:', ANYTHING, AlignOnPat(':'), {'filetype':'vim'} )
call SmartcomAdd( ':', ANYTHING, "\<TAB>", {'filetype':'vim'} )
" Left Right Insert Where
" ========== ===== ============================= ===================
" Vim keywords...
call SmartcomAdd( '^\s*func\%[tion]',
\ EOL, "\<C-W>function!\<CR>endfunction\<UP> ", {'filetype':'vim'} )
call SmartcomAdd( '^\s*for', EOL, " … in …\n…\n\<C-D>endfor\n…", {'filetype':'vim'} )
call SmartcomAdd( '^\s*if', EOL, " … \n…\n\<C-D>endif\n…", {'filetype':'vim'} )
call SmartcomAdd( '^\s*while', EOL, " … \n…\n\<C-D>endwhile\n…", {'filetype':'vim'} )
call SmartcomAdd( '^\s*try', EOL, "\n\t…\n\<C-D>catch\n\t…\n\<C-D>endtry\n…", {'filetype':'vim'} )
" Left Right Insert Where
" ========== ===== ============================= ===================
" Perl keywords...
call SmartcomAdd( '^\s*for', EOL, " my $… (…) {\n…\n}\n…", {' filetype':'perl'} )
call SmartcomAdd( '^\s*if', EOL, " (…) {\n…\n}\n…", {' filetype':'perl'} )
call SmartcomAdd( '^\s*while', EOL, " (…) {\n…\n}\n…", {' filetype':'perl'} )
call SmartcomAdd( '^\s*given', EOL, " (…) {\n…\n}\n…", {' filetype':'perl'} )
call SmartcomAdd( '^\s*when', EOL, " (…) {\n…\n}\n…", {' filetype':'perl'} )
call SmartcomAdd( '^\s*sub', EOL, " … (…) {\n…\n}\n…", {' filetype':'perl'} )
" Complete Perl module loads with the names of Perl modules...
call SmartcomAddAction( '^\s*use\s\+\k\+', "",
\ 'set complete=k~/.vim/perlmodules|set iskeyword+=:'
\)
" .itn itinerary files...
let s:flight_template = "\t…\nOn: \t…\nFrom:\t…\nTo: \t…\nDepart:\t…\nDTerm:\t…\nArrive:\t…\nATerm:\t…\nLength:\t…\nClass:\t…\nSeat:\t…\nBRef:\t…\nTrans:\t…\n"
let s:hotel_template = "\t…\nAddr:\t…\nPhone:\t…\nZone:\t…\nRate:\t…\nConfNo:\t…\n\nName:\t…\nEmail:\t…\nPhone:\t…\n"
let s:event_template = "\t…\nTime:\t…\nVenue:\t…\n"
" Left Right Insert Where
" ========== ===== ===================== ===================
call SmartcomAdd( '^\s*Date:', EOL, "\t…\nSumm:\t…\n", {'filetype':'itn'} )
call SmartcomAdd( '^\s*Flight:', EOL, s:flight_template, {'filetype':'itn'} )
call SmartcomAdd( '^\s*Bus:', EOL, s:flight_template, {'filetype':'itn'} )
call SmartcomAdd( '^\s*Train:', EOL, s:flight_template, {'filetype':'itn'} )
call SmartcomAdd( '^\s*Hotel:', EOL, s:hotel_template, {'filetype':'itn'} )
call SmartcomAdd( '^\s*Event:', EOL , s:event_template, {'filetype':'itn'} )
call SmartcomAdd( '^\s*Keynote:', EOL , s:event_template, {'filetype':'itn'} )
call SmartcomAdd( '^\s*Talk:', EOL , s:event_template, {'filetype':'itn'} )
call SmartcomAdd( '^\s*Course:', EOL , s:event_template, {'filetype':'itn'} )
"=====[ Itinerary generation ]===========
autocmd BufNewFile,BufRead *.itn nnoremap zd !!gen_itinerary_dates<CR>
"=====[ General programming support ]===================================
" Insert various shebang lines...
iab hbc #! /bin/csh
iab hbs #! /bin/sh
iab hbp #! /usr/bin/env polyperl<CR>use 5.020;<CR>use warnings;<CR>use experimentals;<CR>
iab hb6 #! /usr/bin/env perl6<CR>use v6;
" Execute current file polymorphically...
Nmap ,, [Execute current file] :w<CR>:!clear;echo;echo;run %<CR>
Nmap ,,, [Debug current file] :w<CR>:!clear;echo;echo;run -d %<CR>
"=====[ Show help files in a new tab, plus add a shortcut for helpg ]==============
let g:help_in_tabs = 1
"nmap <silent> H :let g:help_in_tabs = !g:help_in_tabs<CR>
"Only apply to .txt files...
augroup HelpInTabs
autocmd!
autocmd BufEnter *.txt call HelpInNewTab()
augroup END
"Only apply to help files...
function! HelpInNewTab ()
if &buftype == 'help' && g:help_in_tabs
"Convert the help window to a tab...
execute "normal \<C-W>T"
endif
endfunction
"Simulate a regular cmap, but only if the expansion starts at column 1...
function! CommandExpandAtCol1 (from, to)
if strlen(getcmdline()) || getcmdtype() != ':'
return a:from
else
return a:to
endif
endfunction
"Expand hh -> helpg...
cmap <expr> hh CommandExpandAtCol1('hh','helpg ')
"=====[ Cut and paste from the system clipboard ]====================
" When in Normal mode, paste over the current line...
nmap <C-P> 0d$"*p
" When in Visual mode, paste over the selected region...
xmap <C-P> "*pgv
" In Normal mode, yank the entire buffer...
nmap <C-C> 1G"*yG``:call YankedToClipboard()<CR>
" In Visual mode, yank the selection...
xmap <C-C> "*y:call YankedToClipboard()<CR>
function! YankedToClipboard ()
let block_of = (visualmode() == "\<C-V>" ? 'block of ' : '')
let N = strlen(substitute(@*, '[^\n]\|\n$', '', 'g')) + 1
let lines = (N == 1 ? 'line' : 'lines')
redraw
echo block_of . N lines 'yanked to clipboard'
endfunction
"=====[ Convert file to different tabspacings ]=====================
function! InferTabspacing ()
return min(filter(map(getline(1,'$'),'strlen(matchstr(v:val, ''^\s\+''))'),'v:val != 0'))
endfunction
function! NewTabSpacing (newtabsize)
" Determine apparent tabspacing, if necessary...
if &tabstop == 4
let &tabstop = InferTabspacing()
endif
" Preserve expansion, if expanding...
let was_expanded = &expandtab
" But convert to tabs initially...
normal TT
" Change the tabsizing...
execute "set ts=" . a:newtabsize
execute "set sw=" . a:newtabsize
" Update the formatting commands to mirror than new tabspacing...
execute "map F !Gformat -T" . a:newtabsize . " -"
execute "map <silent> f !Gformat -T" . a:newtabsize . "<CR>"
" Re-expand, if appropriate...
if was_expanded
normal TS
endif
endfunction
" Note, these are all T-<SHIFTED-DIGIT>, which is easier to type...
nmap <silent> T@ :call NewTabSpacing(2)<CR>
nmap <silent> T# :call NewTabSpacing(3)<CR>
nmap <silent> T$ :call NewTabSpacing(4)<CR>
nmap <silent> T% :call NewTabSpacing(5)<CR>
nmap <silent> T^ :call NewTabSpacing(6)<CR>
nmap <silent> T& :call NewTabSpacing(7)<CR>
nmap <silent> T* :call NewTabSpacing(8)<CR>
nmap <silent> T( :call NewTabSpacing(9)<CR>
" Convert to/from spaces/tabs...
nmap <silent> TS :set expandtab<CR>:%retab!<CR>
nmap <silent> TT :set noexpandtab<CR>:%retab!<CR>
nmap <silent> TF TST$
"=====[ Correct common mistypings in-the-fly ]=======================
iab retrun return
iab pritn print
iab teh the
iab liek like
iab liekwise likewise
iab Pelr Perl
iab pelr perl
iab ;t 't
iab Jarrko Jarkko
iab jarrko jarkko
iab moer more
iab previosu previous
"=====[ Tab handling ]======================================
set tabstop=4 "Tab indentation levels every four columns
set shiftwidth=4 "Indent/outdent by four columns
set expandtab "Convert all tabs that are typed into spaces
set shiftround "Always indent/outdent to nearest tabstop
set smarttab "Use shiftwidths at left margin, tabstops everywhere else
" Make the completion popup look menu-ish on a Mac...
highlight Pmenu ctermbg=white ctermfg=black
highlight PmenuSel ctermbg=blue ctermfg=white cterm=bold
highlight PmenuSbar ctermbg=grey ctermfg=grey
highlight PmenuThumb ctermbg=blue ctermfg=blue
" Make diffs less glaringly ugly...
highlight DiffAdd cterm=bold ctermfg=green ctermbg=black
highlight DiffChange cterm=bold ctermfg=grey ctermbg=black
highlight DiffDelete cterm=bold ctermfg=black ctermbg=black
highlight DiffText cterm=bold ctermfg=magenta ctermbg=black
"=====[ Extra completions for VimPoint files ]==========================
autocmd BufNewFile,BufRead *.vpt :call AddVimPointKeywords()
function! AddVimPointKeywords ()
call SmartcomAddAction(
\ '^=\k*', "", 'set complete=k~/.vim/VimPointKeywords|set iskeyword+=='
\)
endfunction
" "=====[ Grammar checking ]========================================
highlight GRAMMARIAN_ERRORS_MSG ctermfg=red cterm=bold
highlight GRAMMARIAN_CAUTIONS_MSG ctermfg=white cterm=bold
"=====[ Highlight cursor ]===================
" Inverse highlighting for cursor...
highlight CursorInverse ctermfg=black ctermbg=white
" Set up highlighter at high priority (i.e. 99)
call matchadd('CursorInverse', '\%#.', 99)
" Need an invisible cursor column to make it update on every cursor move...
" (via the visualguide.vim plugin, so as to play nice)
runtime plugin/visualsmartia.vim
call VG_Show_CursorColumn('off')
"=====[ Highlight row and column on request ]===================
" Toggle cursor row highlighting on request...
highlight CursorLine term=bold ctermbg=darkgrey ctermfg=yellow cterm=bold
Nmap <silent> ;c [Toggle cursor line highlighting] :set cursorline!<CR>
" Toggle cursor column highlighting on request...
" (via visualguide.vim plugin, so as to play nice)
nmap <silent> \ :silent call VG_Show_CursorColumn('flip')<CR>
xnoremap <silent> \ :<C-W>silent call VG_Show_CursorColumn('flip')<CR>gv
imap <silent> <C-\> <C-O>:silent call VG_Show_CursorColumn('flip')<CR>
"=====[ Highlight spelling errors on request ]===================
set spelllang=en_au
Nmap <silent> ;s [Toggle spell-checking] :set invspell spelllang=en<CR>
Nmap <silent> ;ss [Toggle Basic English spell-checking] :set spell spelllang=en-basic<CR>
"======[ Create a toggle for the XML completion plugin ]=======
Nmap ;x [Toggle XML completion] <Plug>XMLMatchToggle
"======[ Order-preserving uniqueness ]=========================
" Normalize the whitespace in a string...
function! TrimWS (str)
" Remove whitespace fore and aft...
let trimmed = substitute(a:str, '^\s\+\|\s\+$', '', 'g')
" Then condense internal whitespaces...
return substitute(trimmed, '\s\+', ' ', 'g')
endfunction
" Reduce a range of lines to only the unique ones, preserving order...
function! Uniq (...) range
" Ignore whitespace differences, if asked to...
let ignore_ws_diffs = len(a:000)
" Nothing unique seen yet...
let seen = {}
let uniq_lines = []
" Walk through the lines, remembering only the hitherto unseen ones...
for line in getline(a:firstline, a:lastline)
let normalized_line = '>' . (ignore_ws_diffs ? TrimWS(line) : line)
if !get(seen,normalized_line)
call add(uniq_lines, line)
let seen[normalized_line] = 1
endif
endfor
" Replace the range of original lines with just the unique lines...
exec a:firstline . ',' . a:lastline . 'delete'
call append(a:firstline-1, uniq_lines)
endfunction
" Only in visual mode...
"xnoremap q :call Uniq()<CR>
"xnoremap Q :call Uniq('ignore whitespace')<CR>
"====[ Make normalized search use NFKC ]=======
runtime plugin/normalized_search.vim
NormalizedSearchUsing ~/bin/NFKC
"====[ Regenerate help tags when directly editing a help file ]=================
augroup HelpTags
au!
autocmd BufWritePost ~/.vim/doc/* :helptags ~/.vim/doc
augroup END
"====[ Formatting for .lei files ]=======================================
augroup LEI
autocmd!
autocmd BufEnter *.lei nmap = vip!sort -bdfu<CR>vip:call LEI_format()<CR><CR>
augroup END
function! LEI_format () range
let [from, to] = [a:firstline, a:lastline]
" Acquire data...
let lines = getline(from, to)
" Ignore comments and category descriptions...
if lines[0] =~ '^\S'
return
endif
" Subdivide each line into singular/plural/classical plural columns...
let fields = []
for line in lines
let new_fields = split(line, '\s*\(|\|=>\)\s*')
call add(fields, ["","",""])
for col_num in [0,1,2]
let fields[-1][col_num] = get(new_fields, col_num, "")
endfor
endfor
" Work out how wide the columns need to be...
let max_width = [0,0]
for field_num in range(len(fields))
for col_num in [0,1]
let max_width[col_num] = max([max_width[col_num], strlen(fields[field_num][col_num])])
endfor
endfor
" Are there any classical alternatives???
let has_classical = match(lines, '|') >= 0
let field_template
\ = has_classical
\ ? '%-' . max_width[0] . 's => %-' . max_width[1] . 's | %s'
\ : '%-' . max_width[0] . 's => %-s'
" Reformat each line...
for field_num in range(len(fields))
let updated_line
\ = has_classical
\ ? printf(field_template, fields[field_num][0], fields[field_num][1], fields[field_num][2])
\ : printf(field_template, fields[field_num][0], fields[field_num][1])
call setline(from + field_num, substitute(updated_line,'\s*$','',''))
endfor
endfunction
"=====[ Search folding ]=====================
" Don't start new buffers folded
set foldlevelstart=99
" Highlight folds
highlight Folded ctermfg=cyan ctermbg=black
" Toggle special folds on and off...
nmap <silent> <expr> zz FS_ToggleFoldAroundSearch({'context':1})
nmap <silent> <expr> zc FS_ToggleFoldAroundSearch({'hud':1})
" Heads-up on function names (in Vim and Perl)...
let g:HUD_search = {
\ 'vim': { 'list': [ { 'start': '^\s*fu\%[nction]\>!\?\s*\w\+.*',
\ 'end': '^\s*endf\%[unction]\>\zs',
\ },
\ { 'start': '^\s*aug\%[roup]\>!\?\s*\%(END\>\)\@!\w\+.*',
\ 'end': '^\s*aug\%[roup]\s\+END\>\zs',
\ },
\ ],
\ 'default': '"file " . expand("%:~:.")',
\ },
\
\ 'perl': { 'list': [ { 'start': '\_^\s*\zssub\s\+\w\+.\{-}\ze\s*{\|^__\%(DATA\|END\)__$',
\ 'end': '}\zs',
\ },
\ { 'start': '\_^\s*\zspackage\s\+\w\+.\{-}\ze\s*{',
\ 'end': '}\zs',
\ },
\ { 'start': '\_^\s*\zspackage\s\+\w\+.\{-}\ze\s*;',
\ 'end': '\%$',
\ },
\ ],
\ 'default': '"package main"',
\ },
\ }
function! HUD ()
let target = get(g:HUD_search, &filetype, {})
let name = "'????'"
if !empty(target)
let name = eval(target.default)
for nexttarget in target.list
let [linestart, colstart] = searchpairpos(nexttarget.start, '', nexttarget.end, 'cbnW')
if linestart
let name = matchstr(getline(linestart), nexttarget.start)
break
endif
endfor
endif
if line('.') <= b:FS_DATA.context
return '⎺⎺⎺⎺⎺\ ' . name . ' /⎺⎺⎺⎺⎺' . repeat('⎺',200)
else
return '⎽⎽⎽⎽⎽/ ' . name . ' \⎽⎽⎽⎽⎽' . repeat('⎽',200)
endif
endfunction
nmap <silent> <expr> zh FS_ToggleFoldAroundSearch({'hud':1, 'folds':'HUD()', 'context':3})
" Show only sub defns (and maybe comments)...
let perl_sub_pat = '^\s*\%(sub\|func\|method\|package\)\s\+\k\+'
let vim_sub_pat = '^\s*fu\%[nction!]\s\+\k\+'
augroup FoldSub
autocmd!
autocmd BufEnter * nmap <silent> <expr> zp FS_FoldAroundTarget(perl_sub_pat,{'context':1})
autocmd BufEnter * nmap <silent> <expr> za FS_FoldAroundTarget(perl_sub_pat.'\zs\\|^\s*#.*',{'context':0, 'folds':'invisible'})
autocmd BufEnter *.vim,.vimrc nmap <silent> <expr> zp FS_FoldAroundTarget(vim_sub_pat,{'context':1})
autocmd BufEnter *.vim,.vimrc nmap <silent> <expr> za FS_FoldAroundTarget(vim_sub_pat.'\\|^\s*".*',{'context':0, 'folds':'invisible'})
autocmd BufEnter * nmap <silent> <expr> zv FS_FoldAroundTarget(vim_sub_pat.'\\|^\s*".*',{'context':0, 'folds':'invisible'})
augroup END
" Show only 'use' statements
nmap <silent> <expr> zu FS_FoldAroundTarget('\(^\s*\(use\\|no\)\s\+\S.*;\\|\<require\>\s\+\S\+\)',{'context':1})
"====[ Do a command, then restore the cursor ]======
command! -nargs=+ -complete=command Static call Static_impl(<q-args>)
function! Static_impl (cmd)
exec a:cmd
normal ``
endfunction
"====[ Accelerated up and down on wrapped lines, but counted motions use actual lines ]============
nmap <expr> j v:count ? 'j' : '<Plug>(accelerated_jk_gj)'
nmap <expr> k v:count ? 'k' : '<Plug>(accelerated_jk_gk)'
"====[ Pathogen support ]======================
call pathogen#infect()
call pathogen#helptags()
"====[ Mapping to analyse a list of numbers ]====================
" Need to load this early, so we can override its nmapped ++
runtime plugin/eqalignsimple.vim
xnoremap <expr> ++ VMATH_YankAndAnalyse()
nmap ++ vip++
"====[ Make digraphs easier to get right (various versions) ]=================
"inoremap <expr> <C-J> HUDG_GetDigraph()
inoremap <expr> <C-K> BDG_GetDigraph()
"inoremap <expr> <C-L> HUDigraphs()
function! HUDigraphs ()
digraphs
call getchar()
return "\<C-K>"
endfunction
"====[ Extend a previous match ]=====================================
nnoremap // /<C-R>/
nnoremap /// /<C-R>/\<BAR>
"====[ Toggle between lists and bulleted lists ]======================
Nmap <silent> ;l [Toggle list format (bullets <-> commas)] :call ListTrans_toggle_format()<CR>f
xnoremap <silent> ;l :call ListTrans_toggle_format('visual')<CR>f
"=====[ Select a table column in visual mode ]========================
xnoremap <silent><expr> c VTC_select()
"=====[ Make * respect smartcase and also set @/ (to enable 'n' and 'N') ]======
nmap * :let @/ = '\<'.expand('<cword>').'\>' ==? @/ ? @/ : '\<'.expand('<cword>').'\>'<CR>n
"=====[ Much smarter "edit next file" command ]=======================
nmap <silent><expr> e g:GTF_goto_file()
nmap <silent><expr> q g:GTF_goto_file('`')
"=====[ Smarter interstitial completions of identifiers ]=============
"
" When autocompleting within an identifier, prevent duplications...
augroup Undouble_Completions
autocmd!
autocmd CompleteDone * call Undouble_Completions()
augroup END
function! Undouble_Completions ()
let col = getpos('.')[2]
let line = getline('.')
call setline('.', substitute(line, '\(\.\?\k\+\)\%'.col.'c\zs\1\>', '', ''))
endfunction
"=====[ Autocomplete Perl code ]===========================
" (Note insertion of X<C-H># to overcome smartindent's mania for C-like #'s)
"inoremap <silent> > ><ESC>:call SmartArrow()<CR>a
"inoremap <silent> # X<C-H>#<C-R>=SmartOctothorpe()<CR>
inoremap <silent> # X<C-H>#
function! SmartArrow ()
if &filetype =~ '^perl' && search('=\%#>', 'bn', line('.'))
mark m
let [bufnum, lnum, col, off] = getpos('.')
let prefix = matchstr(getline('.'), '^.*=>\%'.(col+1).'v')
let arrow_count = len(split(prefix,'=>'))
let indent_pat = '^' . matchstr(getline('.'), '^\s*') . '\S'
let firstline = search('^\%('. indent_pat . '\)\@!\|^\s*$','bnW') + 1
let lastline = search('^\%('. indent_pat . '\)\@!\|^\s*$', 'nW') - 1
exec firstline.','.lastline.'!perltidyarrows'
normal 'm
while arrow_count
call search('=>','e',lnum)
let arrow_count -= 1
endwhile
endif
endfunction
"function! SmartArrow ()
" if &filetype =~ '^perl' && search('^.*\S.*\s=>\%#$', 'bn', line('.'))
" return "\<ESC>"
" \. ":call EQAS_Align('nmap',{'pattern':'=>'})\<CR>"
" \. ":call EQAS_Align('nmap',{'pattern':'\\%(\\S\\s*\\)\\@<=#'})\<CR>"
" \. "$a"
" else
" return ""
" endif
"endfunction
"
function! SmartOctothorpe ()
if &filetype =~ '^perl' && search('^.\{-}\S.\{-}\s#\%#$','bn')
return "\<ESC>"
\. ":call EQAS_Align('nmap',{'pattern':'\\%(\\S\\s\\)\\@<=#'})\<CR>"
\. "$s"
else
return ""
endif
endfunction
"=====[ Improve ruler with various useful information]=================================
let g:BRF_new_rulerformat = '%40(%#NonText# %v⇢ %l⇣ %= %{BRF_ErrStatus()} %<%{BRF_WordCount()} %L⤓ %P%)'
function! BRF_ErrStatus()
" Count errors and warnings in quickfix list...
let [errors, warnings] = [0,0]
for type in map(getqflist(), {key, val -> get(val, "type", "?")})
if type == "" || type == 'e' | let errors += 1
elseif type == 'w' | let warnings += 1
endif
endfor
" Count matches and distinct files in location list...
let loclist = getloclist(0)
let matches = len(loclist)
let files = {}
for locelem in loclist
let files[locelem.bufnr] = 1
endfor
let buffers = len(files)
" Generate report for ruler...
let status = []
if errors | call add(status, errors . 'ꜝ') | endif
if warnings | call add(status, warnings . 'ʷ') | endif
if matches | call add(status, matches . 'ᵐ ' . buffers . 'ᵇ') | endif
return join(status, ' ')
endfunction
let g:BRF_interval = 1
function! BRF_WordCount()
" Skip an increasing percentage of increasingly expensive updates, as the file gets longer...
let g:BRF_interval += 1
if exists("b:BRF_wordcount")
let timestamp = get(b:,'BRF_timestamp', -1)
if g:BRF_interval < b:BRF_wordcount / 500
return b:BRF_wordcount . (timestamp == undotree().seq_cur ? '⁞' : '⁞̃' )
endif
let g:BRF_interval = 1
endif
" Otherwise, recount the file...
if &modified || !exists("b:BRF_wordcount")
let lines = join(getline(1,'$'), ' ')
let lines = substitute(lines, '\d\.\d', 'X', 'g')
let lines = substitute(lines, '\a[''-]\a', 'X', 'g')
let lines = substitute(lines, '[[:alnum:]]\+', 'X', 'g')
let lines = substitute(lines, '[^[:alnum:]]\+', '', 'g')
let b:BRF_wordcount = strlen(lines)
let b:BRF_timestamp = undotree().seq_cur
endif
" Return the precise count...
return b:BRF_wordcount . '⁞'
endfunction
function! BRF_ToggleRuler ()
if strlen(&rulerformat)
let &rulerformat = ''
else
let &rulerformat = g:BRF_new_rulerformat
endif
set ruler
redraw
endfunction
nmap <silent> ;w :silent call BRF_ToggleRuler()<CR><C-L>
let &rulerformat = g:BRF_new_rulerformat
set ruler
"======[ Fix colourscheme for 256 colours ]============================
highlight Visual ctermfg=Yellow ctermbg=26 " 26 = Dusty blue background
highlight SpecialKey cterm=bold ctermfg=Blue
"======[ Tweak highlighted yank plugin ]====================================
highlight HighlightedyankRegion cterm=NONE ctermfg=white ctermbg=darkyellow
let g:highlightedyank_highlight_duration = -1
let g:highlightedyank_quench_when = [ ['CursorMoved', '<buffer>'] ]
"======[ Add a Y command for incremental yank in Visual mode ]==============
xnoremap <silent> Y <ESC>:silent let @y = @"<CR>gv"Yy:silent let @" = @y<CR>
nnoremap <silent> YY :call Incremental_YY()<CR>
nnoremap <silent><expr> Y Incremental_Y()
function! Incremental_YY () range
let @" .= join(getline(a:firstline, a:lastline), "\n") . "\n"
endfunction
function! Incremental_Y ()
let motion = nr2char(getchar())
if motion == 'Y'
call Incremental_YY()
return
elseif motion =~ '[ia]'
let motion .= nr2char(getchar())
elseif motion =~ '[/?]'
let motion .= input(motion) . "\<CR>"
endif
let @y = @"
return '"Yy' . motion . ':let @" = @y' . "\<CR>"
endfunction
"======[ Add a $$ command in Visual mode ]==============================
xmap <silent> ] $"yygv_$
xnoremap <silent><expr> _$ Under_dollar_visual()
function! Under_dollar_visual ()
" Locate block being shifted...
let maxcol = max(map(split(@y, "\n"), 'strlen(v:val)')) + getpos("'<")[2] - 2
" Return the selection that does the job...
return maxcol . '|'
endfunction
"=====[ Diff against disk ]==========================================
map <silent> zd :silent call DC_DiffChanges()<CR>
" Change the fold marker to something more useful
function! DC_LineNumberOnly ()
if v:foldstart == 1 && v:foldend == line('$')
return '.. ' . v:foldend . ' (No difference)'
else
return '.. ' . v:foldend
endif
endfunction
" Track each buffer's initial state
augroup DC_TrackInitial
autocmd!
autocmd BufReadPost,BufNewFile * if !exists('b:DC_initial_state')
autocmd BufReadPost,BufNewFile * let b:DC_initial_state = getline(1,'$')
autocmd BufReadPost,BufNewFile * endif
augroup END
highlight DC_DEEMPHASIZED ctermfg=grey
function! DC_DiffChanges ()
diffthis
highlight Normal ctermfg=grey
let initial_state = b:DC_initial_state
set diffopt=context:2,filler,foldcolumn:0
" set fillchars=fold:ÃÂ
set foldcolumn=0
setlocal foldtext=DC_LineNumberOnly()
set number
" aboveleft vnew
belowright vnew
normal 0
silent call setline(1, initial_state)
diffthis
set diffopt=context:2,filler,foldcolumn:0
" set fillchars=fold:ÃÂ
set foldcolumn=0
setlocal foldtext=DC_LineNumberOnly()
set number
nmap <silent><buffer> zd :diffoff<CR>:q!<CR>:set diffopt& fillchars& number& foldcolumn=0<CR>:set nodiff<CR>:highlight Normal ctermfg=NONE<CR>
endfunction
"=====[ ,, as => without delays ]===================
inoremap <expr><silent> , Smartcomma()
function! Smartcomma ()
let [bufnum, lnum, col, off, curswant] = getcurpos()
if getline('.') =~ (',\%' . (col+off) . 'c')
return "\<C-H>=>"
else
return ','
endif
endfunction
"=====[ Interface with ag ]======================
set grepprg=ag\ --vimgrep\ $*
set grepformat=%f:%l:%c:%m
" Also use ag in GVI...
let g:GVI_use_ag = 1
"=====[ Decute startify ]================
let g:startify_custom_header = []
"=====[ Configure change-tracking ]========
let g:changes_hl_lines=1
let g:changes_verbose=0
let g:changes_autocmd=1
"=====[ Make netrw more instantly useful ]============
let g:netrw_sort_by = 'time'
let g:netrw_sort_direction = 'reverse'
let g:netrw_banner = 0
let g:netrw_liststyle = 3
let g:netrw_browse_split = 3
let g:netrw_fastbrowse = 1
let g:netrw_sort_by = 'name'
let g:netrw_sort_direction = 'normal'
"=====[ Pod6 proofing ]==========
nmap <silent> ;p :silent call Pod6_ToggleProofing()<CR>:silent call WarmMargin('off')<CR><C-L>
"======[ Breakindenting ]========
set breakindentopt=shift:2,sbr
set showbreak=↪
set breakindent
set linebreak
"======[ Writing support ]=======
augroup PiP6
autocmd!
autocmd BufEnter *.pod6 iab P6 Perl 6
autocmd BufEnter *.pod6 iab P5 Perl 5
autocmd BufEnter *.pod6 iab h1 =head1
autocmd BufEnter *.pod6 iab h2 =head2
autocmd BufEnter *.pod6 iab h3 =head3
autocmd BufEnter *.pod6 iab h4 =head4
autocmd BufEnter *.pod6 iab h5 =head5
for L in split('C I B R')
let l = tolower(L)
exec 'autocmd BufEnter *.pod6 xnoremap <TAB>' . l . ' "vygvc' . L . '<C-R><C-R>=P6_delim("")<CR><ESC>'
exec 'autocmd BufEnter *.pod6 nmap <TAB>' . l . ' viw<TAB>' . l
endfor
autocmd BufEnter *.pod6 xnoremap <TAB>m "vygvcM<C-R><C-R>=P6_delim('T:')<CR><ESC>
autocmd BufEnter *.pod6 nmap <TAB>m viw<TAB>m
function! P6_delim (prefix)
let regy = getreg('v')
if regy =~ '[<>]'
return '«' . a:prefix . regy . '»'
else
return '<' . a:prefix . regy . '>'
endif
endfunction
call SmartcomAdd( '''', '', "\<BS>‘")
call SmartcomAdd( '[‘’]', '', "\<BS>'")
call SmartcomAdd( '\(\w\|[‘.!?]\)''', '', "\<BS>’")
call SmartcomAdd( '"', '', "\<BS>“")
call SmartcomAdd( '\(\w\|[“.!?]\)"', '', "\<BS>”")
call SmartcomAdd( '\.\@<!\.\.\.', '', "\<BS>\<BS>\<BS>…")
call SmartcomAdd( '--', '', "\<BS>\<BS>—")
call SmartcomAdd( '_', '', "\<BS>␣")
augroup END
"=====[ Automate syntax highlighting ]===============================
" Keep long lines from slowing Vim too much
set synmaxcol=200
augroup Autosyntax_actions
autocmd!
autocmd FileType netrw syntax on
autocmd BufEnter * call AS_Enter()
autocmd BufLeave * syntax off
augroup END
command! -complete=filetype -nargs=+ Autosyntax call AS_set_active(<q-args>)
let g:AS_active_in = {}
function! AS_set_active(list)
for ft in split(a:list, '\s\+')
let g:AS_active_in[ft] = 1
let g:AS_active_in['.'.ft] = 1
endfor
endfunction
Autosyntax itn
Autosyntax pod6
Autosyntax todo
Autosyntax diff patch
function! AS_Enter ()
let suffix = '.' . expand('<afile>:e')
if get(g:AS_active_in, &filetype, 0) || suffix != '.' && get(g:AS_active_in, suffix, 0)
syntax enable
endif
endfunction
nmap <silent> ;y :call AS_toggle()<CR>
function! AS_toggle ()
let suffix = '.' . expand('%:e')
if exists('g:syntax_on')
syntax off
let g:AS_active_in[&filetype] = 0
let g:AS_active_in[suffix] = 0
else
syntax enable
let g:AS_active_in[&filetype] = 1
let g:AS_active_in[suffix] = 1
endif
endfunction
"=====[ Double quote Perl single quotes and vice versa ]==================
call SmartcomAdd( '''[^"]*"', NOTHING, "\<ESC>?'\<CR>:nohlsearch\<CR>r\"a", {'restore':1+1} )
call SmartcomAdd( 'q\@<!q{[^"]*"', NOTHING, "\<BS>}\<ESC>?q{\<CR>:nohlsearch\<CR>sqq", {'restore':1+2} )
call SmartcomAdd( '"[^'']*''', NOTHING, "\<ESC>?\"\<CR>:nohlsearch\<CR>r'a", {'restore':1+1} )
call SmartcomAdd( 'qq{[^'']*''', NOTHING, "\<BS>}\<ESC>?qq{\<CR>:nohlsearch\<CR>2sq", {'restore':1+1} )
"=====[ Translate common currencies ]==================
call SmartcomAdd('\<EUR', NOTHING, "\<ESC>xxs€" )
call SmartcomAdd('\<GBP', NOTHING, "\<ESC>xxs£" )
call SmartcomAdd('\<ILS', NOTHING, "\<ESC>xxs₪" )
call SmartcomAdd('\<INR', NOTHING, "\<ESC>xxs₨" )
call SmartcomAdd('\<JPY', NOTHING, "\<ESC>xxs¥" )
call SmartcomAdd('\<YEN', NOTHING, "\<ESC>xxs¥" )
"=====[ Park cursor and demarginalize in vimpoint files ]========================
augroup VimpointConfig
autocmd!
autocmd BufEnter *.vp* :normal 0
autocmd BufEnter *.vp* WarmMargin never
augroup END
"=====[ Let <UP> and <DOWN> iterate the quickfix buffer list too ]=========
let g:ArrNav_arglist_fallback = 1
"=====[ Blockwise mode on : in visual mode ]===============================
let g:Blockwise_autoselect = 1
"=====[ Make jump-selections work better in visual block mode ]=================
xnoremap <expr> G 'G' . virtcol('.') . "\|"
xnoremap <expr> } '}' . virtcol('.') . "\|"
xnoremap <expr> { '{' . virtcol('.') . "\|"
"=====[ Bracketed paste mode ]=======================================
if &term =~ "xterm.*"
let &t_ti = &t_ti . "\e[?2004h"
let &t_te = "\e[?2004l" . &t_te
function! XTermPasteBegin(ret)
set pastetoggle=<Esc>[201~
set paste
return a:ret
endfunction
map <expr> <Esc>[200~ XTermPasteBegin("i")
imap <expr> <Esc>[200~ XTermPasteBegin("")
xmap <expr> <Esc>[200~ XTermPasteBegin("c")
cmap <Esc>[200~ <nop>
cmap <Esc>[201~ <nop>
endif
"=====[ Configure ALE ]==================
" Install the following:
" https://github.com/w0rp/ale
" https://github.com/jceb/vim-hier
highlight AleError ctermfg=red cterm=bold
highlight AleWarning ctermfg=magenta cterm=bold
augroup ALE_Autoconfig
au!
autocmd User GVI_Start silent call Stop_ALE()
autocmd User PV_Start silent call Stop_ALE()
autocmd User PV_End silent call Start_ALE()
autocmd User ALELint silent HierUpdate
augroup END
let g:ale_set_loclist = 0
let g:ale_set_quickfix = 1
let g:ale_set_signs = 0
let g:ale_linters = { 'perl': ['perl'] }
let g:ale_perl_perl_executable = 'polyperl'
let g:ale_perl_perl_options = '-cw -Ilib'
let g:ale_lint_on_text_changed = 'normal'
let g:ale_lint_on_insert_leave = 1
Nmap <silent> ;m [Toggle automake on Perl files] :call Toggle_ALE()<CR>
function! Start_ALE ()
if !expand('./.noale')
ALEEnable
HierStart
endif
endfunction
function! Stop_ALE ()
silent call s:ChangeProfile(&filetype)
ALEDisable
HierStop
call setqflist([])
redraw!
endfunction
function! Toggle_ALE ()
if expand('./.noale')
call Stop_ALE()
echo 'Error highlighting disabled (.noale)'
elseif g:ale_enabled
call Stop_ALE()
echo 'Error highlighting off'
else
call Start_ALE()
echo 'Error highlighting on'
endif
endfunction
"=====[ Adjust terminal profile for various cases ]=========
augroup AutoProfile
au!
autocmd User ALELint call s:AutoChangeProfile()
autocmd BufEnter * call s:AutoChangeProfile()
autocmd VimLeave * call s:ChangeProfile('default')
augroup END
let s:Profile = {
\ 'default' : 'yellow',
\ 'perl6' : 'blue',
\ 'haskell' : 'futuristic',
\ 'java' : 'dubya',
\ 'fortran' : 'typewriter',
\}
function! s:AutoChangeProfile ()
if &filetype == 'help' || empty(filter(getqflist(),{idx, val -> get(val,'bufnr',"") == bufnr('%')}))
call s:ChangeProfile(&filetype)
else
call s:ChangeProfileErrors(&filetype)
endif
endfunction
function! s:ChangeProfile (name)
let bg = get(s:Profile, a:name, s:Profile['default'])
silent exec "!terminal_profile '" . bg . "'"
endfunction
function! s:ChangeProfileErrors (name)
let bg = get(s:Profile, a:name, s:Profile['default'])
silent exec "!terminal_profile '" . bg . " errors'"
endfunction
"=====[ Select a completion from the menu without inserting a <CR> ]========
inoremap <expr> <CR> ((pumvisible())?("\<C-Y>"):("\<CR>"))
"=====[ Change cursor during insertion ]======================
let &t_SI="\033[5 q" " start insert mode, switch to blinking cursor
let &t_EI="\033[1 q" " end insert mode, back to square cursor
"=====[ Completion during search (via Command window) ]======================
function! s:search_mode_start()
cnoremap <tab> <c-f>:resize 1<CR>a<c-n>
let s:old_complete_opt = &completeopt
let s:old_last_status = &laststatus
set completeopt-=noinsert
set laststatus=0
endfunction
function! s:search_mode_stop()
try
silent cunmap <tab>
catch
finally
let &completeopt = s:old_complete_opt
let &laststatus = s:old_last_status
endtry
endfunction
augroup SearchCompletions
autocmd!
autocmd CmdlineEnter [/\?] call <SID>search_mode_start()
autocmd CmdlineLeave [/\?] call <SID>search_mode_stop()
augroup END
"=====[ Make multi-selection incremental search prettier ]======================
augroup SearchIncremental
autocmd!
autocmd CmdlineEnter [/\?] highlight Search ctermfg=DarkRed ctermbg=Black cterm=NONE
autocmd CmdlineLeave [/\?] highlight Search ctermfg=White ctermbg=Black cterm=bold
augroup END
"=====[ Configure table-mode ]=================================================
let g:table_mode_corner = '|'
let g:table_mode_corner_corner = '|'
let g:table_mode_header_fillchar = '='
let g:table_mode_fillchar = '-'
let g:table_mode_align_char = ':'
let g:table_mode_cell_text_object_a_map = 'ac'
let g:table_mode_cell_text_object_i_map = 'ic'
let g:table_mode_syntax = 1
let g:table_mode_delimiter = ' \{2,}'
nmap <TAB> :TableModeToggle<CR>
xmap <TAB> <ESC><TAB>gv
xmap <silent> T :<C-U>call ToggleTabularization()<CR>
function! ToggleTabularization ()
let range = getpos('''<')[1] .','. getpos('''>')[1]
if getline("'<") =~ '\\\@!|'
silent TableModeEnable
exec 'silent! ' . range . 's/[-= ]\@<=+\|+[-= ]\@=/ /g'
exec 'silent! ' . range . 's/[-= ]|[-= ]\|[^\\]\zs|[-= ]\|[-= ]|/ /g'
exec 'silent! ' . range . 's/\s\+$//'
nohlsearch
TableModeDisable
else
TableModeEnable
'<,'>Tableize
endif
normal gv
endfunction
"=====[ Make vim-dirvish work how I prefer ]============
" Sort directories first...
let g:dirvish_mode = ':sort ,^.*[\/],'
augroup DirvishConfig
autocmd!
autocmd FileType dirvish :call MyDirvishSetup()
augroup END
function! MyDirvishSetup ()
" Set up the mapping I want...
nmap <buffer> .. <Plug>(dirvish_up)
" Make directories stand out...
syntax enable
" Make current selection stand out...
highlight CursorLine cterm=bold ctermfg=white ctermbg=blue
highlight MatchLine cterm=bold ctermfg=white ctermbg=blue
" Map <TAB> to open in new tab...
nnoremap <silent><buffer> <TAB> :call DirvishX_TabOpen()<CR>
xnoremap <silent><buffer> <TAB> :call DirvishX_TabOpen()<CR>
" Map <CR> to :next the selected file(s) and then cycle back
nnoremap <silent><buffer> <CR> :call DirvishX_Open()<CR>
xnoremap <silent><buffer> <CR> :call DirvishX_Open()<CR>
" Remove search pattern at start, and on <DELETE>...
let @/ = ''
nnoremap <silent><buffer> <BS> :call DirvishResetMatches()<CR>
" Various other tricks...
let dirvish_file = expand('<afile>')
augroup DirvishConfig
exec 'autocmd BufEnter ' . dirvish_file . ' :normal R'
exec 'autocmd CursorMoved ' . dirvish_file . ' :call DirvishUpdateMatches()'
augroup END
endfunction
function! DirvishSmartMatch ()
let ignorecase = &ignorecase ? '\c' : ''
let smartcase = &smartcase && @/ =~ '\u' ? '\C' : ''
return ignorecase . smartcase . '^.*'.@/.'.*'
endfunction
function! DirvishMatchedFiles ()
let current_search_pattern = DirvishSmartMatch()
let filelist = []
for line in getline(1,'$')
if line =~ current_search_pattern
call add(filelist, line)
endif
endfor
return filelist
endfunction
function! DirvishUpdateMatches ()
if len(@/)
silent! call matchdelete(b:dirvish_matchline)
let b:dirvish_matchline = matchadd('MatchLine', DirvishSmartMatch())
highlight CursorLine cterm=bold ctermfg=white ctermbg=NONE
else
highlight CursorLine cterm=bold ctermfg=white ctermbg=blue
endif
endfunction
function! DirvishResetMatches ()
nohlsearch
let @/ = ''
silent! call matchdelete(b:dirvish_matchline)
highlight CursorLine cterm=bold ctermfg=white ctermbg=blue
endfunction
function! DirvishX_Open () range
let files = len(@/) ? DirvishMatchedFiles() : getline(a:firstline, a:lastline)
exec ':next ' . join(files) . ' %'
endfunction
function! DirvishX_TabOpen () range
let files = len(@/) ? DirvishMatchedFiles() : getline(a:firstline, a:lastline)
for file in files
exec ':tabedit ' . file
endfor
2tabnext
endfunction
"=======[ Prettier tabline ]============================================
highlight Tabline cterm=underline ctermfg=40 ctermbg=22
highlight TablineSel cterm=underline,bold ctermfg=white ctermbg=28
highlight TablineFill cterm=NONE ctermfg=black ctermbg=black
"=======[ Swap <C-A> and g<C-A>, improve <C-A>, and persist in visual mode ]============
xnoremap <C-A> g<C-A>gv<C-X>gv
xnoremap g<C-A> <C-A>gv
"=======[ Make literal spaces match any whitespace in searches ]============
cnoremap <C-M> <C-\>e('/?' =~ getcmdtype() ? substitute(getcmdline(), '\\\@<! ', '\\_s\\+', 'g') : getcmdline())<CR><CR>
"=======[ Limelight configuration ]==========================================
" Color name (:help cterm-colors) or ANSI code
let g:limelight_conceal_ctermfg = 'gray'
" Default dimming: 0.5
let g:limelight_default_coefficient = 0.7
" Highlighting priority (default: 10)
" Set it to -1 not to overrule hlsearch
let g:limelight_priority = -1
4 ThePrimegeanVimrc.txt
syntax on
set guicursor=
set noshowmatch
set relativenumber
set nohlsearch
set hidden
set noerrorbells
set tabstop=4 softtabstop=4
set shiftwidth=4
set expandtab
set smartindent
set nu
set nowrap
set smartcase
set noswapfile
set nobackup
set undodir=~/.vim/undodir
set undofile
set incsearch
set termguicolors
set scrolloff=8
" Give more space for displaying messages.
set cmdheight=2
" Having longer updatetime (default is 4000 ms = 4 s) leads to noticeable
" delays and poor user experience.
set updatetime=50
" Don't pass messages to |ins-completion-menu|.
set shortmess+=c
set colorcolumn=80
highlight ColorColumn ctermbg=0 guibg=lightgrey
call plug#begin('~/.vim/plugged')
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'tweekmonster/gofmt.vim'
Plug 'tpope/vim-fugitive'
Plug 'vim-utils/vim-man'
Plug 'mbbill/undotree'
Plug 'sheerun/vim-polyglot'
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
" I AM SO SORRY FOR DOING COLOR SCHEMES IN MY VIMRC, BUT I HAVE
" TOOOOOOOOOOOOO
Plug 'gruvbox-community/gruvbox'
Plug 'sainnhe/gruvbox-material'
Plug 'phanviet/vim-monokai-pro'
Plug 'vim-airline/vim-airline'
Plug 'flazz/vim-colorschemes'
Plug '/home/mpaulson/personal/vim-be-good'
call plug#end()
let g:gruvbox_contrast_dark = 'hard'
" --- The Greatest plugin of all time. I am not bias
let g:vim_be_good_floating = 1
" --- vim go (polyglot) settings.
let g:go_highlight_build_constraints = 1
let g:go_highlight_extra_types = 1
let g:go_highlight_fields = 1
let g:go_highlight_functions = 1
let g:go_highlight_methods = 1
let g:go_highlight_operators = 1
let g:go_highlight_structs = 1
let g:go_highlight_types = 1
let g:go_highlight_function_parameters = 1
let g:go_highlight_function_calls = 1
let g:go_highlight_generate_tags = 1
let g:go_highlight_format_strings = 1
let g:go_highlight_variable_declarations = 1
let g:go_auto_sameids = 1
colorscheme gruvbox
set background=dark
if executable('rg')
let g:rg_derive_root='true'
endif
let loaded_matchparen = 1
let mapleader = " "
let g:netrw_browse_split = 2
let g:vrfr_rg = 'true'
let g:netrw_banner = 0
let g:netrw_winsize = 25
nnoremap <leader>h :wincmd h<CR>
nnoremap <leader>j :wincmd j<CR>
nnoremap <leader>k :wincmd k<CR>
nnoremap <leader>l :wincmd l<CR>
nnoremap <leader>u :UndotreeShow<CR>
nnoremap <leader>pv :wincmd v<bar> :Ex <bar> :vertical resize 30<CR>
nnoremap <Leader>ps :Rg<SPACE>
nnoremap <C-p> :GFiles<CR>
nnoremap <Leader>pf :Files<CR>
nnoremap <Leader><CR> :so ~/.config/nvim/init.vim<CR>
nnoremap <Leader>+ :vertical resize +5<CR>
nnoremap <Leader>- :vertical resize -5<CR>
nnoremap <Leader>ee oif err != nil {<CR>log.Fatalf("%+v\n", err)<CR>}<CR><esc>kkI<esc>
vnoremap J :m '>+1<CR>gv=gv
vnoremap K :m '<-2<CR>gv=gv
" Vim with me
nnoremap <leader>vwm :colorscheme gruvbox<bar>:set background=dark<CR>
nmap <leader>vtm :highlight Pmenu ctermbg=gray guibg=gray
vnoremap X "_d
inoremap <C-c> <esc>
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
inoremap <silent><expr> <TAB>
\ pumvisible() ? "\<C-n>" :
\ <SID>check_back_space() ? "\<TAB>" :
\ coc#refresh()
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
inoremap <silent><expr> <C-space> coc#refresh()
" GoTo code navigation.
nmap <leader>gd <Plug>(coc-definition)
nmap <leader>gy <Plug>(coc-type-definition)
nmap <leader>gi <Plug>(coc-implementation)
nmap <leader>gr <Plug>(coc-references)
nmap <leader>rr <Plug>(coc-rename)
nmap <leader>g[ <Plug>(coc-diagnostic-prev)
nmap <leader>g] <Plug>(coc-diagnostic-next)
nmap <silent> <leader>gp <Plug>(coc-diagnostic-prev-error)
nmap <silent> <leader>gn <Plug>(coc-diagnostic-next-error)
nnoremap <leader>cr :CocRestart
" Sweet Sweet FuGITive
nmap <leader>gh :diffget //3<CR>
nmap <leader>gu :diffget //2<CR>
nmap <leader>gs :G<CR>
fun! TrimWhitespace()
let l:save = winsaveview()
keeppatterns %s/\s\+$//e
call winrestview(l:save)
endfun
autocmd BufWritePre * :call TrimWhitespace()
5 nickjj_vimrc_file.txt
Reference: https://raw.githubusercontent.com/nickjj/dotfiles/master/.vimrc
" -----------------------------------------------------------------------------
" This config is targeted for Vim 8.1+ and expects you to have Plug installed.
" -----------------------------------------------------------------------------
" -----------------------------------------------------------------------------
" Plugins
" -----------------------------------------------------------------------------
" Specify a directory for plugins.
call plug#begin('~/.vim/plugged')
" Atom One Dark / Light theme.
Plug 'rakr/vim-one'
" Gruvbox Community theme.
Plug 'gruvbox-community/gruvbox'
" Integrate fzf with Vim.
Plug '$XDG_DATA_HOME/fzf'
Plug 'junegunn/fzf.vim'
" Better manage Vim sessions.
Plug 'tpope/vim-obsession'
" Zoom in and out of a specific split pane (similar to tmux).
Plug 'dhruvasagar/vim-zoom'
" Pass focus events from tmux to Vim (useful for autoread and linting tools).
Plug 'tmux-plugins/vim-tmux-focus-events'
" Navigate and manipulate files in a tree view.
Plug 'lambdalisue/fern.vim'
Plug 'lambdalisue/fern-mapping-mark-children.vim'
" Helpers for moving and manipulating files / directories.
Plug 'tpope/vim-eunuch'
" Run a diff on 2 directories.
Plug 'will133/vim-dirdiff'
" Run a diff on 2 blocks of text.
Plug 'AndrewRadev/linediff.vim'
" Add spelling errors to the quickfix list (vim-ingo-library is a dependency).
Plug 'inkarkat/vim-ingo-library' | Plug 'inkarkat/vim-SpellCheck'
" Briefly highlight which text was yanked.
Plug 'machakann/vim-highlightedyank'
" Highlight which character to jump to when using horizontal movement keys.
Plug 'unblevable/quick-scope'
" Modify * to also work with visual selections.
Plug 'nelstrom/vim-visual-star-search'
" Automatically clear search highlights after you move your cursor.
Plug 'haya14busa/is.vim'
" Handle multi-file find and replace.
Plug 'mhinz/vim-grepper'
" Better display unwanted whitespace.
Plug 'ntpeters/vim-better-whitespace'
" Toggle comments in various ways.
Plug 'tpope/vim-commentary'
" Automatically set 'shiftwidth' + 'expandtab' (indention) based on file type.
Plug 'tpope/vim-sleuth'
" A number of useful motions for the quickfix list, pasting and more.
Plug 'tpope/vim-unimpaired'
" Drastically improve insert mode performance in files with folds.
Plug 'Konfekt/FastFold'
" Show git file changes in the gutter.
Plug 'mhinz/vim-signify'
" A git wrapper.
Plug 'tpope/vim-fugitive'
" Dim paragraphs above and below the active paragraph.
Plug 'junegunn/limelight.vim'
" Distraction free writing by removing UI elements and centering everything.
Plug 'junegunn/goyo.vim'
" A bunch of useful language related snippets (ultisnips is the engine).
Plug 'SirVer/ultisnips' | Plug 'honza/vim-snippets'
" Automatically show Vim's complete menu while typing.
Plug 'vim-scripts/AutoComplPop'
" Run test suites for various languages.
Plug 'janko/vim-test'
" Languages and file types.
Plug 'cakebaker/scss-syntax.vim'
Plug 'chr4/nginx.vim'
Plug 'chrisbra/csv.vim'
Plug 'ekalinin/dockerfile.vim'
Plug 'elixir-editors/vim-elixir'
Plug 'Glench/Vim-Jinja2-Syntax'
Plug 'godlygeek/tabular' | Plug 'tpope/vim-markdown'
Plug 'iamcco/markdown-preview.nvim', { 'do': 'cd app & yarn install' }
Plug 'jvirtanen/vim-hcl'
Plug 'lifepillar/pgsql.vim'
Plug 'othree/html5.vim'
Plug 'pangloss/vim-javascript'
Plug 'MaxMEllon/vim-jsx-pretty'
Plug 'PotatoesMaster/i3-vim-syntax'
Plug 'stephpy/vim-yaml'
Plug 'tmux-plugins/vim-tmux'
Plug 'tpope/vim-git'
Plug 'tpope/vim-liquid'
Plug 'tpope/vim-rails'
Plug 'vim-python/python-syntax'
Plug 'vim-ruby/vim-ruby'
Plug 'wgwoods/vim-systemd-syntax'
Plug 'towolf/vim-helm'
call plug#end()
" -----------------------------------------------------------------------------
" Color settings
" -----------------------------------------------------------------------------
" Enable 24-bit true colors if your terminal supports it.
if (has("termguicolors"))
" https://github.com/vim/vim/issues/993#issuecomment-255651605
let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
set termguicolors
endif
" Enable syntax highlighting.
syntax on
" Specific colorscheme settings (must come before setting your colorscheme).
if !exists('g:gruvbox_contrast_light')
let g:gruvbox_contrast_light='hard'
endif
" Set the color scheme.
colorscheme gruvbox
set background=dark
" Specific colorscheme settings (must come after setting your colorscheme).
if (g:colors_name == 'gruvbox')
if (&background == 'dark')
hi Visual cterm=NONE ctermfg=NONE ctermbg=237 guibg=#3a3a3a
else
hi Visual cterm=NONE ctermfg=NONE ctermbg=228 guibg=#f2e5bc
hi CursorLine cterm=NONE ctermfg=NONE ctermbg=228 guibg=#f2e5bc
hi ColorColumn cterm=NONE ctermfg=NONE ctermbg=228 guibg=#f2e5bc
endif
endif
" Spelling mistakes will be colored up red.
hi SpellBad cterm=underline ctermfg=203 guifg=#ff5f5f
hi SpellLocal cterm=underline ctermfg=203 guifg=#ff5f5f
hi SpellRare cterm=underline ctermfg=203 guifg=#ff5f5f
hi SpellCap cterm=underline ctermfg=203 guifg=#ff5f5f
" -----------------------------------------------------------------------------
" Status line
" -----------------------------------------------------------------------------
" Heavily inspired by: https://github.com/junegunn/dotfiles/blob/master/vimrc
function! s:statusline_expr()
let mod = "%{&modified ? '[+] ' : !&modifiable ? '[x] ' : ''}"
let ro = "%{&readonly ? '[RO] ' : ''}"
let ft = "%{len(&filetype) ? '['.&filetype.'] ' : ''}"
let fug = "%{exists('g:loaded_fugitive') ? fugitive#statusline() : ''}"
let sep = ' %= '
let pos = ' %-12(%l : %c%V%) '
let pct = ' %P'
return '[%n] %f %<'.mod.ro.ft.fug.sep.pos.'%*'.pct
endfunction
let &statusline = s:statusline_expr()
" -----------------------------------------------------------------------------
" Basic Settings
" Research any of these by running :help <setting>
" -----------------------------------------------------------------------------
let mapleader=" "
let maplocalleader=" "
set autoindent
set autoread
set backspace=indent,eol,start
set backupdir=/tmp//,.
if has("unix")
let s:uname = system("uname -s")
if s:uname == "Darwin"
" macOS clipboard sharing works with unnamed.
set clipboard=unnamed
else
set clipboard=unnamedplus
endif
endif
set colorcolumn=80
set complete+=kspell
set completeopt=menuone,longest
set cursorline
set directory=/tmp//,.
set encoding=utf-8
set expandtab smarttab
set formatoptions=tcqrn1
set hidden
set hlsearch
set ignorecase
set incsearch
set laststatus=2
set matchpairs+=<:> " Use % to jump between pairs
set mmp=5000
set modelines=2
set mouse=a
set nocompatible
set noerrorbells visualbell t_vb=
set noshiftround
set nospell
set nostartofline
set number relativenumber
set regexpengine=1
set ruler
set scrolloff=0
set shiftwidth=2
set showcmd
set showmatch
set shortmess+=c
set showmode
set smartcase
set softtabstop=2
set spelllang=en_us
set splitbelow
set splitright
set tabstop=2
set textwidth=0
set ttimeout
set timeoutlen=1000
set ttimeoutlen=0
set ttyfast
if !has('nvim')
set ttymouse=sgr
endif
set undodir=/tmp
set undofile
set virtualedit=block
set whichwrap=b,s,<,>
set wildmenu
set wildmode=full
set wrap
runtime! macros/matchit.vim
" -----------------------------------------------------------------------------
" Basic mappings
" -----------------------------------------------------------------------------
" Seamlessly treat visual lines as actual lines when moving around.
noremap j gj
noremap k gk
noremap <Down> gj
noremap <Up> gk
inoremap <Down> <C-o>gj
inoremap <Up> <C-o>gk
" Navigate around splits with a single key combo.
nnoremap <C-l> <C-w><C-l>
nnoremap <C-h> <C-w><C-h>
nnoremap <C-k> <C-w><C-k>
nnoremap <C-j> <C-w><C-j>
" Cycle through splits.
nnoremap <S-Tab> <C-w>w
" Press * to search for the term under the cursor or a visual selection and
" then press a key below to replace all instances of it in the current file.
nnoremap <Leader>r :%s///g<Left><Left>
nnoremap <Leader>rc :%s///gc<Left><Left><Left>
" The same as above but instead of acting on the whole file it will be
" restricted to the previously visually selected range. You can do that by
" pressing *, visually selecting the range you want it to apply to and then
" press a key below to replace all instances of it in the current selection.
xnoremap <Leader>r :s///g<Left><Left>
xnoremap <Leader>rc :s///gc<Left><Left><Left>
" Type a replacement term and press . to repeat the replacement again. Useful
" for replacing a few instances of the term (comparable to multiple cursors).
nnoremap <silent> s* :let @/='\<'.expand('<cword>').'\>'<CR>cgn
xnoremap <silent> s* "sy:let @/=@s<CR>cgn
" Clear search highlights.
map <Leader><Space> :let @/=''<CR>
" Format paragraph (selected or not) to 80 character lines.
nnoremap <Leader>g gqap
xnoremap <Leader>g gqa
" Prevent x from overriding what's in the clipboard.
noremap x "_x
noremap X "_x
" Prevent selecting and pasting from overwriting what you originally copied.
xnoremap p pgvy
" Keep cursor at the bottom of the visual selection after you yank it.
vmap y ygv<Esc>
" Edit Vim config file in a new tab.
map <Leader>ev :tabnew $MYVIMRC<CR>
" Source Vim config file.
map <Leader>sv :source $MYVIMRC<CR>
" Toggle spell check.
map <F5> :setlocal spell!<CR>
" Toggle relative line numbers and regular line numbers.
nmap <F6> :set invrelativenumber<CR>
" Copy the current buffer's path to your clipboard.
nmap cp :let @+ = expand("%")<CR>
" Automatically fix the last misspelled word and jump back to where you were.
" Taken from this talk: https://www.youtube.com/watch?v=lwD8G1P52Sk
nnoremap <leader>sp :normal! mz[s1z=`z<CR>
" Toggle visually showing all whitespace characters.
noremap <F7> :set list!<CR>
inoremap <F7> <C-o>:set list!<CR>
cnoremap <F7> <C-c>:set list!<CR>
" Move 1 more lines up or down in normal and visual selection modes.
nnoremap <C-k> :m .-2<CR>==
nnoremap <C-j> :m .+1<CR>==
vnoremap <C-k> :m '<-2<CR>gv=gv
vnoremap <C-j> :m '>+1<CR>gv=gv
nnoremap <C-Up> :m .-2<CR>==
nnoremap <C-Down> :m .+1<CR>==
vnoremap <C-Up> :m '<-2<CR>gv=gv
vnoremap <C-Down> :m '>+1<CR>gv=gv
" Toggle quickfix window.
function! QuickFix_toggle()
for i in range(1, winnr('$'))
let bnum = winbufnr(i)
if getbufvar(bnum, '&buftype') == 'quickfix'
cclose
return
endif
endfor
copen
endfunction
nnoremap <silent> <Leader>c :call QuickFix_toggle()<CR>
" Convert the selected text's title case using the external tcc script.
" Requires: https://github.com/nickjj/title-case-converter
vnoremap <Leader>tc c<C-r>=system('tcc', getreg('"'))[:-2]<CR>
" Navigate the complete menu items like CTRL+n / CTRL+p would.
inoremap <expr> <Down> pumvisible() ? "<C-n>" :"<Down>"
inoremap <expr> <Up> pumvisible() ? "<C-p>" : "<Up>"
" Select the complete menu item like CTRL+y would.
inoremap <expr> <Right> pumvisible() ? "<C-y>" : "<Right>"
inoremap <expr> <CR> pumvisible() ? "<C-y>" :"<CR>"
" Cancel the complete menu item like CTRL+e would.
inoremap <expr> <Left> pumvisible() ? "<C-e>" : "<Left>"
" -----------------------------------------------------------------------------
" Basic autocommands
" -----------------------------------------------------------------------------
" Auto-resize splits when Vim gets resized.
autocmd VimResized * wincmd =
" Update a buffer's contents on focus if it changed outside of Vim.
au FocusGained,BufEnter * :checktime
" Unset paste on InsertLeave.
autocmd InsertLeave * silent! set nopaste
" Make sure all types of requirements.txt files get syntax highlighting.
autocmd BufNewFile,BufRead requirements*.txt set ft=python
" Make sure .aliases, .bash_aliases and similar files get syntax highlighting.
autocmd BufNewFile,BufRead .*aliases* set ft=sh
" Make sure Kubernetes yaml files end up being set as helm files.
au BufNewFile,BufRead *.{yaml,yml} if getline(1) =~ '^apiVersion:' || getline(2) =~ '^apiVersion:' | setlocal filetype=helm | endif
" Ensure tabs don't get converted to spaces in Makefiles.
autocmd FileType make setlocal noexpandtab
" Only show the cursor line in the active buffer.
augroup CursorLine
au!
au VimEnter,WinEnter,BufWinEnter * setlocal cursorline
au WinLeave * setlocal nocursorline
augroup END
" Mappings to make Vim more friendly towards presenting slides.
autocmd BufNewFile,BufRead *.vpm call SetVimPresentationMode()
function SetVimPresentationMode()
nnoremap <buffer> <Right> :n<CR>
nnoremap <buffer> <Left> :N<CR>
if !exists('#goyo')
Goyo
endif
endfunction
" ----------------------------------------------------------------------------
" Basic commands
" ----------------------------------------------------------------------------
" Allow files to be saved as root when forgetting to start Vim using sudo.
command Sw :execute ':silent w !sudo tee % > /dev/null' | :edit!
" Add all TODO items to the quickfix list relative to where you opened Vim.
function! s:todo() abort
let entries = []
for cmd in ['git grep -niIw -e TODO -e FIXME 2> /dev/null',
\ 'grep -rniIw -e TODO -e FIXME . 2> /dev/null']
let lines = split(system(cmd), '\n')
if v:shell_error != 0 | continue | endif
for line in lines
let [fname, lno, text] = matchlist(line, '^\([^:]*\):\([^:]*\):\(.*\)')[1:3]
call add(entries, { 'filename': fname, 'lnum': lno, 'text': text })
endfor
break
endfor
if !empty(entries)
call setqflist(entries)
copen
endif
endfunction
command! Todo call s:todo()
" Profile Vim by running this command once to start it and again to stop it.
function! s:profile(bang)
if a:bang
profile pause
noautocmd qall
else
profile start /tmp/profile.log
profile func *
profile file *
endif
endfunction
command! -bang Profile call s:profile(<bang>0)
" -----------------------------------------------------------------------------
" Plugin settings, mappings and autocommands
" -----------------------------------------------------------------------------
" .............................................................................
" junegunn/fzf.vim
" .............................................................................
let $FZF_DEFAULT_OPTS = '--bind ctrl-a:select-all'
" Customize fzf colors to match your color scheme.
let g:fzf_colors =
\ { 'fg': ['fg', 'Normal'],
\ 'bg': ['bg', 'Normal'],
\ 'hl': ['fg', 'Comment'],
\ 'fg+': ['fg', 'CursorLine', 'CursorColumn', 'Normal'],
\ 'bg+': ['bg', 'CursorLine', 'CursorColumn'],
\ 'hl+': ['fg', 'Statement'],
\ 'info': ['fg', 'PreProc'],
\ 'prompt': ['fg', 'Conditional'],
\ 'pointer': ['fg', 'Exception'],
\ 'marker': ['fg', 'Keyword'],
\ 'spinner': ['fg', 'Label'],
\ 'header': ['fg', 'Comment'] }
let g:fzf_action = {
\ 'ctrl-t': 'tab split',
\ 'ctrl-b': 'split',
\ 'ctrl-v': 'vsplit',
\ 'ctrl-y': {lines -> setreg('*', join(lines, "\n"))}}
" Launch fzf with CTRL+P.
nnoremap <silent> <C-p> :FZF -m<CR>
" Map a few common things to do with FZF.
nnoremap <silent> <Leader><Enter> :Buffers<CR>
nnoremap <silent> <Leader>l :Lines<CR>
" Allow passing optional flags into the Rg command.
" Example: :Rg myterm -g '*.md'
command! -bang -nargs=* Rg
\ call fzf#vim#grep(
\ "rg --column --line-number --no-heading --color=always --smart-case " .
\ <q-args>, 1, fzf#vim#with_preview(), <bang>0)
" .............................................................................
" lambdalisue/fern.vim
" .............................................................................
" Disable netrw.
let g:loaded_netrw = 1
let g:loaded_netrwPlugin = 1
let g:loaded_netrwSettings = 1
let g:loaded_netrwFileHandlers = 1
augroup my-fern-hijack
autocmd!
autocmd BufEnter * ++nested call s:hijack_directory()
augroup END
function! s:hijack_directory() abort
let path = expand('%:p')
if !isdirectory(path)
return
endif
bwipeout %
execute printf('Fern %s', fnameescape(path))
endfunction
" Custom settings and mappings.
let g:fern#disable_default_mappings = 1
let g:fern#default_hidden = 1
noremap <silent> <Leader>f :Fern . -drawer -reveal=% -toggle -width=35<CR>
function! FernInit() abort
nmap <buffer><expr>
\ <Plug>(fern-my-open-expand-collapse)
\ fern#smart#leaf(
\ "\<Plug>(fern-action-open:select)",
\ "\<Plug>(fern-action-expand)",
\ "\<Plug>(fern-action-collapse)",
\ )
nmap <buffer> <CR> <Plug>(fern-my-open-expand-collapse)
nmap <buffer> <2-LeftMouse> <Plug>(fern-my-open-expand-collapse)
nmap <buffer> n <Plug>(fern-action-new-path)
nmap <buffer> d <Plug>(fern-action-remove)
nmap <buffer> m <Plug>(fern-action-move)
nmap <buffer> M <Plug>(fern-action-rename)
nmap <buffer> h <Plug>(fern-action-hidden-toggle)
nmap <buffer> r <Plug>(fern-action-reload)
nmap <buffer> k <Plug>(fern-action-mark)
nmap <buffer> K <Plug>(fern-action-mark-children:leaf)
nmap <buffer> b <Plug>(fern-action-open:split)
nmap <buffer> v <Plug>(fern-action-open:vsplit)
nmap <buffer><nowait> < <Plug>(fern-action-leave)
nmap <buffer><nowait> > <Plug>(fern-action-enter)
endfunction
augroup FernGroup
autocmd!
autocmd FileType fern call FernInit()
augroup END
" .............................................................................
" unblevable/quick-scope
" .............................................................................
" Trigger a highlight in the appropriate direction when pressing these keys.
let g:qs_highlight_on_keys=['f', 'F', 't', 'T']
" Only underline the highlights instead of using custom colors.
highlight QuickScopePrimary gui=underline cterm=underline
highlight QuickScopeSecondary gui=underline cterm=underline
" .............................................................................
" mhinz/vim-grepper
" .............................................................................
let g:grepper={}
let g:grepper.tools=["rg"]
xmap gr <plug>(GrepperOperator)
" After searching for text, press this mapping to do a project wide find and
" replace. It's similar to <leader>r except this one applies to all matches
" across all files instead of just the current file.
nnoremap <Leader>R
\ :let @s='\<'.expand('<cword>').'\>'<CR>
\ :Grepper -cword -noprompt<CR>
\ :cfdo %s/<C-r>s//g \| update
\<Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left>
" The same as above except it works with a visual selection.
xmap <Leader>R
\ "sy
\ gvgr
\ :cfdo %s/<C-r>s//g \| update
\<Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left>
" .............................................................................
" ntpeters/vim-better-whitespace
" .............................................................................
let g:strip_whitespace_confirm=0
let g:strip_whitelines_at_eof=1
let g:strip_whitespace_on_save=1
" .............................................................................
" Konfekt/FastFold
" .............................................................................
let g:fastfold_savehook=0
let g:fastfold_fold_command_suffixes=[]
" .............................................................................
" junegunn/limelight.vim
" .............................................................................
let g:limelight_conceal_ctermfg=244
" .............................................................................
" iamcco/markdown-preview.nvim
" .............................................................................
let g:mkdp_auto_close=0
let g:mkdp_refresh_slow=1
let g:mkdp_markdown_css=fnameescape($HOME).'/.local/lib/github-markdown-css/github-markdown.css'
" .............................................................................
" SirVer/ultisnips
" .............................................................................
let g:UltiSnipsJumpForwardTrigger="<tab>"
let g:UltiSnipsJumpBackwardTrigger="<s-tab>"
" .............................................................................
" janko/vim-test
" .............................................................................
if has('nvim')
let test#strategy='neovim'
else
let test#strategy='vimterminal'
endif
let test#python#pytest#executable='docker-compose exec web py.test'
let test#ruby#rails#executable='docker-compose exec -e RAILS_ENV=test webpacker rails test'
let test#elixir#exunit#executable='docker-compose exec -e MIX_ENV=test web mix test'
nmap <silent> t<C-n> :TestNearest<CR>
nmap <silent> t<C-f> :TestFile<CR>
nmap <silent> t<C-a> :TestSuite<CR>
nmap <silent> t<C-l> :TestLast<CR>
nmap <silent> t<C-v> :TestVisit<CR>
6 ColbyCheeseVimrc.txt
https://github.com/colbycheeze/dotfiles
" Type :so % to refresh .vimrc after making changes
" Use Vim settings, rather then Vi settings. This setting must be as early as
" possible, as it has side effects.
set nocompatible
" Leader - ( Spacebar )
let mapleader = " "
set backspace=2 " Backspace deletes like most programs in insert mode
set nobackup
set nowritebackup
set noswapfile " http://robots.thoughtbot.com/post/18739402579/global-gitignore#comment-458413287
set history=50
set ruler " show the cursor position all the time
set showcmd " display incomplete command
set laststatus=2 " Always display the status line
set autowrite " Automatically :write before running commands
set autoread " Reload files changed outside vim
" Trigger autoread when changing buffers or coming back to vim in terminal.
au FocusGained,BufEnter * :silent! !
"Set default font in mac vim and gvim
set guifont=Inconsolata\ for\ Powerline:h24
set cursorline " highlight the current line
set visualbell " stop that ANNOYING beeping
set wildmenu
set wildmode=list:longest,full
"Allow usage of mouse in iTerm
set ttyfast
set mouse=a
" set ttymouse=xterm2
" Make searching better
set gdefault " Never have to type /g at the end of search / replace again
set ignorecase " case insensitive searching (unless specified)
set smartcase
set hlsearch
nnoremap <silent> <leader>, :noh<cr> " Stop highlight after searching
set incsearch
set showmatch
" Softtabs, 2 spaces
set tabstop=2
set shiftwidth=2
set shiftround
set expandtab
" Display extra whitespace
set list listchars=tab:»·,trail:·,nbsp:·
" Make it obvious where 100 characters is
set textwidth=100
" set formatoptions=cq
set formatoptions=qrn1
set wrapmargin=0
set colorcolumn=+1
" Numbers
set number
set numberwidth=5
" Open new split panes to right and bottom, which feels more natural
" set splitbelow
set splitright
" Auto resize Vim splits to active split
set winwidth=104
set winheight=5
set winminheight=5
set winheight=999
"HTML Editing
set matchpairs+=<:>
" Treat <li> and <p> tags like the block tags they are
let g:html_indent_tags = 'li\|p'
" ================ Scrolling ========================
set scrolloff=8 "Start scrolling when we're 8 lines away from margins
set sidescrolloff=15
set sidescroll=1
"Toggle relative numbering, and set to absolute on loss of focus or insert mode
set rnu
function! ToggleNumbersOn()
set nu!
set rnu
endfunction
function! ToggleRelativeOn()
set rnu!
set nu
endfunction
autocmd FocusLost * call ToggleRelativeOn()
autocmd FocusGained * call ToggleRelativeOn()
autocmd InsertEnter * call ToggleRelativeOn()
autocmd InsertLeave * call ToggleRelativeOn()
"Use enter to create new lines w/o entering insert mode
nnoremap <CR> o<Esc>
"Below is to fix issues with the ABOVE mappings in quickfix window
autocmd CmdwinEnter * nnoremap <CR> <CR>
autocmd BufReadPost quickfix nnoremap <CR> <CR>
" Quicker window movement
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-h> <C-w>h
nnoremap <C-l> <C-w>l
" <c-h> is interpreted as <bs> in neovim
" This is a bandaid fix until the team decides how
" they want to handle fixing it...(https://github.com/neovim/neovim/issues/2048)
nnoremap <silent> <bs> :TmuxNavigateLeft<cr>
" Navigate properly when lines are wrapped
nnoremap j gj
nnoremap k gk
" Use tab to jump between blocks, because it's easier
nnoremap <tab> %
vnoremap <tab> %
" Set spellfile to location that is guaranteed to exist, can be symlinked to
" Dropbox or kept in Git and managed outside of thoughtbot/dotfiles using rcm.
set spellfile=$HOME/.vim-spell-en.utf-8.add
" Always use vertical diffs
set diffopt+=vertical
" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if (&t_Co > 2 || has("gui_running")) && !exists("syntax_on")
syntax on
endif
" Load up all of our plugins
if filereadable(expand("~/.vimrc.bundles"))
source ~/.vimrc.bundles
endif
filetype plugin indent on
""" SYSTEM CLIPBOARD COPY & PASTE SUPPORT
set pastetoggle=<F2> "F2 before pasting to preserve indentation
"Copy paste to/from clipboard
vnoremap <C-c> "*y
map <silent><Leader>p :set paste<CR>o<esc>"*]p:set nopaste<cr>"
map <silent><Leader><S-p> :set paste<CR>O<esc>"*]p:set nopaste<cr>"
""" MORE AWESOME HOTKEYS
"
"
" Run the q macro
nnoremap <leader>q @q
" bind K to grep word under cursor
nnoremap K :grep! "\b<C-R><C-W>\b"<CR>:cw<CR>
" bind \ (backward slash) to grep shortcut
command! -nargs=+ -complete=file -bar Ag silent! grep! <args>|cwindow|redraw!
nnoremap \ :Ag<SPACE>
" Ag will search from project root
let g:ag_working_path_mode="r"
"Map Ctrl + S to save in any mode
noremap <silent> <C-S> :update<CR>
vnoremap <silent> <C-S> <C-C>:update<CR>
inoremap <silent> <C-S> <C-O>:update<CR>
" Also map leader + s
map <leader>s <C-S>
" Quickly close windows
nnoremap <leader>x :x<cr>
nnoremap <leader>X :q!<cr>
" zoom a vim pane, <C-w>= to re-balance
nnoremap <leader>- :wincmd _<cr>:wincmd \|<cr>
nnoremap <leader>= :wincmd =<cr>
" resize panes
nnoremap <silent> <Right> :vertical resize +5<cr>
nnoremap <silent> <Left> :vertical resize -5<cr>
nnoremap <silent> <Up> :resize +5<cr>
nnoremap <silent> <Down> :resize -5<cr>
inoremap <Tab> <c-r>=InsertTabWrapper()<cr>
inoremap <S-Tab> <c-n>
" Switch between the last two files
nnoremap <leader><leader> <c-^>
" AUTOCOMMANDS - Do stuff
" Save whenever switching windows or leaving vim. This is useful when running
" the tests inside vim without having to save all files first.
au FocusLost,WinLeave * :silent! wa
" automatically rebalance windows on vim resize
autocmd VimResized * :wincmd =
"update dir to current file
autocmd BufEnter * silent! cd %:p:h
augroup vimrcEx
autocmd!
" When editing a file, always jump to the last known cursor position.
" Don't do it for commit messages, when the position is invalid, or when
" inside an event handler (happens when dropping a file on gvim).
autocmd BufReadPost *
\ if &ft != 'gitcommit' && line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
" Set syntax highlighting for specific file types
autocmd BufRead,BufNewFile *.md set filetype=markdown
" autocmd BufRead *.jsx set ft=jsx.html
" autocmd BufNewFile *.jsx set ft=jsx.html
" Enable spellchecking for Markdown
autocmd FileType markdown setlocal spell
" Automatically wrap at 100 characters for Markdown
autocmd BufRead,BufNewFile *.md setlocal textwidth=100
" Automatically wrap at 100 characters and spell check git commit messages
autocmd FileType gitcommit setlocal textwidth=100
autocmd FileType gitcommit setlocal spell
" Allow stylesheets to autocomplete hyphenated words
autocmd FileType css,scss,sass,less setlocal iskeyword+=-
augroup END
" TODO: Don't think I need this anymore? Pretty sure supertab handles it
" Tab completion
" will insert tab at beginning of line,
" will use completion if not at beginning
" function! InsertTabWrapper()
" let col = col('.') - 1
" if !col || getline('.')[col - 1] !~ '\k'
" return "\<tab>"
" else
" return "\<c-p>"
" endif
" endfunction
7 ColbyCheeseVimrcBundles.txt
"
" :so % to refresh .vimrc after making changes
" :PlugInstall to install new stuff
" :PlugUpdate to update to latest versions
"
if &compatible
set nocompatible
end
call plug#begin('~/.vim/plugged')
""" Theme / Pretty stuff
"""
" [1]
Plug 'altercation/vim-colors-solarized'
Plug 'endel/vim-github-colorscheme'
" Awesome looking meta at bottom
" Fugitive will help with git related stuff, and show branch on statusline
Plug 'tpope/vim-fugitive' | Plug 'vim-airline/vim-airline' | Plug 'vim-airline/vim-airline-themes'
""
""" Some ESSENTIAL IDE like plugins for Vim
"""
" [2] File tree viewer
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
" [3]
" Several plugins to help work with Tmux
Plug 'christoomey/vim-tmux-navigator'
Plug 'https://github.com/christoomey/vim-tmux-runner'
Plug 'christoomey/vim-run-interactive'
" [4] search filesystem with ctrl+p
Plug 'ctrlpvim/ctrlp.vim'
" Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
" [5] Code highlighting and linting
Plug 'scrooloose/syntastic' "Run linters and display errors etc
" Plug 'benekastah/neomake' "Async Jobs (can use it instead of syntastic, but hard to setup)
Plug 'pangloss/vim-javascript' | Plug 'mxw/vim-jsx'
Plug 'jimmyhchan/dustjs.vim' "Highlighting for Dust
Plug 'elmcast/elm-vim' "Highlighting for Elm
" [6] Adds a ; at the end of a line by pressing <leader> ;
Plug 'lfilho/cosco.vim'
Plug 'jiangmiao/auto-pairs' "MANY features, but mostly closes ([{' etc
Plug 'vim-scripts/HTML-AutoCloseTag' "close tags after >
Plug 'vim-scripts/tComment' "Comment easily with gcc
Plug 'tpope/vim-repeat' "allow plugins to utilize . command
Plug 'tpope/vim-surround' "easily surround things...just read docs for info
Plug 'vim-scripts/matchit.zip' " % also matches HTML tags / words / etc
Plug 'duff/vim-scratch' "Open a throwaway scratch buffer
""
""" Utilities / Extras / Etc
"""
" [7] Make gists of current buffer
" View (https://github.com/mattn/gist-vim) for setup instructions
Plug 'mattn/webapi-vim' | Plug 'mattn/gist-vim'
" [8] Diary, notes, whatever. It's amazing
Plug 'vimwiki/vimwiki'
" Opens a browser to preview markdown files
Plug 'suan/vim-instant-markdown', {'do': 'npm install -g instant-markdown-d'}
""
" [9]
Plug 'SirVer/ultisnips' | Plug 'justinj/vim-react-snippets' | Plug 'colbycheeze/vim-snippets'
" [10]
" supertab makes tab work with autocomplete and ultisnips
Plug 'ervandew/supertab'
" For YouCompleteMe, have you installed using:
" ./install.py --tern-completer
" Provides Async autocomplete with Tern
Plug 'https://github.com/Shougo/deoplete.nvim'
" IDE like code intelligence for Javascript
Plug 'ternjs/tern_for_vim', {'do': 'npm install'}
" Reads any .editorconfig files and sets spacing etc automatically
Plug 'editorconfig/editorconfig-vim'
""" TODO / Plugins to evaluate
" Figure out how to change matchit to ALSO use <tab>
" Plug 'junegunn/vim-easy-align'
call plug#end()
"""" PLUGIN RELATED TWEAKS
""
"
" [1]
" Color scheme
syntax enable
" let g:solarized_termcolors=16
let g:colarized_termtrans = 1
let g:solarized_termcolors=256
let g:solarized_visibility = "high"
let g:solarized_contrast = "high"
colorscheme solarized
" set background=dark
" Allow powerline symbols to show up
let g:airline_powerline_fonts = 1
" [2]
map <silent> <C-n> :NERDTreeToggle<cr>
nnoremap <C-t> :call ToggleRelativeOn()<cr>
" Close vim if only NERDTree is open
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
" [3]
" Allow moving around between Tmux windows
nnoremap <silent> <C-h> :TmuxNavigateLeft<cr>
nnoremap <silent> <C-j> :TmuxNavigateDown<cr>
nnoremap <silent> <C-k> :TmuxNavigateUp<cr>
nnoremap <silent> <C-l> :TmuxNavigateRight<cr>
let g:tmux_navigator_no_mappings = 1
let g:tmux_navigator_save_on_switch = 1
"
"Open a tmux pane with Node
nnoremap <leader>node :VtrOpenRunner {'orientation': 'h', 'percentage': 50, 'cmd': 'node'}<cr>
" [4]
" Use The Silver Searcher https://github.com/ggreer/the_silver_searcher
if executable('ag')
" Use Ag over Grep
set grepprg=ag\ --nogroup\ --nocolor
" Use ag in CtrlP for listing files. Lightning fast and respects .gitignore
let g:ctrlp_user_command = 'ag %s -l --nocolor -g ""'
let g:ctrlp_working_path_mode = 'r'
" ag is fast enough that CtrlP doesn't need to cache
let g:ctrlp_use_caching = 0
let g:ctrlp_extensions = ['line']
endif
" [5]
" Setup for NEOMAKE plugin ~~~~~~~
" let g:neomake_scss_csslint_maker = ['sass-lint']
" let g:neomake_javascript_enabled_makers = ['eslint']
" let g:neomake_open_list = 0
" let g:neomake_warning_sign = {
" \ 'texthl': 'WarningMsg',
" \ }
"
" let g:neomake_error_sign = {
" \ 'texthl': 'ErrorMsg',
" \ }
" autocmd! BufWritePost,BufEnter * Neomake
" ~~~~~~~~~~~~~~~~
" configure syntastic syntax checking to check on open as well as save
let g:syntastic_html_tidy_ignore_errors=[" proprietary attribute \"ng-"]
let g:syntastic_mode_map = { 'mode': 'active', 'active_filetypes': ['javascript'], 'passive_filetypes': [] }
set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0
" " Syntastic will search for an .eslintrc in your project, otherwise it defaults
autocmd FileType javascript let b:syntastic_checkers = findfile('.eslintrc', '.;') != '' ? ['eslint'] : ['standard']
" these 2 lines check to see if eslint is installed via local npm and runs that before going global
let s:eslint_path = system('PATH=$(npm bin):$PATH && which eslint')
let b:syntastic_javascript_eslint_exec = substitute(s:eslint_path, '^\n*\s*\(.\{-}\)\n*\s*$', '\1', '')
" " Allow highlighting of HTML within Javascript (for React)
let g:javascript_enable_domhtmlcss = 1
let g:jsx_ext_required = 0
" [6] Key mapping for Cosco.vim - space + ; to add semicolon or comma in Javascript or CSS
autocmd FileType javascript,css nnoremap <silent> <Leader>; :call cosco#commaOrSemiColon()<CR>
autocmd FileType javascript,css inoremap <silent> <Leader>; <c-o>:call cosco#commaOrSemiColon()<CR>
" [7] Gist setup
let g:gist_clip_command = 'pbcopy' "Using Gist will copy URL to clipboard automatically
let g:gist_detect_filetype = 1
let g:gist_open_browser_after_post = 1
" [8] Set Vim Wiki to my Dropbox directory
let g:vimwiki_list = [{'path':'$HOME/Dropbox/vimwiki'}]
" [9]
" Set ultisnips triggers
let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsJumpForwardTrigger="<tab>"
let g:UltiSnipsJumpBackwardTrigger="<s-tab>"
let g:UltiSnipsEditSplit="vertical"
" [10] make YCM compatible with UltiSnips (using supertab)
let g:SuperTabDefaultCompletionType = '<C-n>'
let g:deoplete#enable_at_startup = 1
if !exists('g:deoplete#omni#input_patterns')
let g:deoplete#omni#input_patterns = {}
endif
autocmd InsertLeave,CompleteDone * if pumvisible() == 0 | pclose | endif
" omnifuncs
augroup omnifuncs
autocmd!
autocmd FileType css setlocal omnifunc=csscomplete#CompleteCSS
autocmd FileType html,markdown setlocal omnifunc=htmlcomplete#CompleteTags
autocmd FileType javascript setlocal omnifunc=javascriptcomplete#CompleteJS
autocmd FileType xml setlocal omnifunc=xmlcomplete#CompleteTags
augroup end
" tern
if exists('g:plugs["tern_for_vim"]')
let g:tern_show_argument_hints = 'on_hold'
let g:tern_show_signature_in_pum = 1
let g:tern_map_keys = 1
autocmd FileType javascript setlocal omnifunc=tern#Complete
endif
"set up path to editorconfig
let g:EditorConfig_exec_path = findfile('.editorconfig', '.;')
" Not sure what the below code does...look into Tern docs etc and figure it out?
" Found this snippet on a forum post that says it gets everything working
" https://github.com/Valloric/YouCompleteMe/issues/570
" autocmd FileType javascript setlocal omnifunc=tern#Complete
" " Run commands that require an interactive shell
" nnoremap <Leader>r :RunInInteractiveShell<space>
"