Skip to content

Instantly share code, notes, and snippets.

@c0psrul3
Last active March 12, 2018 11:40
Show Gist options
  • Save c0psrul3/b73f28f15bd5459fa462bb1f1b4a37eb to your computer and use it in GitHub Desktop.
Save c0psrul3/b73f28f15bd5459fa462bb1f1b4a37eb to your computer and use it in GitHub Desktop.
vimrc with dein
" /* vim: set filetype=vim : */
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" When started as "evim", evim.vim will already have done these settings.
if v:progname =~? "evim"
finish
else
" Vim >= 5.0 support syntax highlighting. This line enables it by default.
syntax on
endif
" Source a global configuration file if available
if filereadable("/etc/vim/vimrc.local")
source /etc/vim/vimrc.local
endif
" This line should not be removed as it ensures that various options are
" properly set to work with the Vim-related packages available in FreeBSD.
" make changes after sourcing freebsd.vim since it alters the value of the
"runtime! freebsd.vim
set compatible
if has('python3')
let g:powerline_pycmd = 'py3'
endif
"" Set the leader key
let mapleader = '\'
let maplocalleader = '\'
"" Source viminit files
runtime! config/**/*.vim
"" List of directory names for the swap file, separated with commas.
silent !mkdir -vp ~/.vim/tmp/undo/ > /dev/null 2>&1
"" - The [swap file] will be created in the first directory where possible.
setlocal directory=~/tmp/vim,~/.vim/tmp
"" keep an undo file (undo changes after closing)
setlocal undodir=~/tmp/vim/undo,~/tmp/vim,~/.vim/tmp
"" keep a backup file (restore to previous version)
setlocal backupdir=~/tmp/vim/backup,~/tmp/vim,~/.vim/tmp
"" Exceptions for backup file situations
if has("vms")
setlocal nobackup " do not keep a backup file, use versions instead
setlocal nowritebackup " dont want a backup file while editing
else
"" Auto save before commands like :next or :make
setlocal undofile backup autowrite
endif
"" Allow backspacing over everything in insert mode
set backspace=indent,eol,start
set history=500 " keep xxx lines of command line history
set ruler " show the cursor position all the time
set showcmd " display incomplete commands
"" use capital P for pasting from system clip board
map P "+p
map vp "+p
"" Don't use Ex mode, use Q for formatting
map Q gq
"" CTRL-U in insert mode deletes a lot. Use CTRL-G u to first break undo,
"" so that you can undo CTRL-U after inserting a line break.
inoremap <C-U> <C-G>u<C-U>
"" In many terminal emulators the mouse works just fine, thus enable it.
if has('mouse')
set mouse=n
endif
"" Set the mouse to not be used, I think I prefer it that way.
set mouse=
if ! has('gui_running') "&& $TERM =~# 'xterm-256color'
""Instantly leave insert mode when pressing <Esc> {{{
set ttimeoutlen=10
augroup FastEscape
autocmd!
au InsertEnter * set timeoutlen=0
au InsertLeave * set timeoutlen=1000
augroup END
""Change cursor color in insert mode
"let &t_SI = '50;CustomCursorColor=#89b6e2;BlinkingCursorEnabled=true^G'
"let &t_EI = '50;CustomCursorColor=#dd4010;BlinkingCursorEnabled=false^G'
""Use custom fillchars/listchars/showbreak icons {{{
""Show trailing whitepace and spaces before a tab:
autocmd Syntax * syn match ExtraWhitespace /\s\+$\| \+\ze\t/
set fillchars=vert:│,fold:┄,diff:╱
"" Replace (irregular) whitespace for special chars
""set listchars=tab:⋮\ ,trail:·,eol:·,precedes:◂,extends:▸
""set listchars=tab:»·,trail:·,eol:¶
set listchars=tab:»⋯,space:◆,trail:⌴,eol:¶,precedes:◂,extends:▸
"set listchars=tab:»·,space:·,trail:⌴,eol:¶,precedes:◂,extends:▸
set showbreak=↪
"" Replace/substitute Carriage Return (CR) with Line Feed (LF)
"" Vim Help: {{ :help ++opt }} or {{ :help 'fileformat' }}
"" Vim Tips: [[http://vim.wikia.com/wiki/VimTip1266]]
":s/\r/\r/gc "" Substitute CR with LF {\n}
":s/<C-v><C-m>/\r/gc
":s/0x130x10/0x10/g "" Substitute CRLF with LF (ref. ascii codes)
"" [[http://www.theasciicode.com.ar/ascii-control-characters/line-feed-ascii-code-10.html]]
"yl # yank one character into unnamed buffer
"/<C-R><C-R>" # pull unnamed buffer contents onto search (that's two presses of Control-R)
"" [[http://vim.wikia.com/wiki/Search_for_non-ASCII_characters]]
set fileformats=unix "" Declare allowed file formats.
"set ffs=unix,dos,mac "" Default 'fileformats'
"autocmd BufWrite * :set ff=unix "" convert upon write file
""`tr '\015 '\012' <${infile} >${outfile}` "" Shell Command
endif
filetype plugin on "" Enable file type detection.
"" augroup filetypedetect " Moved to ./ftdetect/<ext>.vim
"" These examples should go in individual files,i.e.: "$VIM/ftdetect/<ext>.vim"
""| au! BufRead,BufNewFile *.csv,*.dat,*.map setfiletype csv
""| au! BufRead,BufNewFile *.csv,*.dat,*.map set ft=csv
""| au! BufRead,BufNewFile *.vimrc setfiletype vim ""?? 'setfiletype ' or 'set filetype='
""| au! BufRead,BufNewFile *.vimrc set filetype=vim
""| augroup END
augroup vimrc
au BufReadPre * setlocal foldmethod=manual " indent syntax expr marker diff
"| " Powershell
"| au BufNewFile,BufRead *.ps1,*.psc1 setf ps1
"| au BufReadPre * setlocal foldmethod=manual " indent syntax expr marker diff
" map <F8> :set foldmethod=indent!<CR>
" When editing a file, always jump to the last known cursor position.
" Don't do it when the position is invalid or when inside an event handler
" (happens when dropping a file on gvim).
" Also don't do it when the mark is in the first line, that is the default
" position when opening a file.
au BufReadPost *
\ if line("'\"") > 1 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
augroup END
"TODO unless nowrap
augroup AutoIndentation
set smartindent " shorthand: set ai noai
"" 2xSpace indentation, Tabs=2xSpace, Tab Key inserts 2xSpace
set shiftwidth=2 tabstop=4 softtabstop=2 expandtab
"" For all text files set 'textwidth' to 78 characters.
autocmd FileType text,markdown
\ setlocal textwidth=78 columns=100
autocmd FileType c,asm,python
\ setlocal shiftwidth=4 tabstop=4 expandtab
\ foldmethod=indent autoindent
"" Highlighting for syslog +log files
au BufRead,BufNewFile {*.cfg,*.profile,*.log} set ft=syslog
au BufRead,BufNewFile {*.bashrc,*.*rc,*.bash_*,*.profile} set ft=sh
"" The line will be broken in the middle of a word if necessary.
"" Use 'nolinebreak' to prevent insertion of <eol> when wrap length, or
"" wrapmargin the break at a word boundary.b
set nowrap nolinebreak
"" Map kbd-shortcut for [no]fold, [no]wrap, [no]linebreak
nmap <silent> <leader>F :set foldenable! foldenable?<CR>
nmap <silent> <leader>w :set wrap! wrap?<CR>
nmap <silent> <leader>W :set linebreak! linebreak?<CR>
augroup END
set expandtab "" Always expand tabs -- WE WANT SPACES! {{{
""TODO configure Backup and Undo Files (use ~/.vim/tmp, ~/tmp, /tmp/$USER/vim/,[etc...]
" Backups and versioning ("undo" files)
"set autowrite " Auto save before commands like :next or :make
"set backupdir=~/.vim/tmp,/tmp,.
"set directory=.,~/.vim/tmp,/tmp,.
"" The following are commented out as they cause vim to behave a lot
"" differently from regular Vi.
set showcmd " Show (partial) command in status line.
set showmatch " Show matching brackets.
"set ignorecase " Do case insensitive matching
set smartcase " Do smart case matching
set incsearch " Incremental search jumps to the found string.
set hlsearch " Search Hilighting
set hidden " Hide buffers when they are abandoned
"set mouse=a " Enable mouse usage (all modes)
set number
"set columns=100 " this should be set automatically (fluid window with)
"set textwidth=80 " show a vertical line at the 79th character
set cursorline " highlight the current line (row)
set cursorcolumn " highlight the current column
set splitright
set guioptions-=T " turn off GUI toolbar (icons)
set guioptions-=r " turn off GUI right scrollbar
set guioptions-=L " turn off GUI left scrollbar
set winaltkeys=no " turn off stupid fucking alt shortcuts
set laststatus=2 " always show status bar
set t_Co=256 " 256 colors in terminal
set scrolloff=3 " we keep 3 lines when scrolling
set shell=/usr/bin/zsh
if has('gui_running')
"set guifont=Ubuntu\ Mono\ 11
endif
colorscheme molokai
if has('gui_running')
colorscheme elflord
endif
set background=dark " set background to influence the colorscheme
"" Override some highlight settings (turn off stupid italics in Molokai)
highlight ColorColumn ctermbg=235 guibg=#2c2d27
highlight CursorLine ctermbg=235 guibg=#2c2d27
highlight CursorColumn ctermbg=235 guibg=#2c2d27
highlight DiffText gui=none
highlight Macro gui=none
highlight SpecialKey gui=none
highlight Special gui=none
highlight StorageClass gui=none
highlight Tag gui=none
""=====[ Turn On and Off Search Highlighting ]=================================
set hlsearch
noremap <silent> <F4> :set hlsearch! hlsearch?<CR>
noremap <silent> <CR> :nohlsearch<CR>
" While in 'insert mode', search hilighting should be hidden
autocmd InsertEnter * :setlocal nohlsearch
autocmd InsertLeave * :setlocal hlsearch
"TODO: modify this next block to only happen if (hlsearch == *on*)
""=====[ Highlight matches when jumping to next ]==============================
"" This rewires n and N to do the highlighing...
nnoremap <silent> n n:call HLNext(0.4)<cr>
nnoremap <silent> N N:call HLNext(0.4)<cr>
" Now, just highlight the match in red...
function! HLNext (blinktime)
let [bufnum, lnum, col, off] = getpos('.')
let matchlen = strlen(matchstr(strpart(getline('.'),col-1),@/))
let target_pat = '\c\%#'.@/
let ring = matchadd('Error', target_pat, 101)
redraw
exec 'sleep ' . float2nr(a:blinktime * 500) . 'm'
call matchdelete(ring)
redraw
endfunction
""=====[ Turn On and Off Search Highlighting ]==================================
noremap <silent> <F4> :set hlsearch! hlsearch?<CR>
noremap <silent> <CR> :nohlsearch<CR>
" While in 'insert mode', search hilighting should be hidden
autocmd InsertEnter * :setlocal nohlsearch
autocmd InsertLeave * :setlocal hlsearch
""=====[ Highlight Right Column at defined value, '80' ]=======================
if exists('+ColorColumn')
" Highlight the 80th column : In Vim >= 7.3, also highlight columns 120+
" (I picked 120-320 because you have to provide an upper bound and 320 just
" covers a 1080p GVim window in Ubuntu Mono 11 font.)
let &ColorColumn="80,".join(range(120,320),",")
else
" fallback for Vim < v7.3
autocmd BufWinEnter * let w:m2=matchadd('ErrorMsg', '\%>80v.\+', -1)
endif
""====[ Smart way to move between panes ]====================================== "" ((code-illustration showing two methods)) "" While in command mode, enable arrow keys to navigate panes.
"" While in command mode, enable arrow keys to navigate panes.
vnoremap p <Esc>:let current_reg = @"<CR>gvdi<C-R>=current_reg<CR><Esc>
""====[ Use ctrl-[hjkl] to select the active split! ]==========================
nmap <silent> <C-k> :wincmd k<CR>
nmap <silent> <C-j> :wincmd j<CR>
nmap <silent> <C-h> :wincmd h<CR>
nmap <silent> <C-l> :wincmd l<CR>
""====[ Jump to end and beginning of line ]=====================================
nmap <silent> <S-h> ^
nmap H ^
nmap <silent> <S-l> $
nmap L $
nmap <silent> <S-k> 10k
nmap <silent> <S-j> 10j
""====[ Resize / Move window borders ]==========================================
nmap <silent> <S-LEFT> :wincmd ><CR>
nmap <silent> <S-RIGHT> :wincmd <<CR>
nmap <silent> <S-DOWN> :wincmd +<CR>
nmap <silent> <S-UP> :wincmd -<CR>
"nmap <silent> <S-l> :wincmd ><CR>
"nmap <silent> <S-h> :wincmd <<CR>
"nmap <silent> <S-k> :wincmd +<CR>
"nmap <silent> <S-j> :wincmd -<CR>
""====[ PageUp / PageDown act as I prefer. ]====================================
"map <PageUp> <C-U>
"map <PageDown> <C-D>
imap <PageUp> <C-O><C-U>
imap <PageDown> <C-O><C-D>
""====[ Macros:: simple whitespace manipulation ]==============================
nmap <leader>w :,$s/\s\+$//g<CR>
nmap <silent> <leader>s :,$s/\s\+$//g<CR>
""====[ Delete blank lines: ]===================================================
nmap <silent> <leader>D :g/^$/d<CR>
nmap <leader>G :g/^$/d<CR>
""====[ Diff _current_ buffer and original loaded file ]========================
"" Only define it when not defined already.
if !exists(":DiffOrig")
command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
\ | wincmd p | diffthis
endif
set diffopt=vertical,filler,context:3
"
" Macro to use git diff on current file name.
nmap <silent> <leader>gd :!git diff %<CR>
nmap <silent> <leader>G :!git diff %<CR>
""====[ LustyExplorer Settings Section ]=======================================
let g:LustyExplorerDefaultMappings = 0
let g:LustyJugglerSuppressRubyWarning = 1
let g:LustyExplorerSuppressRubyWarning = 1
""====[ YankRing Settings Section ]============================================
let g:yankring_enabled = 1
let g:yankring_persist = 1
"" YankRing History (file and stack size)
let g:yankring_history_dir = expand('$HOME/.vim/tmp')
let g:yankring_history_file = 'YankRing.history'
let g:yankring_max_history = 100
let g:yankring_max_element_length = 4194304 " 4M
let g:yankring_share_between_instances = 1
let g:yankring_clipboard_monitor = 1
"" The following are the default mappings:
nnoremap yy :<C-U>YRYankCount 'yy'<CR>
nnoremap dd :<C-U>YRYankCount 'dd'<CR>
nnoremap yw :<C-U>YRYankCount 'yw'<CR>
nnoremap dw :<C-U>YRYankCount 'dw'<CR>
nnoremap ye :<C-U>YRYankCount 'ye'<CR>
nnoremap de :<C-U>YRYankCount 'de'<CR>
nnoremap yiw :<C-U>YRYankCount 'yiw'<CR>
nnoremap diw :<C-U>YRYankCount 'diw'<CR>
nnoremap Y :<C-U>YRYankCount 'Y'<CR>
nnoremap D :<C-U>YRYankCount 'D'<CR>
nnoremap y$ :<C-U>YRYankCount 'y$'<CR>
nnoremap d$ :<C-U>YRYankCount 'd$'<CR>
nnoremap yG :<C-U>YRYankCount 'yG'<CR>
nnoremap dG :<C-U>YRYankCount 'dG'<CR>
""====[ Setup some 1-key shortcuts (F-keys are useless anyway) ]===============
nmap <Esc><Esc><Esc><Esc><Esc> :wq<CR>
nmap <silent> <leader><C-W> :close<CR>
nmap <silent> <leader>q :close<CR>
nmap <silent> <C-S> :split<CR>
"nmap <silent> <C-F> :Unite file<CR>
let g:fuf_keyOpenTabpage = '<CR>'
nmap <silent> <C-f> :FufFile<CR>
nmap <silent> <C-o> :FufFile<CR>
"nmap <silent> <C-B> :FufBuffer<CR>
nmap <silent> <Esc><Esc><CR> :FufDir<CR>
nmap <silent> <leader>f :FufFileWithCurrentBufferDir<CR>
nmap <silent> <leader>F :FufFile<CR>
nmap <silent> <leader>d :FufDirWithCurrentBufferDir<CR>
nmap <silent> <leader>D :FufDir<CR>
nmap <silent> <leader>b :FufBuffer<CR>
nmap <silent> <leader>g :NERDTreeFind<CR>
nmap <silent> <Esc><F1> :NERDTreeToggle<CR>
nmap <silent> <F1> :NERDTreeCWD<CR>
nmap <silent> <F2> :FufFile<CR>
nmap <silent> <F3> :set list! list?<CR>
nmap <silent> <leader>a :set list! list?<CR>
"" Map kbd-shortcut for alternating between wrap and linebreaks
nmap <silent> <F4> :set linebreak! linebreak? wrap! wrap?<CR>
nmap <silent> <leader>w :set wrap! wrap?<CR>
"nmap <silent> <leader>lb :set linebreak! linebreak?<CR>
"nmap <silent> <leader>W :set linebreak! linebreak? wrap! wrap?<CR>
nmap <silent> <F5> :set wrap! linebreak! wrap? linebreak?<CR>
"" Folding Method
nmap <silent> <C-F5> :set foldenable! foldenable?<CR>
nmap <silent> <F6> :set foldenable! foldenable?<CR>
"" Save and lint php code
"nmap <silent> <F6> :w !php -l<CR>
nmap <silent> <F7> :w !pylint -l<CR>
nmap <silent> <F8> :LustyFilesystemExplorer<CR>
nmap <silent> <F9> :LustyBufferExplorer<CR>
"nmap <silent> <F10>
"nmap <silent> <F11>
nmap <silent> <leader>v :YRShow<CR>
nmap <silent> <F12> :YRShow<CR>
""====[]========================================================================
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" /* vim: set filetype=vim : */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment