Skip to content

Instantly share code, notes, and snippets.

@xcv58
Last active December 25, 2015 16:49
Show Gist options
  • Save xcv58/7008706 to your computer and use it in GitHub Desktop.
Save xcv58/7008706 to your computer and use it in GitHub Desktop.
Vim tips. For details I found in daily use.
set fileencoding=utf-8
"this line causes the long long latency for opening lagre file.
"set fileencodings=utf-8,ucs-bom,cp936,gb18030,utf-16,big5,gbk,ucs-bom,cp936,latin1
"for vim-latex
"only for tex files. three <leader> to write and compile. view is reserved.
autocmd FileType tex map <leader><leader><leader> :w<cr><plug>Tex_Compile
"<plug>Tex_View
"C-L to automatically add \left and \right. Because <Alt+L> will key in special symbol.
autocmd FileType tex imap <C-L> <plug>Tex_LeftRight
"auto save/read position and fold info
"not work for largefile, which is large than 10MB
"autocmd BufWinLeave *.* mkview!
"autocmd BufWinEnter *.* silent loadview
let g:LargeFile = 1024 * 1024 * 30
"let g:LargeFile = 1024 * 1024 * 10
let g:skipview_files = [
\ '[EXAMPLE PLUGIN BUFFER]'
\ ]
function! MakeViewCheck()
if has('quickfix') && &buftype =~ 'nofile'
" Buffer is marked as not a file
return 0
endif
if empty(glob(expand('%:p')))
" File does not exist on disk
return 0
endif
if len($TEMP) && expand('%:p:h') == $TEMP
" We're in a temp dir
return 0
endif
if len($TMP) && expand('%:p:h') == $TMP
" Also in temp dir
return 0
endif
if index(g:skipview_files, expand('%')) >= 0
" File is in skip list
return 0
endif
" autocmd BufReadPre * let f=expand("<afile>") |
if getfsize(expand("<afile>")) > g:LargeFile
" File is too large
return 0
endif
return 1
endfunction
augroup vimrcAutoView
autocmd!
" Autosave & Load Views.
autocmd BufWritePost,BufLeave,WinLeave,BufWinLeave ?* if MakeViewCheck() | mkview | endif
autocmd BufWinEnter ?* if MakeViewCheck() | silent loadview | syntax on | else | syntax off | endif
augroup end
"Big thanks for manalive. http://vim.wikia.com/wiki/Make_views_automatic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment