Skip to content

Instantly share code, notes, and snippets.

@yyq
Last active July 4, 2018 08:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yyq/b701e781b00822fb41f271eef42c9767 to your computer and use it in GitHub Desktop.
Save yyq/b701e781b00822fb41f271eef42c9767 to your computer and use it in GitHub Desktop.
my vimrc file
" Use Vim settings, rather then Vi settings. This setting must be as early as
" possible, as it has side effects.
set nocompatible
if filereadable(expand("~/.vimrc.bundles"))
source ~/.vimrc.bundles
endif
" Highlight current line高亮光标的位置,横着的,竖着的
au WinLeave * set nocursorline nocursorcolumn
au WinEnter * set cursorline cursorcolumn
set cursorline cursorcolumn
" Leader 充分利用大拇指和空格键,效率提升
let mapleader = " "
set backspace=2 " Backspace deletes like most programs in insert mode
set nobackup
set nowritebackup
set noswapfile " http://robots.thoughtbot.com/post/18739402579/global-gitignore#comment-458413287
set history=1000
set ruler " show the cursor position all the time
set showcmd " display incomplete commands
set incsearch " do incremental searching
set laststatus=2 " Always display the status line
set autowrite " Automatically :write before running commands
set confirm " Need confrimation while exit
set fileencodings=utf-8,gb18030,gbk,big5
" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if (&t_Co > 2 || has("gui_running")) && !exists("syntax_on")
syntax on
endif
filetype plugin indent on
" NERDTree config
"nmap <leader>ne :NERDTree<CR>
map <silent> <C-n> :NERDTreeToggle<CR>
let NERDTreeShowHidden=1
let NERDChristmasTree=0
let NERDTreeWinSize=40
let NERDTreeChDirMode=2
let NERDTreeIgnore=['\~$', '\.pyc$', '\.swp$']
let NERDTreeShowBookmarks=1
let NERDTreeWinPos="left"
autocmd vimenter * if !argc() | NERDTree | endif " Automatically open a NERDTree if no files where specified
"autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif " Close vim if the only window left open is a NERDTree)"
augroup vimrcEx
autocmd!
" When editing a file, always jump to the last known cursor position.
" Don't do it for commit messages, when the position is invalid, or when
" inside an event handler (happens when dropping a file on gvim).
" autocmd BufReadPost *
" \ if &ft != 'gitcommit' && line("'\") > 0 && line("'\") <= line("$") |
" \ exe "normal g`\" |
" \ endif
" Cucumber navigation commands
autocmd User Rails Rnavcommand step features/step_definitions -glob=**/* -suffix=_steps.rb
autocmd User Rails Rnavcommand config config -glob=**/* -suffix=.rb -default=routes
" Set syntax highlighting for specific file types
autocmd BufRead,BufNewFile Appraisals set filetype=ruby
autocmd BufRead,BufNewFile *.md set filetype=markdown
" Enable spellchecking for Markdown
autocmd FileType markdown setlocal spell
" Automatically wrap at 80 characters for Markdown
autocmd BufRead,BufNewFile *.md setlocal textwidth=80
augroup END
" Softtabs, 2 spaces
set tabstop=2
set shiftwidth=2
set shiftround
set expandtab
" Display extra whitespace
set list listchars=tab:»·,trail:·
" Color scheme
colorscheme molokai
highlight NonText guibg=#060606
highlight Folded guibg=#0A0A0A guifg=#9090D0
" Make it obvious where 80 characters is
set colorcolumn=+1
" Numbers
set number
set numberwidth=5
" Tab completion
" will insert tab at beginning of line,
" will use completion if not at beginning
set wildmode=list:longest,list:full
function! InsertTabWrapper()
let col = col('.') - 1
if !col || getline('.')[col - 1] !~ '\k'
return "\<tab>"
else
return "\<c-p>"
endif
endfunction
inoremap <Tab> <c-r>=InsertTabWrapper()<cr>
inoremap <S-Tab> <c-n>
" Exclude Javascript files in :Rtags via rails.vim due to warnings when parsing
let g:Tlist_Ctags_Cmd="ctags --exclude='*.js'"
" Index ctags from any project, including those outside Rails
map <Leader>ct :!ctags -R .<CR>
" Switch between the last two files
nnoremap <leader><leader> <c-^>
" Get off my lawn
"nnoremap <Left> :echoe "Use h"<CR>
"nnoremap <Right> :echoe "Use l"<CR>
"nnoremap <Up> :echoe "Use k"<CR>
"nnoremap <Down> :echoe "Use j"<CR>
nnoremap <Left> 8h
nnoremap <Right> 8l
nnoremap <Up> 8k
nnoremap <Down> 8j
" Run commands that require an interactive shell
"
"nnoremap <Leader>r :RunInInteractiveShell<space>
" Treat <li> and <p> tags like the block tags they are
let g:html_indent_tags = 'li\|p'
" Open new split panes to right and bottom, which feels more natural
set splitbelow
set splitright
" This is quit all
noremap <Leader>q :q<cr>
" " key bindings for quickly moving between windows
" " h left, l right, k up, j down
noremap <leader>h <C-w>h
noremap <leader>l <C-w>l
noremap <leader>k <C-w>k
noremap <leader>j <C-w>j
" configure syntastic syntax checking to check on open as well as save
let g:syntastic_check_on_open=1
let g:syntastic_html_tidy_ignore_errors=[" proprietary attribute \"ng-"]
autocmd Syntax javascript set syntax=jquery " JQuery syntax support
set matchpairs+=<:>
set statusline+=%{fugitive#statusline()} " Git Hotness
" Tagbar
let g:tagbar_width=35
let g:tagbar_autofocus=1
"nmap <F6> :TagbarToggle<CR>
nmap <leader>tb :TagbarToggle<CR>
" Emmet
let g:user_emmet_mode='i' " enable for insert mode
" Search results high light
set hlsearch
" ignorecase and smartcase when searching
set ignorecase
set smartcase
" nohlsearch shortcut
nmap -hl :nohlsearch<cr>
nmap +hl :set hlsearch<cr>
" Javascript syntax hightlight
syntax enable
" ctrlp
set wildignore+=*/tmp/*,*.so,*.swp,*.zip " MacOSX/Linux"
let g:ctrlp_custom_ignore = '\v[\/]\.(git|hg|svn)$'
set laststatus=2 " Always display the status line
set statusline+=%{fugitive#statusline()} " Git Hotness
" RSpec.vim mappings
"map <Leader>t :call RunCurrentSpecFile()<CR>
"map <Leader>s :call RunNearestSpec()<CR>
"map <Leader>l :call RunLastSpec()<CR>
"map <Leader>a :call RunAllSpecs()<CR>
" Vim-instant-markdown doesn't work in zsh
"set shell=bash\ -i
"
"expand the current buffer folder when type %%
cnoremap <expr> %% getcmdtype( ) == ':' ? expand('%:h').'/' : '%%'
"setting for vim-airline
let g:airline#extensions#tabline#enabled = 1
"buffer management
nnoremap <silent> [b :bprevious<CR>
nnoremap <silent> ]b :bnext<CR>
nnoremap H :bprevious<CR>
nnoremap L :bnext<CR>
"switch between tabs
"nnoremap H gT
"nnoremap L gt
" Keep search matches in the middle of the window.
" " zz centers the screen on the cursor, zv unfolds any fold if the cursor
" " suddenly appears inside a fold.
nnoremap * *zzzv
nnoremap # #zzzv
nnoremap n nzzzv
nnoremap N Nzzzv
"
" " Also center the screen when jumping through the changelist
nnoremap g; g;zz
nnoremap g, g,zz
" fast save file
nnoremap <leader>w :w<CR>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Command-T "
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let g:CommandTMaxHeight = 30
let g:CommandTMatchWindowReverse = 1 " shows results in reverse order
" If we're at_google, then use the ruby finder because that will not traverse
" directories matched by wildignore. The 'find' scanner will only filter out
" paths matching wildignore *AFTER* enumerating all the paths, which is when
" some dirs are mapped to the network.
"if at_google
" let g:CommandTFileScanner = 'ruby'
"else
" let g:CommandTFileScanner = 'find'
"endif
let g:CommandTTraverseSCM = 'pwd'
set wildignore+=*.o,*.obj,.git,*.pyc,*.so,blaze*,READONLY,llvm,Library*
set wildignore+=CMakeFiles,packages/*,**/packages/*,**/node_modules/*
" This appears to be necessary; command-t doesn't appear to be falling back to
" wildignore on its own.
let g:CommandTWildIgnore=&wildignore
" MacVim doesn't use tab focus to switch from command-t input field to the file
" list, so using j and k for next and prev screws everything up. But it does
" work on linux so let's use it there.
if has("gui_gtk2")
let g:CommandTSelectNextMap = [ '<down>' ]
let g:CommandTSelectPrevMap = [ '<up>' ]
endif
nnoremap <leader>t :CommandT<cr>
nnoremap <leader>n :CommandTBuffer<cr>
nnoremap <leader>' :CommandTFlush<cr>
" Switch to the directory of the open buffer
noremap <leader>cd :cd %:p:h<cr>
""""""""""""""""""""""""""""""""""""""""""""""""""
" ack.vim "
""""""""""""""""""""""""""""""""""""""""""""""""""
if executable('ag')
let g:ackprg = "ag --nocolor --nogroup --column"
elseif executable('ack-grep')
let g:ackprg = "ack-grep --nocolor --nogroup --column"
elseif executable('ack')
let g:ackprg = "ack --nocolor --nogroup --column"
endif
cnoreabbrev Ack Ack!
nnoremap <Leader>a :Ack!<Space>
:let g:pymode_rope = 0
":let g:pymode_lint_ignore = "E501,E303,E302,E266,E111,W"
:let g:pymode_lint_ignore = "E111"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment