Vim基本命令

clipboard.png

clipboard.png

1、进入命令行模式后输入 文件路径同样可以打开相应文件

2、游标移动
\color{red}{h}
\color{red}{l }
\color{red}{j }
\color{red}{ k} k 上
\color{red}{w} 移动到下一个单词
\color{red}{b} 移动到上一个单词

3、进入插入模式
\color{red}{i} 在当前光标处进行编辑
\color{red}{I} 在行首插入
\color{red}{A} 在行末插入
\color{red}{a} 在光标后插入编辑
\color{red}{o} 在当前行后插入一个新行
\color{red}{O} 在当前行前插入一个新行
\color{red}{cw} 替换从光标所在位置后到第一个单词结尾的字符
4、删除文本
\color{red}{x} 删除游标所在字符
\color{red}{X} 删除游标所在前一个字符
\color{red}{dd} 删除整行
\color{red}{dw} 删除一个单词
D删除至行尾
d^ 删除至行首
\color{red}{dG} 删除到文档结尾
\color{red}{d1G} 删至文档首部
5、重复执行上次命令
在普通模式下\color{red}{.}(小数点)表示重复上一次的命令操作
6、执行指定次数相同的命令
进入普通模式输入\color{red}{N<command>}\color{red}{N} 表示重复后面的次数
7、游标行间跳转
\color{red}{nG} 游标移动到第n行
\color{red}{gg} 游标移动到第一行
\color{red}{G }游标移动到最后一行
你在完成依次跳转后,可以使用\color{red}{ Ctrl+o} 快速回到上一次(跳转前)光标所在位置
8、游标行内跳转
\color{red}{w }到下一个单词的开头
\color{red}{e }到当前单词的结尾
\color{red}{b }到前一个单词的开头
\color{red}{ge} 到前一个单词的结尾
\color{red}{0}或^ 到行首
到行尾
\color{red}{f<字母>} 向后搜索<字母>并跳转到第一个匹配位置
\color{red}{F<字母>}向前搜索<字母>并跳转到第一个匹配位置
9、复制及粘贴文本

普通模式中使用\color{red}{y}复制
\color{red}{yy} 复制游标所在的整行
y^ 复制至行首,或\color{red}{y0}(不含光标所在处的字符)
y 复制至行尾(含光标所在处的字符)
\color{red}{yw} 复制一个单词
\color{red}{y2w} 复制两个单词
\color{red}{yG }复制至文本末
\color{red}{y1G} 复制至文本开头
普通模式中使用p粘贴
\color{red}{p} 粘贴至光标后
\color{red}{P} 粘贴至光标前

10、剪切及粘贴文本
其实前面讲得 \color{red}{dd} 删除命令就是剪切,你每次\color{red}{ dd }删除文档内容后,便可以使用 p 来粘贴,也这一点可以让我们实现一个很爽快的功能——交换上下行:\color{red}{ddp },就这么简单,即实现了快速交换光标所在行与它下面的行
11、字符的替换和撤销
\color{red}{r+<待替换字母> }将游标所在字母替换为指定字母
\color{red}{R 连续替换},直到按下\color{red}{Esc}
\color{red}{cc} 替换整行,即删除游标所在行,并进入插入模式
\color{red}{cw }替换一个单词,即删除一个单词,并进入插入模式
\color{red}{C} 替换游标以后至行末
\color{red}{~ }反转游标所在字母的大小写
\color{red}{u{n}} 撤销n次操作
\color{red}{U }撤销当前行的所有修改
\color{red}{Ctrl+r redo},即撤销$\color{red}{undo的操作
12、快速缩进
普通模式下输入>>整行将向右缩进
普通模式下输入<<整行向左回退
普通模式下输入:进入命令行模式下对shiftwidth值进行设置可以控制缩进和回退的字符数,如:set shiftwidth=10
13、快速查找
普通模式下输入/然后键入需要查找的字符串 按回车后就会进行查找。? 与/功能相同,只不过?是向上而 / 是向下查找。 进入查找之后,输入n 和 N 可以继续查找。n是查找下一个内容,N查找上一个内容。
14、可视模式

在普通模式下输入 \color{red}{v,}进入字符选择模式,就可以移动光标,光标走过的地方就会选取。再次按下\color{red}{v}后就会取消选取。
在普通模式下输入 \color{red}{Shift+v},进入行选择模式,按下\color{red}{V}之后就会把整行选取,您可以上下移动光标选更多的行,同样,再按一次\color{red}{Shift+v}就可以取消选取。
在普通模式下输入\color{red}{Ctrl+v},这是区域选择模式,可以进行矩形区域选择,再按一次\color{red}{Ctrl+v}取消选取。
在可视模式下输入 \color{red}{d} 删除选取区域内容
在可视模式下输入\color{red}{y}复制选取区域内容

作者:Ccccolin_aha
链接:https://www.jianshu.com/p/e9e0277cd9ff
来源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

" ************* Vundle 配置 ****************
" 侦测文件类型 
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()

" Vundle.vim : vim的一个非常好用的插件管理器
Bundle 'gmarik/Vundle.vim'

" 更酷的启动界面
"Bundle 'mhinz/vim-startify'

" 协作编程
"Bundle 'FredKSchott/CoVim'

" 代码补全
Bundle 'Valloric/YouCompleteMe'
Bundle 'SirVer/ultisnips'
Bundle 'honza/vim-snippets'
Bundle 'YanhaoMo/snippets'

" Python代码补全
"Bundle 'Pydiction'

" 符号自动补全
Bundle 'Raimondi/delimitMate'

" 文件搜索
Bundle 'kien/ctrlp.vim'
Bundle 'Shougo/unite.vim'
Bundle 'scrooloose/nerdtree'
Bundle 'vim-scripts/mru.vim'

" 静态语法检查
Bundle 'scrooloose/syntastic'

" 代码浏览
Bundle 'majutsushi/tagbar'

" git支持
Bundle 'tpope/vim-fugitive'
Bundle 'airblade/vim-gitgutter'

" 美化主题
Bundle 'tomasr/molokai'
Bundle 'morhetz/gruvbox'
Bundle 'kien/rainbow_parentheses.vim'
Bundle 'bling/vim-airline'
"Bundle 'vim-airline-themes'
Bundle 'nathanaelkane/vim-indent-guides'
Bundle 'solarized'
Bundle 'jpo/vim-railscasts-theme'
"Bundle 'altercation/vim-colors-solarized.git'
"Bundle 'fholgado/minibufexpl.vim'

" 代码bug追踪
Bundle 'ZenCoding.vim'

" 模仿sublime text 的 ctrl + shift + f 在工程中全局查找某字符
" 需先安装ack: sudo apt-get install ack
Bundle 'dyng/ctrlsf.vim'

" 编辑增强
" 多光标操作
Bundle 'terryma/vim-multiple-cursors'
" 成对符号编辑
Bundle 'tpope/vim-surround'
Bundle 'tpope/vim-unimpaired'

" 快速注释
Bundle 'scrooloose/nerdcommenter'
" 自动对齐
Bundle 'godlygeek/tabular'
" 快速移动
Bundle 'Lokaltog/vim-easymotion'
" 代码块对齐用
Bundle 'Yggdroot/indentLine'
" 增强状态栏
Bundle 'rstatusline'

" tmux支持
Bundle 'benmills/vimux'

" c/c++
Bundle 'vim-scripts/a.vim'
Bundle 'vim-scripts/c.vim'

" org-mode
Bundle 'jceb/vim-orgmode'
Bundle 'tpope/vim-speeddating'

" markdown
Bundle 'plasticboy/vim-markdown'
" 可以通过浏览器实时预览,但是要安装额外依赖,详见官网
"Bundle 'suan/vim-instant-markdown'

" 网页开发
Bundle 'mattn/emmet-vim'

" pyhon
Bundle 'klen/python-mode'
"Bundle 'python-imports.vim'

" js
Bundle 'coolwanglu/vim.js'

" golang
"Bundle 'fatih/vim-go'

" 用ack代替grep搜索
Bundle 'mileszs/ack.vim'
"bundle 'vimwiki/vimwiki'
"Bundle 'vim-scripts/bufexplorer.zip'
"Bundle 'terryma/vim-smooth-scroll'

call vundle#end()
filetype plugin on                                              " 载入文件类型插件
filetype indent on                                              " 为特定文件类型载入相关缩进文件


" *************** gvim配置 ***************
if has("gui_running")
    let $LANG='en'      "设置gvim菜单栏始终显示为英文
    set langmenu=en
    source $VIMRUNTIME/delmenu.vim
    source $VIMRUNTIME/menu.vim
    "set guifont=DejaVu\ Sans\ Mono\ for\ Powerline\ Book\ 10
    set guifont=Source\ Code\ Pro\ for\ Powerline\ Regular\ 10
    set guioptions-=e
    set guioptions-=m
    set guioptions-=T
    set guioptions-=L
    set guioptions-=r
    set guioptions-=B
    set guioptions-=0
    set go=
    winpos 1000 0
    "set lines=100 columns=150      " 开启时的窗口默认大小
endif


" *************** vim常用的基本设置 ***************
set nocompatible                                                " 不使用vi的键盘模式,而是vim自己的
"syntax enable                                                   " 开启语法高亮功能
syntax on                                                       " 语法高亮支持
set nu                                                          " 显示行号
set rnu                                                         " 显示相对行号
set wrap                                                        " 当一行文字很长时换行
"set nowrap                                                      " 当一行文字很长时取消换行
set showmatch                                                   " 当光标移动到一个括号时高亮显示对应的另一个括号
set showcmd                                                     " 回显输入的命令
set showmode                                                    " 显示当前的模式
set clipboard+=unnamed                                          " 关联系统的剪贴板
set ruler                                                       " 在编辑过程中右下角显示光标的行列信息
set nocp                                                        " 让Vim工作在不兼容模式下
set shortmess=atI                                               " 启动时不显示捐助乌干达儿童的提示
set so=6                                                        " 上下滚行时空余6行
set autoindent                                                  " 自动套用上一行的缩进方式
set smartindent                                                 " 智能缩进
set mouse=a                                                     " 开启鼠标支持
set laststatus=2                                                " 总是显示状态行
set backspace=indent,eol,start                                  " 对退格键提供更好的支持
set ts=4                                                        " 设置tab长度为4
set sts=4                                                       " 设置制表符宽度
set shiftwidth=4                                                " 设置缩进空格数
set expandtab                                                   " 用空格代替tab键
set smarttab                                                    " 更加智能的tab键
set hid                                                         " 当buffer被丢弃时隐藏它
set encoding=utf-8                                              " 默认使用utf-8编码格式
set fileencodings=utf-8,cp936,gb18030,big5,euc-kr,latin1        " 自动判断编码时 依次尝试一下编码
set ffs=unix,dos,mac                                            " 设置文件类型
set hlsearch                                                    " 高亮搜索内容
set ignorecase                                                  " 搜索模式里忽略大小写
set smartcase                                                   " 如果搜索字符串里包含大写字母,则禁用 ignorecase
set incsearch                                                   " 显示搜索的动态匹配效果
set lazyredraw                                                  " 解决某些类型的文件由于syntax导致vim反应过慢的问题
set ttyfast                                                     " 平滑地变化
set cc=80                                                       " 第80字符处显示分隔符
set foldmethod=indent                                           " 折叠方式
set nofoldenable                                                " 不自动折叠
set foldcolumn=1                                                " 在行号前空出一列的宽度
set t_Co=256                                                    " 设置256真彩色
set history=1000                                                " 设置历史记录条数
"set autoread                                                   " 当文件在外部被修改时自动载入
"set cindent                                                    " 使用c语言的缩进格式
"set whichwrap+=<,>,h,l                                         " 允许backspace和光标键跨越行边界
"set cmdheight=2                                                " 显示两行命令行

set list lcs=tab:\♠\ ,trail:•                                   " 显示tab键为♠,并且显示每行结尾的空格为'•'
" 一些备用字符:›┆┇┊┋♠♦•

" 格式化状态行显示的内容
set statusline=[%t]\ %y\ %m%=%{&fileencoding}\ [%{&ff}]\ [%l,\ %c]\ [%L]\ [%p%%]

" 打开一个文件自动定位到上一次退出的位置
if has("autocmd")
    au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
endif

" 保存.vim文件后不用退出即可生效
"autocmd BufWritePost $MYVIMRC source $MYVIMRC
"au! bufwritepost .vimrc source %


" ************** 备份设置 ****************
"set nobackup                                                   " 不进行备份
"set nowb                                                       " 重新载入文件时不要备份
"set noswapfile                                                 " 不使用swf文件,可能导致错误无法恢复


" *************** 关闭错误声音 **************
set noerrorbells
set novisualbell
set  t_vb=


" **************** 设置vim主题外观 ***************
"set background=light                                           " 设置vim背景为浅色
set background=dark                                             " 设置vim背景为深色
set cursorline                                                  " 突出显示当前行
set cursorcolumn                                                " 突出显示当前列

"colorscheme molokai                                             " 设置molokai高亮主题
"colorscheme desert                                              " 设置desert高亮主题
"let g:solarized_termcolors=256
"colorscheme solarized                                           " 设置solarized高亮主题
"let g:gruvbox_termcolors=16
colorscheme gruvbox                                             " 设置gruvbox高亮主题


" ************** vim的配色 **************
"hi CursorLine cterm=NONE ctermbg=237 ctermfg=NONE
"hi CursorColumn cterm=NONE ctermbg=237 ctermfg=NONE
hi vertsplit ctermbg=bg guibg=bg
hi GitGutterAdd ctermbg=bg guibg=bg
hi GitGutterChange ctermbg=bg guibg=bg
hi GitGutterDelete ctermbg=bg guibg=bg
hi GitGutterChangeDelete ctermbg=bg guibg=bg
hi SyntasticErrorSign ctermbg=bg guibg=bg
hi SyntasticWarningSign ctermbg=bg guibg=bg
hi FoldColumn ctermbg=bg guibg=bg


" *********** NERDTree插件配置 ***********
let NERDTreeChDirMode=2                                         " 设置当前目录为nerdtree的起始目录
let NERDChristmasTree=1                                         " 使得窗口有更好看的效果
let NERDTreeMouseMode=1                                         " 双击鼠标左键打开文件
let NERDTreeWinSize=25                                          " 设置窗口宽度为25
let NERDTreeQuitOnOpen=1                                        " 打开一个文件时nerdtree分栏自动关闭


" *********** ctags插件配置 ***********
set tags+=/usr/include/tags


" ********* cscope插件配置 **********
if has("cscope")
    "set csprg=/usr/bin/cscope
    set csto=0
    set cst
    set nocsverb
    set cscopequickfix=s-,c-,d-,i-,t-,e- "在quickfix窗口中显示搜索结果


    " add any database in current directory
    if filereadable("cscope.out")
        cs add cscope.out
        " else add database pointed to by environment
    elseif $CSCOPE_DB != ""
        cs add $CSCOPE_DB
    endif
    set csverb
endif


" *********** nerdcommenter快速注释插件配置 **********
" Add spaces after comment delimiters by default
let g:NERDSpaceDelims = 1
" Use compact syntax for prettified multi-line comments
let g:NERDCompactSexyComs = 1
" Align line-wise comment delimiters flush left instead of following code indentation
let g:NERDDefaultAlign = 'left'
" Set a language to use its alternate delimiters by default
let g:NERDAltDelims_java = 1
" Add your own custom formats or override the defaults
let g:NERDCustomDelimiters = { 'c': { 'left': '/**','right': '*/' } }
" Allow commenting and inverting empty lines (useful when commenting a region)
let g:NERDCommentEmptyLines = 1
" Enable trimming of trailing whitespace when uncommenting
let g:NERDTrimTrailingWhitespace = 1


" *********** syntastic插件配置 ***********
set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 1
let g:syntastic_error_symbol = '✗'
let g:syntastic_warning_symbol = '⚡'
"let g:syntastic_cpp_include_dirs = ['/usr/include/qt']
"let g:syntastic_cpp_compiler_options = '-std=gnu++11 -Wall'
let g:syntastic_mode_map = { 'mode': 'passive', 'active_filetypes': [],'passive_filetypes': [] }


" ********** pydiction补全设置 **********
"let g:pydiction_location = '~/.vim/bundle/Pydiction/complete-dict'
""defalut g:pydiction_menu_height == 15
"let g:pydiction_menu_height = 10


" ********** youcompleteme自动补全配置 ***********
let g:ycm_global_ycm_extra_conf = '~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py'
"let g:ycm_python_binary_path = 'python'
set completeopt=longest,menu    "让Vim的补全菜单行为与一般IDE一致(参考VimTip1228)
autocmd InsertLeave * if pumvisible() == 0|pclose|endif "离开插入模式后自动关闭预览窗口
inoremap <expr> <CR>       pumvisible() ? "\<C-y>" : "\<CR>"    "回车即选中当前项
"上下左右键的行为 会显示其他信息
inoremap <expr> <Down>     pumvisible() ? "\<C-n>" : "\<Down>"
inoremap <expr> <Up>       pumvisible() ? "\<C-p>" : "\<Up>"
inoremap <expr> <PageDown> pumvisible() ? "\<PageDown>\<C-p>\<C-n>" : "\<PageDown>"
inoremap <expr> <PageUp>   pumvisible() ? "\<PageUp>\<C-p>\<C-n>" : "\<PageUp>"
" 跳转到定义处
nnoremap <leader>jd :YcmCompleter GoToDefinitionElseDeclaration<CR>
nnoremap <F4> :YcmForceCompileAndDiagnostics<CR>    "force recomile with syntastic
" nnoremap <leader>lo :lopen<CR>    "open locationlist
" nnoremap <leader>lc :lclose<CR>   "close locationlist
inoremap <leader><leader> <C-x><C-o>


" 不显示开启vim时检查ycm_extra_conf文件的信息  
let g:ycm_confirm_extra_conf=0
" 开启基于tag的补全,可以在这之后添加需要的标签路径  
let g:ycm_collect_identifiers_from_tags_files=1
"注释和字符串中的文字也会被收入补全
let g:ycm_collect_identifiers_from_comments_and_strings = 0
" 输入第2个字符开始补全
let g:ycm_min_num_of_chars_for_completion=2
" 禁止缓存匹配项,每次都重新生成匹配项
let g:ycm_cache_omnifunc=0
" 开启语义补全
let g:ycm_seed_identifiers_with_syntax=1    
"在注释输入中也能补全
let g:ycm_complete_in_comments = 1
"在字符串输入中也能补全
let g:ycm_complete_in_strings = 1
" 设置在下面几种格式的文件上屏蔽ycm
let g:ycm_filetype_blacklist = {
      \ 'tagbar' : 1,
      \ 'nerdtree' : 1,
      \}
"youcompleteme  默认tab  s-tab 和 ultisnips 冲突
let g:ycm_key_list_select_completion = ['<Down>']
let g:ycm_key_list_previous_completion = ['<Up>']
" 修改对C函数的补全快捷键,默认是CTRL + space,修改为ALT + ;
let g:ycm_key_invoke_completion = '<M-;>'

" SirVer/ultisnips 代码片断
" Trigger configuration. Do not use <tab> if you use https://github.com/Valloric/YouCompleteMe.
let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsJumpForwardTrigger="<tab>"
let g:UltiSnipsJumpBackwardTrigger="<s-tab>"
let g:UltiSnipsListSnippets="<c-e>"
"定义存放代码片段的文件夹,使用自定义和默认的,将会的到全局,有冲突的会提示
let g:UltiSnipsSnippetDirectories=["~/.vim/bundle/vim-snippets/UltiSnips"]

" 参考https://github.com/Valloric/YouCompleteMe/issues/36#issuecomment-62941322
" 解决ultisnips和ycm tab冲突,如果不使用下面的办法解决可以参考
" https://github.com/Valloric/YouCompleteMe/issues/36#issuecomment-63205056的配置
" begin
" let g:ycm_key_list_select_completion=['<C-n>', '<Down>']
" let g:ycm_key_list_previous_completion=['<C-p>', '<Up>']
" let g:UltiSnipsExpandTrigger="<Tab>"
" let g:UltiSnipsJumpForwardTrigger="<Tab>"                                           
" let g:UltiSnipsJumpBackwardTrigger="<S-Tab>"
" end
" UltiSnips completion function that tries to expand a snippet. If there's no
" snippet for expanding, it checks for completion window and if it's
" shown, selects first element. If there's no completion window it tries to
" jump to next placeholder. If there's no placeholder it just returns TAB key 
function! g:UltiSnips_Complete()
    call UltiSnips#ExpandSnippet()
    if g:ulti_expand_res == 0
        if pumvisible()
            return "\<C-n>"
        else
            call UltiSnips#JumpForwards()
            if g:ulti_jump_forwards_res == 0
               return "\<TAB>"
            endif
        endif
    endif
    return ""
endfunction

au BufEnter * exec "inoremap <silent> " . g:UltiSnipsExpandTrigger . " <C-R>=g:UltiSnips_Complete()<cr>"

" Expand snippet or return
let g:ulti_expand_res = 1
function! Ulti_ExpandOrEnter()
    call UltiSnips#ExpandSnippet()
    if g:ulti_expand_res
        return ''
    else
        return "\<return>"
endfunction

" Set <space> as primary trigger
inoremap <return> <C-R>=Ulti_ExpandOrEnter()<CR>


" ********** indentLine插件 **********
let g:indentLine_char = '┊'                                     "代码块对齐用┊符号


" *********** UltiSnips插件配置 **********
let g:UltiSnipsExpandTrigger="<tab>"
""let g:UltiSnipsJumpForwardTrigger="<tab>"
""let g:UltiSnipsJumpBackwardTrigger="<s-tab>"
let g:UltiSnipsEditSplit = "vertical"
"let g:UltiSnipsSnippetDirectories = ["UltiSnips", "bundle/snippets"]
let g:UltiSnipsSnippetDirectories = ["bundle/snippets"]


" ********** rainbow_parentheses插件配置 ***********
let g:rbpt_colorpairs = [
            \ ['brown',       'RoyalBlue3'],
            \ ['Darkblue',    'SeaGreen3'],
            \ ['darkgray',    'DarkOrchid3'],
            \ ['darkgreen',   'firebrick3'],
            \ ['darkcyan',    'RoyalBlue3'],
            \ ['darkred',     'SeaGreen3'],
            \ ['darkmagenta', 'DarkOrchid3'],
            \ ['brown',       'firebrick3'],
            \ ['gray',        'RoyalBlue3'],
            \ ['black',       'SeaGreen3'],
            \ ['darkred',     'DarkOrchid3'],
            \ ['darkmagenta', 'DarkOrchid3'],
            \ ['Darkblue',    'firebrick3'],
            \ ['darkgreen',   'RoyalBlue3'],
            \ ['darkcyan',    'SeaGreen3'],
            \ ['red',         'firebrick3'],
            \ ]
let g:rbpt_max = 16
let g:rbpt_loadcmd_toggle = 0
au VimEnter * RainbowParenthesesToggle
au Syntax * RainbowParenthesesLoadRound
au Syntax * RainbowParenthesesLoadSquare
au Syntax * RainbowParenthesesLoadBraces


" ********** vim-multiple-cursors插件配置 ***********
let g:multi_cursor_use_default_mapping=0
let g:multi_cursor_next_key='<C-m>'
let g:multi_cursor_prev_key='<C-p>'
let g:multi_cursor_skip_key='<C-x>'
let g:multi_cursor_quit_key='<Esc>'


" ********** airline插件配置 ***********
let g:airline_powerline_fonts=1     "配置airline使用powerline字体
"let g:airline#extensions#tabline#enabled = 1
"let g:airline#extensions#tabline#left_sep = ' '
"let g:airline#extensions#tabline#left_alt_sep = '|'


" *********** vimwiki插件配置 ***********
"let g:vimwiki_list = [{'path' : '~/.vimwiki/',
"        \'template_path' : '~/.vimwiki/template/',
"        \'template_default' : 'default_template',
"        \'template_ext' : '.html',
"        \'path_html': '~/.vimwiki/html/'}
"        \]


" ********** mru插件配置 **********
let MRU_Auto_Close = 1
let MRU_Max_Entries = 40


" ************ pythom-mode *********
let g:pymode_lint_on_write = 0
let g:pymode_lint_signs = 0
let g:pymode_rope_lookup_project = 0
let g:pymode_rope = 0
let g:pymode_floding = 0


" ********** Emmet--> html插件 **********
let g:user_emmet_expandabbr_key = '<Tab>'
let g:user_emmet_settings = {
            \ 'php' : {
            \ 'extends' : 'html',
            \ 'filters' : 'c',
            \ },
            \ 'xml' : {
            \ 'extends' : 'html',
            \ },
            \ 'haml' : {
            \ 'extends' : 'html',
            \ },
            \}


" ********** vim write django **********
" au FileType python set ft=python.django
" au FileType html set ft=htmldjango.html


" *********** 重新映射一些键 **********
" 设置以空格打开和关闭折叠
nmap <space> @=((foldclosed(line('.'))<0)?'zc':'zo')<CR>

" 当一行很长时把分开的段行当作一行来移动
map j gj
map k gk

" 将Esc键映射到jj,zz
im jj <Esc>
im JJ <Esc>
im zz <Esc>
im ZZ <Esc>
map zz <Esc>
map ZZ <Esc>

" quickfix相关的一些快捷键
map cop :copen<CR>
map ccl :cclose<CR>
map cn :cn<CR>
map cp :cp<CR>

" emacs式的行内跳转
map <c-a> ^
map <c-e> $
imap <c-a> <Esc>^i
imap <c-e> <Esc>$a

" ff跳转到文件末尾
map ff G

" visual模式下快速对齐
vnoremap < <gv
vnoremap > >gv

" <F3>关闭打开目录树
map <F3> :NERDTreeToggle<CR>
imap <F3> <ESC> :NERDTreeToggle<CR>
" 打开树状文件目录
map <C-F3> \be

" <F7>生成ctags
map <F7> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR>
im <F7> <Esc>:!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR>
nmap go g<C-]>
nmap bk <C-t>

nmap <C-_>s :cs find s <C-R>=expand("<cword>")<CR><CR>
nmap <C-_>g :cs find g <C-R>=expand("<cword>")<CR><CR>
nmap <C-_>c :cs find c <C-R>=expand("<cword>")<CR><CR>
nmap <C-_>t :cs find t <C-R>=expand("<cword>")<CR><CR>
nmap <C-_>e :cs find e <C-R>=expand("<cword>")<CR><CR>
nmap <C-_>f :cs find f <C-R>=expand("<cfile>")<CR><CR>
nmap <C-_>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
nmap <C-_>d :cs find d <C-R>=expand("<cword>")<CR><CR>

" <F5>编译运行
" map <F5> :Autopep8<CR> :w<CR> :call RunPython()<CR>
" function RunPython()
"     let mp = &makeprg
"     let ef = &errorformat
"     let exeFile = expand("%:t")
"     setlocal makeprg=python\ -u
"     set efm=%C\ %.%#,%A\ \ File\ \"%f\",\ line\ %l%.%#,%Z%[%^\ ]%@=%m
"     silent make %
"     copen
"     let &makeprg = mp
"     let &errorformat = ef
" endfunction

:autocmd BufRead,BufNewFile *.dot map <F5> :w<CR>:!dot -Tjpg -o %<.jpg % && eog %<.jpg  <CR><CR> && exec "redr!"
" C,C++ 按F5编译运行
map <F5> :call CompileRunGcc()<CR>
func! CompileRunGcc()
    exec "w"
    if &filetype == 'c'
        exec "!g++ % -o %<"
        exec "!time ./%<"
    elseif &filetype == 'cpp'
        exec "!g++ % -o %<"
        exec "!time ./%<"
    elseif &filetype == 'java'
        exec "!javac %"
        exec "!time java %<"
    elseif &filetype == 'sh'
        :!time bash %
    elseif &filetype == 'python'
        exec "!time python2.7 %"
    elseif &filetype == 'html'
        exec "!firefox % &"
    elseif &filetype == 'go'
    "        exec "!go build %<"
        exec "!time go run %"
    elseif &filetype == 'mkd'
        exec "!~/.vim/markdown.pl % > %.html &"
        exec "!firefox %.html &"
    endif
endfunc

" C,C++的调试
map <F6> :call Rungdb()<CR>
func! Rungdb()
    exec "w"
    exec "!g++ % -g -o %<"
    exec "!gdb ./%<"
endfunc

" <F4>语法检查
map <F4> :SyntasticCheck<CR>
im <F4> <Esc>:SyntasticCheck<CR>

"" 代码格式优化化
"map <F4> :call FormartSrc()<CR><CR>
"" 定义FormartSrc()
"func FormartSrc()
"    exec "w"
"    if &filetype == 'c'
"        exec "!astyle --style=ansi -a --suffix=none %"
"    elseif &filetype == 'cpp' || &filetype == 'hpp'
"        exec "r !astyle --style=ansi --one-line=keep-statements -a --suffix=none %> /dev/null 2>&1"
"    elseif &filetype == 'perl'
"        exec "!astyle --style=gnu --suffix=none %"
"    elseif &filetype == 'py'||&filetype == 'python'
"        exec "r !autopep8 -i --aggressive %"
"    elseif &filetype == 'java'
"        exec "!astyle --style=java --suffix=none %"
"    elseif &filetype == 'jsp'
"        exec "!astyle --style=gnu --suffix=none %"
"    elseif &filetype == 'xml'
"        exec "!astyle --style=gnu --suffix=none %"
"    else
"        exec "normal gg=G"
"        return
"    endif
"    exec "e! %"
"endfunc

" <F8>更新cscope文件
map <F8> :!cscope -Rbq<CR>
im <F8> <Esc>:!cscope -Rbq<CR>

" 修改<leader>的键盘映射
nmap ' <leader>
" 当按下\+Enter时取消搜索高亮
map <silent> <leader><CR> :noh<CR>

" Unite插件配置
map <Leader>b :Unite -winheight=10 buffer<CR>
map <Leader>r :MRU<CR>
map <leader>f :NERDTreeToggle<CR>

" Tagbar插件配置
let g:tagbar_autoclose=1
"map <leader>t :TagbarToggle<CR>
map <F2> :TagbarToggle<CR>
"
" 设置文件类型辅助
map <leader>s :setfiletype
" 更方便的窗口间跳转
map <leader>j <c-w>j
map <leader>k <c-w>k
map <leader>l <c-w>l
map <leader>h <c-w>h
map <C-j> <c-w>j
map <C-k> <c-w>k
map <C-l> <c-w>l
map <C-h> <c-w>h

" vimux插件配置
map <Leader>e :VimuxPromptCommand<CR>
map <Leader>x :VimuxCloseRunner<CR>
map <Leader>vl :VimuxRunLastCommand<CR>
map <Leader>vi :VimuxInspectRunner<CR>
" 更方便的页滚动
map <C-j> <C-f>
map <C-k> <C-b>

map ,,j <Plug>(easymotion-w)
map ,,k <Plug>(easymotion-b)
map ,,s <Plug>(easymotion-s)


" ctrlsf 插件
map <leader>f <Plug>CtrlSFPrompt
map <leader>F <Plug>CtrlSFQuickfixPrompt


"********** 新建.c,.h,.sh,.java文件,自动插入文件头 **********
autocmd BufNewFile *.cpp,*.[ch],*.sh,*.rb,*.java,*.py exec ":call SetHead()"
"" 定义函数SetHead,自动插入文件头
func! SetHead()
    if &filetype == 'sh'
        call setline(1,"\#!/bin/bash")
        call append(line("."), "")
    elseif &filetype == 'python'
        call setline(1,"#!/usr/bin/env python")
        call append(line("."),"# -*- coding=utf-8 -*-")
        call append(line(".")+1, "")
    elseif &filetype == 'ruby'
        call setline(1,"#!/usr/bin/env ruby")
        call append(line("."),"# encoding: utf-8")
        call append(line(".")+1, "")
"    elseif &filetype == 'mkd'
"        call setline(1,"<head><meta charset=\"UTF-8\"></head>")
    else
        call setline(1, "/*************************************************************************")
        call append(line("."), "    > File Name: ".expand("%"))
        call append(line(".")+1, "  > Author: ")
        call append(line(".")+2, "  > Mail: ")
        call append(line(".")+3, "  > Created Time: ".strftime("%c"))
        call append(line(".")+4, " ************************************************************************/")
        call append(line(".")+5, "")
    endif

    if expand("%:e") == 'cpp'
        call append(line(".")+6, "#include<iostream>")
        call append(line(".")+7, "using namespace std;")
        call append(line(".")+8, "")
    endif

    if &filetype == 'c'
        call append(line(".")+6, "#include<stdio.h>")
        call append(line(".")+7, "")
    endif

    if expand("%:e") == 'h'
        call append(line(".")+6, "#ifndef _".toupper(expand("%:r"))."_H")
        call append(line(".")+7, "#define _".toupper(expand("%:r"))."_H")
        call append(line(".")+8, "#endif")
    endif

    if &filetype == 'java'
        call append(line(".")+6,"public class ".expand("%:r"))
        call append(line(".")+7,"")
    endif
    " 新建文件后,自动定位到文件末尾
endfunc
autocmd BufNewFile * normal G


" ********* 实用设置 *********
if has("autocmd")
      autocmd BufReadPost *
          \ if line("'\"") > 0 && line("'\"") <= line("$") |
          \   exe "normal g`\"" |
          \ endif
endif

" 当打开vim且没有文件时自动打开NERDTree
autocmd vimenter * if !argc() | NERDTree | endif
" 只剩 NERDTree时自动关闭
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif

" quickfix模式
autocmd FileType c,cpp map <buffer> <leader><space> :w<cr>:make<cr>

K-Vim地址:https://github.com/ajioy/aj-vim

https://github.com/ajioy/aj-vim](https://github.com/ajioy/aj-vim)

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 159,290评论 4 363
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,399评论 1 294
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 109,021评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 44,034评论 0 207
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,412评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,651评论 1 219
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,902评论 2 313
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,605评论 0 199
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,339评论 1 246
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,586评论 2 246
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,076评论 1 261
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,400评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,060评论 3 236
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,083评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,851评论 0 195
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,685评论 2 274
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,595评论 2 270

推荐阅读更多精彩内容

  • Linux基础命令 目录: /dev 存放硬件相关的文件 /etc 存放配置文件的目录 /bin 存放普通用户命令...
    影子ing阅读 869评论 0 2
  • vim编辑文件有两个模式。 正常模式:所有输入都是命令,也叫命令模式(命令区分大小写,必须是英文半角字符)。 插入...
    饥人谷_空影幽灵阅读 390评论 0 0
  • 自我总结篇: 对文件的操作技巧: vim文件一个有三种状态:命令(浏览/输入命令转变末行模式),文本(添加/编辑/...
    小知大知阅读 771评论 0 0
  • 在命令状态下对当前行用== (连按=两次), 或对多行用n==(n是自然数)表示自动缩进从当前行起的下面n行。你可...
    三十儿阅读 399评论 0 1
  • vim 选择文本,删除,复制,粘贴 文本的选择,对于编辑器来说,是很基本的东西,也经常被用到,总结如下: v 从光...
    MiracleJQ阅读 633评论 0 0