Skip to content

Instantly share code, notes, and snippets.

@jackywyz
Last active December 14, 2021 07:27
Show Gist options
  • Save jackywyz/3057503 to your computer and use it in GitHub Desktop.
Save jackywyz/3057503 to your computer and use it in GitHub Desktop.
vim tips
# ~/.gitconfig: git-config(1) - Git configuration
# vim: ft=gitconfig
[apply]
# Detect whitespace errors when applying a patch
whitespace = fix
[interactive]
diffFilter = diffr
[core]
# Use custom `.gitignore` and `.gitattributes`
#pager = diffr | less -R
pager = delta
excludesfile = ~/.gitignore
attributesfile = ~/.gitattributes
# Treat spaces before tabs, lines that are indented with 8 or more spaces, and all kinds of trailing whitespace as an error
whitespace = space-before-tab,indent-with-non-tab,trailing-space
[alias]
a = add .
ci = commit -m
co = checkout
st = status
br = branch
di = diff
dc = diff --cached
unstage = reset HEAD
lg = log --oneline --decorate
tg = log --oneline --decorate --graph
ls = ls-files
sg = diff --cached
stat = diff --stat
bra = branch -a -v
statg = diff --cached --stat
amend = commit --amend
mend = commit --amend --reuse-message HEAD
undo = reset --soft HEAD^
remaster = rebase --autosquash -i master
local = log --oneline origin/master..HEAD
export = !touch $(git rev-parse --git-dir)/git-daemon-export-ok
unexport = !rm -v $(git rev-parse --git-dir)/git-daemon-export-ok
mrproper = !git reset --hard HEAD && git clean -fdx
empty = !git init && git commit --allow-empty -m Initial
[color]
branch = auto
diff = auto
status = auto
ui = auto
interactive = auto
[format]
pretty = %Cblue%h%Creset %Cgreen[%ar]%Creset (%an) %s
[color "branch"]
current = yellow reverse
local = yellow
remote = green
[color "diff"]
meta = yellow bold
frag = magenta
plain = white bold
old = red bold
new = green bold
commit = yellow bold
func = green dim
[color "status"]
added = yellow
changed = green
untracked = cyan
[color "grep"]
filename = magenta
linenumber = green
[credential]
helper = cache --timeout=36000
[diff]
renames = copies
[grep]
lineNumber = true
extendedRegexp = true
[merge]
defaultToUpstream = true
tool = vimdiff
[push]
#default = upstream
default = current
# External programs
[tig]
show-date = relative
show-author = abbreviated
author-width = 10
line-graphics = true
tab-size = 4
[tig "bind"]
# noop on unrecognized escape sequences
main = ~ none
[tig "color"]
cursor = black green
title-focus = white blue
# URL replacements
[url "ssh://"]
pushInsteadOf = git://
[url "git://panther.nathan7.eu/~grawity/pub/git/"]
#insteadOf = nullroute:
[url "ssh://panther.nathan7.eu/~grawity/pub/git/"]
insteadOf = nullroute+ssh:
insteadOf = nullroute:
pushInsteadOf = nullroute:
[url "git://anongit.freedesktop.org/"]
insteadOf = freedesktop:
insteadOf = fdo:
[url "git://gist.github.com/"]
insteadOf = gist:
insteadOf = https://gist.github.com/
[url "[email protected]:"]
insteadOf = gist+ssh:
pushInsteadOf = git://gist.github.com/
pushInsteadOf = gist:
pushInsteadOf = https://gist.github.com/
[url "git://github.com/"]
insteadOf = github:
insteadOf = gh:
insteadOf = https://github.com/
[url "[email protected]:"]
insteadOf = github+ssh:
insteadOf = gh+ssh:
pushInsteadOf = git://github.com/
pushInsteadOf = github:
pushInsteadOf = gh:
pushInsteadOf = https://github.com/
[url "git://git.gnome.org/"]
insteadOf = gnome:
[url "git://bitbucket.org:"]
insteadOf = bb:
[url "git://git.sv.gnu.org/"]
insteadOf = gnu:
[url "git://anongit.kde.org/"]
insteadOf = kde:
[url "git://git.kernel.org/pub/scm/linux/kernel/git/"]
insteadOf = linux:
[include]
path = .gitconfig-local
set nocompatible
source ~/.vim/plugins.vim
filetype on " Enable filetype detection
filetype indent on " Enable filetype-specific indenting
filetype plugin on " Enable filetype-specific plugins
filetype plugin indent on " Automatically detect file types.
syntax on
set nu
set autoindent
set ic
set hls
set lbr
colorscheme delek
" auto reload vimrc when editing it
autocmd! bufwritepost .vimrc source ~/.vimrc
set hlsearch " search highlighting
if has("gui_running") " GUI color and font settings
set t_Co=256 " 256 color mode
set cursorline " highlight current line
"colors moria
endif
set clipboard=unnamed " yank to the system register (*) by default
set showmatch " Cursor shows matching ) and }
set showmode " Show current mode
set wildchar=<TAB> " start wild expansion in the command line using <TAB>
set wildmenu " wild char completion menu
" ignore these files while expanding wild chars
set wildignore=*.o,*.class,*.pyc
set autoindent " auto indentation
set incsearch " incremental search
set nobackup " no *~ backup files
set copyindent " copy the previous indentation on autoindenting
set ignorecase " ignore case when searching
set smartcase " ignore case if search pattern is all lowercase,case-sensitive otherwise
set smarttab " insert tabs on the start of a line according to context
" disable sound on errors
set noerrorbells
set novisualbell
set t_vb=
set tm=500
" TAB setting{
set expandtab "replace <TAB> with spaces
set softtabstop=3
set shiftwidth=3
au FileType Makefile set noexpandtab
"}
" status line {
set laststatus=2
set statusline=\ %{HasPaste()}%<%-15.25(%f%)%m%r%h\ %w\ \
set statusline+=\ \ \ [%{&ff}/%Y]
set statusline+=\ \ \ %<%20.30(%{hostname()}:%{CurDir()}%)\
set statusline+=%=%-10.(%l,%c%V%)\ %p%%/%L
function! CurDir()
let curdir = substitute(getcwd(), $HOME, "~", "")
return curdir
endfunction
function! HasPaste()
if &paste
return '[PASTE]'
else
return ''
endif
endfunction
"}
" C/C++ specific settings
autocmd FileType c,cpp,cc set cindent comments=sr:/*,mb:*,el:*/,:// cino=>s,e0,n0,f0,{0,}0,^-1s,:0,=s,g0,h1s,p2,t0,+2,(2,)20,*30
"Restore cursor to file position in previous editing session
set viminfo='10,\"100,:20,%,n~/.viminfo
au BufReadPost * if line("'\"") > 0|if line("'\"") <= line("$")|exe("norm '\"")|else|exe "norm $"|endif|endif
"---------------------------------------------------------------------------
" Tip #382: Search for <cword> and replace with input() in all open buffers
"---------------------------------------------------------------------------
fun! Replace()
let s:word = input("Replace " . expand('<cword>') . " with:")
:exe 'bufdo! %s/\<' . expand('<cword>') . '\>/' . s:word . '/ge'
:unlet! s:word
endfun
"---------------------------------------------------------------------------
" USEFUL SHORTCUTS
"---------------------------------------------------------------------------
" set leader to ,
let mapleader=","
let g:mapleader=","
"replace the current word in all opened buffers
map <leader>r :call Replace()<CR>
" open the error console
map <leader>bc :botright cope<CR>
" move to next error
map <leader>] :cn<CR>
" move to the prev error
map <leader>[ :cp<CR>
" --- move around splits {
" move to and maximize the below split
map <C-J> <C-W>j<C-W>_
" move to and maximize the above split
map <C-K> <C-W>k<C-W>_
" move to and maximize the left split
nmap <c-h> <c-w>h<c-w><bar>
" move to and maximize the right split
nmap <c-l> <c-w>l<c-w><bar>
set wmw=0 " set the min width of a window to 0 so we can maximize others
set wmh=0 " set the min height of a window to 0 so we can maximize others
" }
" move around tabs. conflict with the original screen top/bottom
" comment them out if you want the original H/L
" go to prev tab
map <S-H> gT
" go to next tab
map <S-L> gt
" new tab
map <C-t><C-t> :tabnew<CR>
" close tab
map <C-t><C-w> :tabclose<CR>
" ,/ turn off search highlighting
nmap <leader>/ :nohl<CR>
" Bash like keys for the command line
cnoremap <C-A> <Home>
cnoremap <C-E> <End>
cnoremap <C-K> <C-U>
" ,p toggles paste mode
nmap <leader>p :set paste!<BAR>set paste?<CR>
" allow multiple indentation/deindentation in visual mode
vnoremap < <gv
vnoremap > >gv
" :cd. change working directory to that of the current file
cmap cd. lcd %:p:h
" Writing Restructured Text (Sphinx Documentation) {
" Ctrl-u 1: underline Parts w/ #'s
noremap <C-u>1 yyPVr#yyjp
inoremap <C-u>1 <esc>yyPVr#yyjpA
" Ctrl-u 2: underline Chapters w/ *'s
noremap <C-u>2 yyPVr*yyjp
inoremap <C-u>2 <esc>yyPVr*yyjpA
" Ctrl-u 3: underline Section Level 1 w/ ='s
noremap <C-u>3 yypVr=
inoremap <C-u>3 <esc>yypVr=A
" Ctrl-u 4: underline Section Level 2 w/ -'s
noremap <C-u>4 yypVr-
inoremap <C-u>4 <esc>yypVr-A
" Ctrl-u 5: underline Section Level 3 w/ ^'s
noremap <C-u>5 yypVr^
inoremap <C-u>5 <esc>yypVr^A
"}
"---------------------------------------------------------------------------
" PROGRAMMING SHORTCUTS
"---------------------------------------------------------------------------
autocmd FileType javascript set dictionary=~/.vim/dict/javascript.dict
autocmd FileType scala set dictionary=~/.vim/dict/scala.dict
autocmd FileType java set dictionary=~/.vim/dict/java.dict
" Enable omni completion. (Ctrl-X Ctrl-O)
autocmd FileType html,markdown setlocal omnifunc=htmlcomplete#CompleteTags
autocmd FileType javascript setlocal omnifunc=javascriptcomplete#CompleteJS
autocmd FileType python setlocal omnifunc=pythoncomplete#Complete
autocmd FileType xml setlocal omnifunc=xmlcomplete#CompleteTags
autocmd FileType css set omnifunc=csscomplete#CompleteCSS
autocmd FileType c set omnifunc=ccomplete#Complete
autocmd FileType java setlocal omnifunc=javacomplete#Complete
autocmd FileType java setlocal completefunc=javacomplete#CompleteParamsInfo
" use syntax complete if nothing else available
if has("autocmd") && exists("+omnifunc")
autocmd Filetype *
\ if &omnifunc == "" |
\ setlocal omnifunc=syntaxcomplete#Complete |
\ endif
endif
" make CSS omnicompletion work for SASS and SCSS
autocmd BufNewFile,BufRead *.scss set ft=scss.css
autocmd BufNewFile,BufRead *.sass set ft=sass.css
""**************My config of the VIM***************************************
inoremap <c-l> <Right>
inoremap <c-k> <Up>
inoremap <c-j> <Down>
inoremap <c-h> <Left>
" TECHNICAL
set mouse=a
set encoding=utf-8
set fileencoding=utf-8
set termencoding=utf-8
set winaltkeys=no
nmap <Leader>s :w<CR>
nmap <a-s> :w<CR>
imap <a-s> <Esc><c-s>
autocmd BufRead *.java map <F5> :w<CR>:!clear <CR>:!javac % <CR>:!java %< <CR>
autocmd filetype python map <buffer> <F5> :w<CR>:!python %<CR>
autocmd filetype python imap <buffer> <F5> <Esc>:w<CR>:!python %<CR>
autocmd BufRead *.py set tabstop=4
autocmd BufRead *.py set nowrap
autocmd BufRead *.py set go+=b
"---------------------------------------------------------------------------
" PLUGIN SETTINGS
"---------------------------------------------------------------------------
" --- AutoClose - Inserts matching bracket, paren, brace or quote
"if !has("gui_running")
" imap OA <ESC>ki
" imap OB <ESC>ji
" imap OC <ESC>li
" imap OD <ESC>hi
"let g:AutoClosePreservDotReg=0
" nmap OA k
" nmap OB j
" nmap OC l
" nmap OD h
"endif
"let g:AutoClosePairs = {'(': ')', '{': '}', '[': ']', '"': '"', "'": "'"}
" --- SuperTab
let g:SuperTabRetainCompletionType=2
let g:SuperTabDefaultCompletionType="<C-X><C-O><C-P>"
"let g:SuperTabDefaultCompletionType="context"
set completeopt=menu
" --- Tlist
let Tlist_Show_One_File = 1
let Tlist_Use_Right_Window=1
let Tlist_Exit_OnlyWindow=1
nnoremap <silent> <Leader>tl :TlistToggle<CR>
nnoremap <silent> <Leader>tb :TagbarToggle<CR>
" --- NERDTree
noremap <Leader>n :NERDTree<space>
noremap <Leader>n. :execute "NERDTree ".expand("%:p:h")<cr>
noremap <Leader>nb :NERDTreeFromBookmark<space>
noremap <Leader>nn :NERDTreeToggle<cr>
noremap <Leader>no :NERDTreeToggle<space>
noremap <Leader>nf :NERDTreeFind<cr>
noremap <Leader>nc :NERDTreeClose<cr>
" --- ConqueTerm
autocmd BufRead *.py noremap <F4> :ConqueTermSplit python<CR>
autocmd BufRead *.scala noremap <F4> :ConqueTermSplit scala %<CR>
autocmd BufRead *.coffee noremap <F4> :ConqueTermSplit coffee %<CR>
noremap ,sh :ConqueTermSplit bash<CR>
let g:ConqueTerm_InsertOnEnter = 0 " Go straight to insert mode
let g:ConqueTerm_CWInsert = 0 " Allow C-w in insert mode
let g:ConqueTerm_ReadUnfocused = 1 " Read while unfocused too
let g:ConqueTerm_CloseOnEnd = 0
"------- ctags config
set tags=tags;
set autochdir
autocmd filetype java set tags+=/home/jacky/Soft/scala/jdk/jdk1.6/src/tags
autocmd filetype scala set tags+=/home/jacky/Soft/scala/scala/src/library-src/tags
autocmd filetype python set tags+=/home/jacky/Soft/python/Lib27/tags
noremap <Leader>cts :!ctags -R<cr>
"------------tagbar filetype-----
let g:tagbar_type_scala = {
\ 'ctagstype' : 'Scala',
\ 'kinds' : [
\ 'p:packages:1',
\ 'V:values',
\ 'v:variables',
\ 'T:types',
\ 't:traits',
\ 'o:objects',
\ 'a:aclasses',
\ 'c:classes',
\ 'r:cclasses',
\ 'm:methods'
\ ]
\ }
" ---------------
" Vundle
" ---------------
nmap <Leader>bi :BundleInstall<CR>
nmap <Leader>bu :BundleInstall!<CR> " Because this also updates
nmap <Leader>bc :BundleClean<CR>
" ---------------
" Fugitive
" ---------------
nmap <Leader>gc :Gcommit<CR>
nmap <Leader>gw :Gwrite<CR>
nmap <Leader>gs :Gstatus<CR>
nmap <Leader>gp :Git push<CR>
" Mnemonic, gu = Git Update
nmap <Leader>gu :Git pull<CR>
nmap <Leader>gd :Gdiff<CR>
" Exit a diff by closing the diff window
nmap <Leader>gx :wincmd h<CR>:q<CR>
"---------------------fuzzyfinder---
let g:fuf_modesDisable = [] " {{{
nnoremap <silent> <LocalLeader>h :FufHelp<CR>
nnoremap <silent> <LocalLeader>2 :FufFileWithCurrentBufferDir<CR>
nnoremap <silent> <LocalLeader>@ :FufFile<CR>
nnoremap <silent> <LocalLeader>3 :FufBuffer<CR>
nnoremap <silent> <LocalLeader>4 :FufDirWithCurrentBufferDir<CR>
nnoremap <silent> <LocalLeader>$ :FufDir<CR>
nnoremap <silent> <LocalLeader>5 :FufChangeList<CR>
nnoremap <silent> <LocalLeader>6 :FufMruFile<CR>
nnoremap <silent> <LocalLeader>7 :FufLine<CR>
nnoremap <silent> <LocalLeader>8 :FufBookmark<CR>
nnoremap <silent> <LocalLeader>* :FuzzyFinderAddBookmark<CR><CR>
nnoremap <silent> <LocalLeader>9 :FufTaggedFile<CR>
" " }}}
" Window Movement
" Here's a visual guide for moving between window splits.
" 4 Window Splits
" --------
" g1 | g2
" ---|----
" g3 | g4
" -------
"
" 6 Window Splits
" -------------
" g1 | gt | g2
" ---|----|----
" g3 | gb | g4
" -------------
nmap <silent> gh :wincmd h<CR>
nmap <silent> gj :wincmd j<CR>
nmap <silent> gk :wincmd k<CR>
nmap <silent> gl :wincmd l<CR>
" Upper left window
nmap <silent> g1 :wincmd t<CR>
" Upper right window
nmap <silent> g2 :wincmd b<Bar>:wincmd k<CR>
" Lower left window
nmap <silent> g3 :wincmd t<Bar>:wincmd j<CR>
" Lower right window
nmap <silent> g4 :wincmd b<CR>
" Top Middle
nmap <silent> gt g2<Bar>:wincmd h<CR>
" Bottom Middle
nmap <silent> gb g3<Bar>:wincmd l<CR>
" Previous Window
nmap <silent> gp :wincmd p<CR>
" Equal Size Windows
nmap <silent> g= :wincmd =<CR>
" Swap Windows
nmap <silent> gx :wincmd x<CR>
set nocompatible " be iMproved
filetype off " required!
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
" let Vundle manage Vundle
" required!
Bundle 'gmarik/vundle'
" My Bundles here:
"
" original repos on github
Bundle 'tpope/vim-fugitive'
Bundle 'Lokaltog/vim-easymotion'
Bundle 'rstacruz/sparkup', {'rtp': 'vim/'}
Bundle 'tpope/vim-rails.git'
Bundle 'scrooloose/nerdtree'
Bundle 'jiangmiao/auto-pairs'
Bundle 'scrooloose/nerdcommenter'
Bundle 'ervandew/supertab'
Bundle 'majutsushi/tagbar'
Bundle 'suan/vim-instant-markdown'
Bundle 'derekwyatt/vim-scala'
Bundle 'msanders/snipmate.vim'
Bundle 'derekwyatt/vim-sbt'
Bundle 'honza/snipmate-snippets'
Bundle 'kchmck/vim-coffee-script'
"" Bundle 'jackywyz/pydiction'
Bundle 'add20/vim-conque'
Bundle 'mattn/zencoding-vim'
" vim-scripts repos
Bundle 'L9'
Bundle 'FuzzyFinder'
Bundle 'taglist.vim'
Bundle 'javacomplete'
" non github repos
Bundle 'git://git.wincent.com/command-t.git'
"
" ...
filetype plugin indent on " required!
"
" Brief help
" :BundleList - list configured bundles
" :BundleInstall(!) - install(update) bundles
" :BundleSearch(!) foo - search(or refresh cache first) for foo
" :BundleClean(!) - confirm(or auto-approve) removal of unused bundles
"
" see :h vundle for more details or wiki for FAQ
"

###python supertab with omni invalid handle method Fork https://github.com/honza/snipmate-snippets and remove the mapping for the dot (Using the dot will not be possible anymore, to complete self). ###taglist must config the tags vim ~/.ctags

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment