1、编辑vim ~/.vimrc
vim ~/.vimrc
较复杂配置:参考的是https://github.com/samlaudev/ConfigurationFiles/tree/master/vim
少许改动
" Use Vim settings, rather then Vi settings. This setting must be as early as
" possible, as it has side effects.
set nocompatible
" Highlight current line
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=50
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
syntax on
if filereadable(expand("~/.vimrc.bundles"))
source ~/.vimrc.bundles
endif
filetype plugin indent on
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, 4 spaces
set tabstop=4
set shiftwidth=4
set shiftround
set expandtab
" Display extra whitespace
set list listchars=tab:»·,trail:·
" Use The Silver Searcher https://github.com/ggreer/the_silver_searcher
if executable('ag')
" Use Ag over Grep
set grepprg=ag\ --nogroup\ --nocolor
" Use ag in CtrlP for listing files. Lightning fast and respects .gitignore
let g:ctrlp_user_command = 'ag %s -l --nocolor -g ""'
" ag is fast enough that CtrlP doesn't need to cache
let g:ctrlp_use_caching = 0
endif
" Color scheme
colorscheme molokai
"highlight NonText guibg=#060606
"highlight Folded guibg=#0A0A0A guifg=#9090D0
" Make it obvious where 80 characters is
set textwidth=80
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-^>
" vim-rspec mappings
nnoremap <Leader>t :call RunCurrentSpecFile()<CR>
nnoremap <Leader>s :call RunNearestSpec()<CR>
nnoremap <Leader>l :call RunLastSpec()<CR>
" 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
" Quicker window movement
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-h> <C-w>h
nnoremap <C-l> <C-w>l
" 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
" Nerd Tree
" autocmd VimEnter * NERDTree
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
nmap <F1> :NERDTreeToggle<cr>
" Tagbar
let g:tagbar_width=35
let g:tagbar_autofocus=1
nmap <F6> :TagbarToggle<CR>
" Emmet
let g:user_emmet_mode='i' " enable for insert mode
" Search results high light
set hlsearch
" nohlsearch shortcut
nmap -hl :nohlsearch<cr>
nmap +hl :set hlsearch<cr>
" Javascript syntax hightlight
syntax enable
" YouCompleteMe
let g:ycm_autoclose_preview_window_after_completion=1
nnoremap <leader>g :YcmCompleter GoToDefinitionElseDeclaration<CR>
" 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
nnoremap <leader>w :w<CR>
nnoremap <leader>q :q<CR>
" 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
" Snippets author
let g:snips_author = 'Yuez'
" python mode
let g:pymode_indent = 1
" no folding
let g:pymode_folding = 0
let g:pymode_doc = 1
let g:pymode_run = 1
let g:pymode_run_bind = '<space>r'
let g:pymode_breakpoint_bind = '<leader>b'
let g:pymode_rope_goto_definition_bind = "<C-]>"
let g:pymode_virtualenv_path = $VIRTUAL_ENV
简单配置:
作者:地球的外星人君
链接:https://www.zhihu.com/question/19989337/answer/168444287
来源:知乎
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
"显示行号
set nu
"启动时隐去援助提示
set shortmess=atI
"语法高亮
syntax on
"使用vim的键盘模式
"set nocompatible
"不需要备份
set nobackup
"没有保存或文件只读时弹出确认
set confirm
"鼠标可用
set mouse=a
"tab缩进
set tabstop=4
set shiftwidth=4
set expandtab
set smarttab
"文件自动检测外部更改
set autoread
"c文件自动缩进
set cindent
"自动对齐
set autoindent
"智能缩进
set smartindent
"高亮查找匹配
set hlsearch
"背景色
set background=dark
"显示匹配
set showmatch
"显示标尺,就是在右下角显示光标位置
set ruler
"去除vi的一致性
set nocompatible
"允许折叠
set foldenable
"""""""""""""""""设置折叠"""""""""""""""""""""
"
"根据语法折叠
set fdm=syntax
"手动折叠
"set fdm=manual
"设置键盘映射,通过空格设置折叠
nnoremap <space> @=((foldclosed(line('.')<0)?'zc':'zo'))<CR>
""""""""""""""""""""""""""""""""""""""""""""""
"不要闪烁
set novisualbell
"启动显示状态行
set laststatus=2
"浅色显示当前行
autocmd InsertLeave * se nocul
"用浅色高亮当前行
autocmd InsertEnter * se cul
"显示输入的命令
set showcmd
"被分割窗口之间显示空白
set fillchars=vert:/
set fillchars=stl:/
set fillchars=stlnc:/
set encoding=utf-8
2、编辑~/.vimrc.bundles
vim ~/.vimrc.bundles
if &compatible
set nocompatible
end
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" Let Vundle manage Vundle
Bundle 'gmarik/vundle'
" Define bundles via Github repos
Bundle 'christoomey/vim-run-interactive'
Bundle 'Valloric/YouCompleteMe'
Bundle 'croaky/vim-colors-github'
Bundle 'danro/rename.vim'
Bundle 'majutsushi/tagbar'
Bundle 'kchmck/vim-coffee-script'
Bundle 'kien/ctrlp.vim'
Bundle 'pbrisbin/vim-mkdir'
Bundle 'scrooloose/syntastic'
Bundle 'slim-template/vim-slim'
Bundle 'thoughtbot/vim-rspec'
Bundle 'tpope/vim-bundler'
Bundle 'tpope/vim-endwise'
Bundle 'tpope/vim-fugitive'
Bundle 'tpope/vim-rails'
Bundle 'tpope/vim-surround'
Bundle 'vim-ruby/vim-ruby'
Bundle 'vim-scripts/ctags.vim'
Bundle 'vim-scripts/matchit.zip'
Bundle 'vim-scripts/tComment'
Bundle "mattn/emmet-vim"
Bundle "scrooloose/nerdtree"
Bundle "Lokaltog/vim-powerline"
Bundle "godlygeek/tabular"
Bundle "msanders/snipmate.vim"
Bundle "jelera/vim-javascript-syntax"
Bundle "altercation/vim-colors-solarized"
Bundle "othree/html5.vim"
Bundle "xsbeats/vim-blade"
Bundle "Raimondi/delimitMate"
Bundle "groenewege/vim-less"
Bundle "evanmiller/nginx-vim-syntax"
Bundle "Lokaltog/vim-easymotion"
Bundle "tomasr/molokai"
Bundle "klen/python-mode"
if filereadable(expand("~/.vimrc.bundles.local"))
source ~/.vimrc.bundles.local
endif
call vundle#end()
filetype plugin indent on
3、配色方案 molokai
mkdir ~/.vim
git clone https://github.com/tomasr/molokai
mv molokai/colors ~/.vim
rm -rf molokai/
4、插件管理vundle
下载vundle:
git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle
~/.vimrc中要有:(需要添加)
if filereadable(expand("~/.vimrc.bundles"))
source ~/.vimrc.bundles
endif
~/.vimrc.bundles要有:(上面文件中有)
filetype off
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
vim +BundleInstall +qall
常用的命令:
- 目录结构 Fn + F1
- 脚本运行 space + r
- 目录结构下,切换文件/目录 ctrl + w + w http://yang3wei.github.io/blog/2013/01/29/nerdtree-kuai-jie-jian-ji-lu/
- python mode的一些常用命令
1).K :查阅对象文档
2).<leader>r: 运行python脚本
3). <leader>b:自动加入断点
4). <C-P>/<C-N>:自动补全
5). <C-]>: 跳转到函数定义
遇到的问题:
1、插件一直安装失败,命令vim +BundleInstall +qall执行完没有反应
目录权限问题,一开始是 root:Staff (这是mac下的问题,Ubuntu上没有)
改成user:staff
~/.vim » sudo chown -R *user*:staff .
image.png
2、YouCompleteMe需要c环境
mac上安装了很久....
https://elloop.github.io/tools/2016-06-26/upgrade-vim-built-in-mac
~/software » git clone
[https://github.com/vim/vim.git](https://github.com/vim/vim.git)
make --version
cd src
./configure --enable-pythoninterp
make
make install
#make uninstall有问题可以用此命令卸载
brew install cmake
cd ~/.vim/bundle/YouCompleteMe
./install.sh --clang-completer
vim 支持html
参考 https://stackoverflow.com/questions/8168320/can-vim-highlight-matching-html-tags-like-notepad
还没测试实现。
网友评论