Skip to content

Instantly share code, notes, and snippets.

@nima
Created December 21, 2016 01:47
Show Gist options
  • Save nima/09e0737874d35cb262c8bc06bc572e13 to your computer and use it in GitHub Desktop.
Save nima/09e0737874d35cb262c8bc06bc572e13 to your computer and use it in GitHub Desktop.
Vim RC
". BEGIN -={
let g:solarized_termcolors=256
"let colortheme="solarized"
". advantage candy distinguished earendel gentooish
". grb256 inkpot jellybeans liquidcarbon moria
". nu42dark twilight vividchalk wombat zenburn
". molokai mustang koehler blue darkblue
". default delek desert elflord evening
". koehler morning murphy pablo peachpuff
". ron shine slate torte zellner
let base16colorspace=256
"let colortheme="base16-solarized"
let colortheme="slate"
set verbose=0
set nocompatible
". Import this script once only
"if exists("g:imported")
" finish
"endif
"let g:imported = 1
". Encoding -={
set encoding=utf-8
set fileencodings=ucs-bom,utf-8,latin1,default
set fileformats=unix,mac,dos " Support all three, in this order
set fillchars+=stl:\ ,stlnc:\
". }=-
". Core
set nobackup
set noswapfile
set hidden
let mapleader=","
". Modelines
set modeline
set modeline modelines=5
". Memory
let s:RD_use_mem = 1 " Allow vim to hog memory
if s:RD_use_mem
set history=1000
set maxmemtot=2000000
set maxmem=2000000
endif
". Pathogen -={
execute pathogen#infect()
call pathogen#helptags()
syntax on
filetype plugin indent on
". }=-
". Colors
let s:RD_use_conn = 1 " Allow vim to use colors
if s:RD_use_conn
syn sync fromstart
set ttyfast
set ttyscroll=0
set synmaxcol=500
set t_Co=256
if &t_Co > 2 || has("gui_running")
syntax on
set background=dark
set hlsearch
set incsearch
if version > 700
"augroup HiglightSpecial
" autocmd!
" autocmd WinEnter,VimEnter * :silent! call matchadd('Special', '\<\(VULN\|PENTEST\|NiMA\|rasputin\|fuck\|cunt\|shit\|whore\|slut\)\>', -1)
"augroup END
call matchadd('Special', '\<\(NiMA\|rasputin\|fuck\|cunt\|shit\|whore\|slut\)\>', 9)
call matchadd('Todo', '\<\(TODO\|FIXME\|XXX\|DEPRECATED\|DEBUG\|DEEPDIVE\|<<<<<<<\|=======\|>>>>>>>\)\>', 9)
call matchadd('Special', '-={\|}=-')
call matchadd('Operator', '^#. .* -={$', -3)
call matchadd('Operator', '^#. }=-', -1)
call matchadd('Comment', '^#\. ', -1)
endif
if &t_Co >= 256 || has("gui_running")
exe "colorscheme ".colortheme
endif
"hi Comment ctermfg=darkgrey
endif
endif
". Auto-complete
set wildmenu
let s:RD_privacy = 0
". Save and Restore State
if s:RD_privacy == 0
if has("autocmd")
" When editing a file, always jump to the last cursor position
autocmd BufReadPost *
\ if line("'\"") > 0 && line ("'\"") <= line("$") |
\ exe "normal g'\"" |
\ endif
endif
endif
". }=-
". Basics -={
set nostartofline
set ignorecase " ignore case when searching
set smartcase " ignore case if search pattern is all lowercase, case-sensitive otherwise
set joinspaces " insert 2 spaces when joining lines terminated with a period.
set mat=1 " 10th of second blink on matching brackets
set showmatch " set show matching parenthesis
nnoremap Q gqip
:
"set title
set cursorline " highlight the current line
set number " always show line numbers
highlight LineNr term=bold cterm=NONE ctermfg=DarkGrey ctermbg=NONE gui=NONE guifg=DarkGrey guibg=NONE
if version >= 640 | set numberwidth=5 | endif
cmap w!! w !sudo tee % >/dev/null
"nnoremap ; :
". }=-
". List Toggle -={
set listchars=tab:\|\ ,trail:.,extends:>,precedes:<,eol:$ " What to show when you do :set list
fun! ListToggle()
if !exists("b:list") || !b:list
let b:list = 1
set list
else
let b:list = 0
set nolist
endif
endfunction
". }=-
noremap <LeftDrag> <LeftMouse>
noremap! <LeftDrag> <LeftMouse>
set mouse=a
if has("mouse_sgr")
set ttymouse=sgr
else
set ttymouse=xterm2
end
". Warnings -={
". Past 80 columns, Alert -={
if version > 700
set colorcolumn=81,82,83,84
au! FileType gitcommit set colorcolumn=71,72,73,74
let s:color_column_old = 0
function! s:ToggleColorColumn()
if s:color_column_old == 0
let s:color_column_old = &colorcolumn
windo let &colorcolumn = 0
else
windo let &colorcolumn=s:color_column_old
let s:color_column_old = 0
endif
endfunction
endif
"highlight OverLength ctermbg=red ctermfg=white
"match OverLength /\%81v.*/
". }=-
". highlight spaces at the end of the line...
highlight WhitespaceEOL ctermbg=red guibg=red
match WhitespaceEOL /\s\+$/
". }=-
". Status Bar -={
set laststatus=2 " enable status line always
function! InsertStatuslineColor(mode)
if a:mode == 'i'
hi StatusLine ctermbg=0 ctermfg=blue cterm=reverse
elseif a:mode == 'r'
hi StatusLine ctermbg=0 ctermfg=red cterm=reverse
elseif a:mode == 's'
hi StatusLine ctermbg=0 ctermfg=yellow cterm=reverse
elseif a:mode == 'v'
hi StatusLine ctermbg=0 ctermfg=magenta cterm=reverse
else
hi StatusLine ctermbg=0 ctermfg=cyan cterm=reverse
endif
endfunction
if version >= 700
hi StatusLine ctermbg=0 ctermfg=green cterm=reverse
au InsertLeave * hi StatusLine ctermbg=0 ctermfg=green cterm=reverse
au InsertEnter * call InsertStatuslineColor(v:insertmode)
endif
set statusline=%n:\ [%l/%L,%v][%p%%]\ %f%m%r%h%w\ [%Y,%{&fileencoding},%{&fileformat}]
". Enable the ruler with the format:
"{buffer number}{modified/readonly flag}: {file type} [current line, current column] {position percentage in file}
set ruler
set rulerformat=%25(%n%m%r:\ %Y\ [%l,%v]\ %p%%%)
". }=-
". Indenting and Width -={
set autoindent
set copyindent
set smarttab
set backspace=indent,eol,start
set shiftround " use multiple of shiftwidth when indenting with '<' and '>'
". The 4 whitespace settings
". Indentation via `Tab' and `Backspace' in insert mode
". Indentation via `<' and `>' in normal mode
set expandtab " causes space to be used instead of tabs
set tabstop=4 " width of a tab character
set shiftwidth=4 " number of spaces to use for autoindenting in normal mode
set softtabstop=4 " fine-tunes the amount of whitespace to be inserted or remove
" via backspace in insert mode
set nowrap
". Navigation
" Allow specified keys that move the cursor left/right to move to the previous/
" next line when the cursor is on the first/last character in the line.
" b (backspace), s (space) and the arrows.
set whichwrap=b,s,<,>
". }=-
". Special Comments -={
hi nimaComment ctermfg=cyan guifg=cyan
hi specialComment ctermfg=red guifg=red
" }=-
". Over-rides for certain filetypes -={
if has("autocmd")
". TXT
"autocmd BufRead *.txt set tw=78
". Git
autocmd FileType gitcommit set textwidth=70
". MIB
autocmd Syntax mib setl sw=2 sts=2 et
". Ruby
autocmd FileType ruby setl sw=2 sts=2 et
autocmd FileType ruby syn match specialComment /#! .*/
autocmd FileType ruby syn match nimaComment /#\. .*/
". JavaScript
autocmd FileType javascript setl sw=2 sts=2 et
autocmd FileType javascript syn match specialComment /\/\/! .*/
autocmd FileType javascript syn match nimaComment /\/\/\. .*/
". Perl
autocmd FileType perl syn match specialComment /#! .*/
autocmd FileType perl syn match nimaComment /#\. .*/
". Python
autocmd FileType python setl nosmartindent
autocmd FileType python syn match specialComment /#! .*/
autocmd FileType python syn match nimaComment /#\. .*/
". Puppet
autocmd FileType puppet setl sw=2 sts=2 et
autocmd FileType puppet syn match specialComment /#! .*/
autocmd FileType puppet syn match nimaComment /#\. .*/
". Make
" in makefiles, don't expand tabs to spaces, since actual tab characters are
" needed, arend have indentation at 8 chars to be sure that all indents are
" tabs.
autocmd FileType make set noexpandtab shiftwidth=8 tabstop=8 smarttab
autocmd FileType make syn match specialComment /#! .*/
autocmd FileType make syn match nimaComment /#\. .*/
". Bash
function! BashSyntax()
if &ft == "bash"
let b:is_bash=1
set ft=sh
endif
map! fnfn function{;}<ESC>2ba
autocmd FileType sh syn match specialComment /#! .*/
autocmd FileType sh syn match nimaComment /#\. .*/
endfunction
autocmd FileType * call BashSyntax()
". Diff
au FilterWritePost * if &diff | nmap <F5> :diffupdate<CR> | endif
"au FilterWritePost * if &diff | set t_Co=256 | set bg=dark | colorscheme solarized | else | exe "colorscheme ".colortheme | endif
"au BufWinLeave * exe "colorscheme ".colortheme
". C
let c_cpp_comments = 0
autocmd FileType c syn match nimaComment #//\. .*#
autocmd FileType c syn match specialComment #//! .*#
autocmd Syntax * call SyntaxRange#Include('/\* lang:c \*/', '/\* lang:c \*/', 'c', 'NonText')
". JSON
autocmd Syntax * call SyntaxRange#Include('/\* lang:js \*/', '/\* lang:js \*/', 'javascript', 'NonText')
". SML
"autocmd Syntax * call SyntaxRange#Include('lang:sml', 'lang:sml', 'sml', 'NonText')
set so=1024
autocmd VimEnter * set so=16
endif
". }=-
". Folding -={
let b:folded = 0
function! ToggleFold()
if(b:folded == 0)
exec "normal! zM"
let b:folded = 1
else
exec "normal! zR"
let b:folded = 0
endif
endfunction
if version >= 640
set foldenable
set foldminlines=2
set foldlevel=1 " Folds with a higher level will be automatically closed.
set foldopen= " Don't auto-open folds
"set foldmethod=indent " Make folding indent sensitive
set foldmethod=marker
set foldmarker=-={,}=-
endif
hi Folded ctermfg=010
function! MarkdownFoldText()
let nl = v:foldend - v:foldstart + 1
let nlp = 100 * nl / line('$')
let line = getline(v:foldstart)
let sub = substitute(line, ' *-[x]{0}={', ' ', 'g')
return sub . v:folddashes . '[ ' . nl . '/' . line('$') . ', ' . nlp . '% ]'
endfunction
setlocal foldtext=MarkdownFoldText()
". }=-
". Copy/Paste -={
set clipboard=unnamed
if version >= 640
fun! CopyPasteToggle()
if !exists("b:cpt") || !b:cpt
let b:cpt = 1
set nonu wrap paste foldcolumn=0
else
let b:cpt = 0
set nu nowrap nopaste foldcolumn=4
endif
endfunction
set nu nowrap nopaste foldcolumn=4
endif
". }=-
". Windows -={
if bufwinnr(1)
map <leader><kPlus> <C-W>+
map <leader><kMinus> <C-W>-
map <leader><kDivide> <c-w><
map <leader><kMultiply> <c-w>>
nmap <silent> <A-Up> :wincmd k<CR>
nmap <silent> <A-Down> :wincmd j<CR>
nmap <silent> <A-Left> :wincmd h<CR>
nmap <silent> <A-Right> :wincmd l<CR>
endif
". }=-
". Common Task Speed-Dials -={
map <silent> <C-c> :qall<CR>
map <silent> <space><space><space> :nohlsearch<CR>:echo<CR>
map <silent> <F2> :w<CR>
map! <silent> <F2> <ESC>:w<CR>
inoremap <silent> <F3> <ESC>mq<S-Insert>'qa
nnoremap <silent> <F3> mq<S-Insert>'q
"inoremap <silent> <C-i> <Insert>
"nnoremap <silent> <C-i> <Insert>
set pastetoggle=<F4>
nnoremap <silent> <F4> :call CopyPasteToggle()<CR>
map <silent> <F5> :source $MYVIMRC<CR>
". Folds
map <silent> <F6> :call ToggleFold()<CR>
map ; za
". Tabularized -={
nmap <F7><bar> :Tabularize /<bar><CR>
vmap <F7><bar> :Tabularize /<bar><CR>
nmap <F7>3 :Tabularize /#.<CR>
vmap <F7>3 :Tabularize /#.<CR>
nmap <F7>= :Tabularize /=<CR>
vmap <F7>= :Tabularize /=<CR>
nmap <F7>> :Tabularize /=><CR>
vmap <F7>> :Tabularize /=><CR>
nmap <F7>: :Tabularize /:\zs<CR>
vmap <F7>: :Tabularize /:\zs<CR>
". }=-
map <silent> <F8> :set ignorecase! ignorecase?<CR>
map <silent> <F9> :call ListToggle()<CR>
map <silent> <F10> :%s/ *$//<CR>:nohlsearch<CR>``zz<space><space><space>
nnoremap <silent> <F11> :call <SID>ToggleColorColumn()<cr>
inoremap <silent> <F11> <ESC>:call <SID>ToggleColorColumn()<cr>a
". }=-
". Powerline -={
let Powerline_symbols = 'fancy'
set rtp+=/srv/github/powerline/powerline/bindings/vim/
set laststatus=2
set t_Co=256
". }=-
function! YuiDocstr()
r~/vim/yuish/docstr.sh
endfunction
nmap ^Y :call YuiDocstr()<CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment