Skip to content

Instantly share code, notes, and snippets.

@chew-z
Created February 19, 2017 16:15
Show Gist options
  • Save chew-z/a87585bb3a5179d93211d91a986d4342 to your computer and use it in GitHub Desktop.
Save chew-z/a87585bb3a5179d93211d91a986d4342 to your computer and use it in GitHub Desktop.
My precious .vimrc
" :set spelllang=pl,en
" :set spell
" ---- Color scheme ----
" in .gvimrc for MacVim
let g:seoul256_background = 235
colo seoul256
" Make Vim more useful
" Enable syntax highlighting
" syntax on will overrule commands like :highlight
" but syntax enable not - see docs
syntax enable
" set comment in italics
highlight Comment cterm=italic
" Enable file type detection
filetype on
filetype plugin on
set nocompatible
" A buffer becomes hidden when it is abandoned
set hidden
" Use the OS clipboard by default (on versions compiled with `+clipboard`)
set clipboard=unnamed
" Enhance command-line completion
set wildmenu
" Allow cursor keys in insert mode
set esckeys
" Allow backspace in insert mode
set backspace=indent,eol,start
" Optimize for fast terminal connections
set ttyfast
" Add the g flag to search/replace by default
set gdefault
" Use UTF-8 without BOM
set encoding=utf-8 nobomb
" Change mapleader to Space!
let mapleader = "\<Space>"
" Don’t add empty newlines at the end of files
set binary
set noeol
" we like long history
set history=2048
" Centralize backups, swapfiles and undo history
set backupdir=~/.vim/backups
set directory=~/.vim/swaps
if exists("&undodir")
set undodir=~/.vim/undo
endif
" Don’t create backups when editing files in certain directories
set backupskip=/tmp/*,/private/tmp/*
" Respect modeline in files
set modeline
set modelines=4
" Enable per-directory .vimrc files and disable unsafe commands in them
set exrc
set secure
" Enable line numbers
set number
" Highlight current line
set cursorline
" Make tabs 4 spaces
set tabstop=4
set shiftwidth=4
set softtabstop=4
set expandtab
" Show “invisible” characters
set lcs=tab:▸\ ,trail:·,eol:¬,nbsp:_
set list
" Highlight searches
set hlsearch
" Ignore case of searches
set ignorecase
" but be case sensitive when uppercase in search term
set smartcase
" Highlight dynamically as pattern is typed
set incsearch
" For regular expressions turn magic on
set magic
" Show matching brackets when text indicator is over them
set showmatch
" How many tenths of a second to blink when matching brackets
set mat=2
" Always show status line
set laststatus=2
" Enable mouse in all modes
set mouse=a
" large terminal mouse support in Vim
" https://www.iterm2.com/faq.html
if has('mouse_sgr')
set ttymouse=sgr
endif
" Disable error bells
set noerrorbells
" Don’t reset cursor to start of line when moving around.
set nostartofline
" Show the cursor position
set ruler
" Don’t show the intro message when starting Vim
set shortmess=atI
" Show the current mode
set showmode
" Show the filename in the window titlebar
set title
" Show the (partial) command as it’s being typed
set showcmd
" Use relative line numbers
if exists("&relativenumber")
set relativenumber
au BufReadPost * set relativenumber
endif
" Start scrolling three lines before the horizontal window border
set scrolloff=3
" Don't redraw while executing macros (good performance config)
set lazyredraw
" define new silent command
" http://vi.stackexchange.com/questions/1942/how-to-execute-shell-commands-silently
command! -nargs=1 Silent execute ':silent !'.<q-args> | execute ':redraw!'
" Return to last edit position when opening files (You want this!)
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
" Remember info about open buffers on close
set viminfo^=%
" ---- Key mappings ----
" press <space> twice in normal mode to save file - macOS Cmd+S also works in MacVim
nnoremap <leader><leader> :w<CR>
" press <ESC> twice in insert mode to quit to normal mode and save file
imap <ESC><ESC> <ESC>:w<CR>
" Opens a new tab with the current buffer's path
" Super useful when editing files in the same directory
map <leader>te :tabedit <c-r>=expand("%:p:h")<cr>/
" Switch CWD to the directory of the open buffer
map <leader>cd :cd %:p:h<cr>:pwd<cr>
" Use <space>d on top of a word to look it up in Dictionary.app
" nmap <leader>d :Silent open dict://<cword><CR><CR>
map <leader>d "dyiw:call MacDict(@d)<CR>
" fzf
nnoremap <leader>o :Files<cr>
nnoremap <C-P> :Files<cr>
" For editing markdown files (and Vim-Notes).
" Convert selected text to link (url comes from OSX clipboard)
" 'i' like image 'l' like link
" `> `< - go to end, beggining of selection, "*p - insert OSX clipboard
vnoremap <Leader>l <ESC>`<i[<ESC>`>la](<C-R><C-R>*)<ESC>
vnoremap <Leader>i <ESC>`<i![<ESC>`>2la](<C-R><C-R>*)<ESC>
" find and replace
" https://elliotekj.com/2016/08/30/better-find-and-replace-in-vim/
" /foo - to find 'foo'
" <leader>r - to replace / <leader>rl to replace in current line
" c - confirm replace
map <leader>r :%s///cg<left><left><left>
map <leader>rl :s///g<left><left>
" remove last search highlight by hitting return.
" n will find the next occurrence (which will be highlighted again)
nnoremap <silent> <CR> :nohlsearch<CR><CR>
" brighten/dim background - a'la macOS dim screen function keys
" 233 (darkest) ~ 239 (lightest) 252 (darkest) ~ 256 (lightest)
function Seoul256Brighten()
if g:seoul256_background == 239
let g:seoul256_background = 252
elseif g:seoul256_background == 256
let g:seoul256_background = 256
else
let g:seoul256_background += 1
endif
colo seoul256
endfunction
"
function Seoul256Dim()
if g:seoul256_background == 252
let g:seoul256_background = 239
elseif g:seoul256_background == 233
let g:seoul256_background = 233
else
let g:seoul256_background -= 1
endif
colo seoul256
endfunction
"
nmap <F1> :call Seoul256Dim()<CR>
nmap <F2> :call Seoul256Brighten()<CR>
" nmap <F1> :let g:seoul256_background -= 1<CR>:colo seoul256<CR>
" nmap <F2> :let g:seoul256_background += 1<CR>:colo seoul256<CR>
" Insert current date under cursor using Fn4 (also in insert mode)
" Maping used mostly in Vim Notes
nnoremap <F4> "=strftime("%a, %d %b %Y")<CR>
inoremap <F4> <C-R>=strftime("%a, %d %b %Y")<CR>
" mappings for TwitVim
nnoremap <F7> :FriendsTwitter<CR>
nnoremap <S-F7> :ListTwitter forex-i<CR>
nnoremap <A-F7> :ListTwitter forex-ii<CR>
nnoremap <D-F7> :ListTwitter macro<CR>
" <Leader><Leader> - refreshes the timeline. See |:RefreshTwitter|.
" <C-PgUp> / <C-PgDown> serves 2nd (older) page of list/timeline and back
" ---- Options for plugins ----
" vim-notes
let g:notes_directories = ['~/Notes/Current']
let g:notes_suffix = '.txt'
let g:notes_markdown_program = "/usr/local/bin/multimarkdown"
" let g:notes_markdown_program = "/usr/local/bin/cmark"
" TwitVim
" Under Mac OS, the following will use the default browser
let twitvim_browser_cmd = 'open'
let twitvim_proxy = "127.0.0.1:8118"
" The system default for socket timeouts may be as long as a few minutes, so
" TwitVim will appear to hang for that length of time before displaying
" an error message.
let twitvim_net_timeout = 45
let twitvim_show_header = 1
" let twitvim_filter_enable = 1
" let twitvim_filter_regex = '@GetGlue\|/youtu\.be/'
let twitvim_count = 50
" default location for :TrendTwitter
let twitvim_woeid = 523920
" Goyo and Limelight
" Color name (:help gui-colors) or RGB color
let g:limelight_conceal_guifg = 'DarkGray'
" Default: 0.5
let g:limelight_default_coefficient = 0.7
" Number of preceding/following paragraphs to include (default: 0)
let g:limelight_paragraph_span = 0
let g:goyo_linenr = 1
let g:goyo_height = '90%'
let g:goyo_width = 120
"
function! s:goyo_enter()
" silent !tmux set status off
" silent !tmux list-panes -F '\#F' | grep -q Z || tmux resize-pane -Z
set noshowmode
set noshowcmd
set scrolloff=999
Limelight
" ...
endfunction
"
function! s:goyo_leave()
" silent !tmux set status on
" silent !tmux list-panes -F '\#F' | grep -q Z && tmux resize-pane -Z
set showmode
set showcmd
set scrolloff=3
Limelight!
" ...
endfunction
"
autocmd! User GoyoEnter nested call <SID>goyo_enter()
autocmd! User GoyoLeave nested call <SID>goyo_leave()
"
" fzf
let g:fzf_launcher = "/usr/local/bin/fzf %s"
" :Rg command - search within files - start fzf with hidden preview window that can be enabled with "?" key
command! -bang -nargs=* Rg
\ call fzf#vim#grep(
\ 'rg --column --color=always --no-heading --smart-case --hidden --follow --glob "!.git/*" '.shellescape(<q-args>), 1,
\ <bang>0 ? fzf#vim#with_preview('up:60%')
\ : fzf#vim#with_preview('right:50%:hidden', '?'),
\ <bang>0)
command! -bang -nargs=* Notes
\ call fzf#vim#grep(
\ 'rg --no-heading --vimgrep '.shellescape(<q-args>).' ~/Notes ', 1,
\ <bang>0 ? fzf#vim#with_preview('up:60%')
\ : fzf#vim#with_preview('right:50%:hidden', '?'),
\ <bang>0)
" Augmenting Ag command
" Ag doesn't fully support .gitignore. It doesn't support unicode.
" Default options are --nogroup --column --color
let s:ag_folder = ' $HOME/Documents $HOME/Notes '
let s:ag_options = ' '
command! -bang -nargs=* Ag
\ call fzf#vim#grep(
\ 'ag --nogroup --column --color '.s:ag_options.shellescape(<q-args>).s:ag_folder, 1,
\ <bang>0 ? fzf#vim#with_preview('up:60%')
\ : fzf#vim#with_preview('right:50%:hidden', '?'),
\ <bang>0)
"
" Using locate - :Locate / will list every file on the system.
command! -nargs=1 -bang Locate call fzf#run(fzf#wrap(
\ {'source': 'locate <q-args>', 'options': '-m'}, <bang>0))
"
" ---- Plugins ----
" vim-plug
call plug#begin('~/.vim/plugged')
" Seoul256 colorscheme
Plug 'junegunn/seoul256.vim'
" vim-notes
Plug 'xolox/vim-misc'
Plug 'xolox/vim-notes'
Plug 'vim-scripts/utl.vim'
" Markdown
Plug 'plasticboy/vim-markdown'
" Distraction free editing
Plug 'junegunn/goyo.vim'
" automatic with focus
Plug 'junegunn/limelight.vim'
" Markdown preview in Chrome
Plug 'junegunn/vim-xmark'
" Twitter
Plug 'vim-scripts/TwitVim'
" HN in vim
Plug 'ryanss/vim-hackernews'
" MacDict - search macOS system dictionary from Vim
Plug 'jonhiggs/MacDict.vim'
" fzf
Plug '/usr/local/opt/fzf'
Plug 'junegunn/fzf.vim'
call plug#end()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment