定义一个自动命令的格式如下 autocmd type pattern cmd autocmd: 自动命令以 autocmd 关键字开始,它的作用类似与 js 中定义函数时使用的 function 关键字 分组一个是为了划分模块,第二个原因就是我们可以使用 autocmd! 来清除同一组之前的命令。 例如我们将上述命令修改为 :augroup testgrp : autocmd! : autocmd BufWrite * echom "hello3" :augroup END 我们发现在保存之后,它还是会打印3条语句 autocmd! :augroup NVIMRC : autocmd! : autocmd BufWritePost init.vim source % :augroup END 这里我们先使用 autocmd!清除之前的加载操作。
之前我们介绍自动命令的时候已经给出了如何自动加载配置 augroup NVIMRC autocmd! nvim_create_autocmd,第一个参数是一个或者多个事件字符串组成的 table,它的含义与 autocmd 中的事件相同,用的字符串也相同。第二个参数是一个表示属性的 table。 autocmd BufWritePost init.lua source % autocmd BufReadPost init.lua set path+=**/* augroup END autocmd BufWritePost init.lua source % autocmd BufReadPost init.lua set path+=**/* augroup END ]] end 我将这段代码放到了 lua/autocmd.lua 中。
pydiction_location = '/usr/share/vim/vim74/pydiction/complete-dict' let g:pydiction_menu_height = 20 autocmd FileType python set omnifunc=pythoncomplete#Complete autocmd FileType javascrīpt set omnifunc=javascriptcomplete #CompleteJS autocmd FileType html set omnifunc=htmlcomplete#CompleteTags autocmd FileType css set omnifunc =csscomplete#CompleteCSS autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags autocmd FileType php set omnifunc=phpcomplete#CompletePHP autocmd FileType c set omnifunc=ccomplete#Complete autocmd FileType
"配置python解释器 autocmd BufRead *.py set makeprg=python\ -c\ \"import\ py_compile,sys;\ sys.stderr=sys.stdout ;\ py_compile.compile(r'%')\" autocmd BufRead *.py set efm=%C\ %. %#,%Z%[%^\ ]%\\@=%m autocmd BufRead *.py nmap <F5> :! python %<CR> autocmd BufRead *.py nmap <F6> :make<CR> autocmd BufRead *.py copen "如果是py文件
FileType python set omnifunc=pythoncomplete#Complete autocmd FileType javascrīpt set omnifunc=javascriptcomplete #CompleteJS autocmd FileType html set omnifunc=htmlcomplete#CompleteTags autocmd FileType css set omnifunc =csscomplete#CompleteCSS autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags autocmd FileType php set omnifunc=phpcomplete#CompletePHP autocmd FileType c set omnifunc=ccomplete#Complete let g:pydiction_location colorscheme zenburn endif map <C-n> :NERDTreeToggle<CR> hi MatchParen ctermbg=DarkRed guibg=lightblue autocmd
CopyFromZ() autocmd! [ch] :call DeleteTrailingWS() "autocmd BufWrite *.cc :call DeleteTrailingWS() "autocmd BufWrite *.txt autocmd FileType tex inoremap $* \cdot autocmd FileType tex inoremap $i \item autocmd FileType script_id=850 autocmd FileType python set complete+=k~/.vim/tools/pydiction autocmd FileType python set *.py 0r ~/.vim/template/simple.py autocmd FileType html set shiftwidth=4 tabstop=4 expandtab autocmd
") autocmd FileType xml,html,c,cs,java,perl,shell,bash,cpp,python,vim,php,ruby set number autocmd FileType --<ESC>o<ESC>'>o--> autocmd FileType java,c,cpp,cs vmap <C-o> <ESC>'<o autocmd FileType html,text,php ,vim,c,java,xml,bash,shell,perl,python setlocal textwidth=100 autocmd Filetype html,xml,xsl source $ ") autocmd FileType xml,html,c,cs,java,perl,shell,bash,cpp,python,vim,php,ruby set number autocmd FileType --<ESC>o<ESC>'>o--> autocmd FileType java,c,cpp,cs vmap <C-o> <ESC>'<o autocmd FileType html,text,php
color ron " 设置背景主题 "color torte " 设置背景主题 "set guifont=Courier_New:h10:cANSI " 设置字体 "autocmd InsertLeave * se nocul " 用浅色高亮当前行 autocmd InsertEnter * se cul " 用浅色高亮当前行 set ruler """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" "新建.c,.h,.sh,.java文件,自动插入文件头 autocmd ") autocmd BufReadPost * \ if line("'\"") > 0 && line("'\"") <= line("$") | \ exe "normal g`\"" | \ endif endif "当打开vim且没有文件时自动打开NERDTree autocmd vimenter * if !
我们需要一个自己完全理解,并且足够简单的 ~/.vimrc autocmd Filetype c,cpp,hpp,python set nu " 只在打开特定格式文件时开启行号 autocmd Filetype c,cpp,hpp,python set numberwidth=1 " 当行数为个位数时,只占用一个字符位显示行号 syntax on " 打开语法高亮 autocmd FileType markdown """"""" """""""""""""""""""""""python"""""""""""""""""""""""""""""" set shiftwidth=4 set tabstop=4 autocmd FileType python set expandtab autocmd Filetype gitcommit setlocal spell textwidth=100 " for git commit Filetype c,cpp,hpp,python set nu " 只在打开特定格式文件时开启行号 autocmd Filetype c,cpp,hpp,python set numberwidth
smartim 插件依靠 Vim 的 autocmd 机制,就是进入命令模式时先把正在使用的输入法保存起来,然后切换到默认的输入法,进入插入模式时再切换为之前的输入法: augroup smartim autocmd! autocmd VimLeavePre * call Smartim_SelectDefault() autocmd InsertLeave * call Smartim_SelectDefault set timeoutlen=0 autocmd VimLeavePre * call Smartim_SelectDefault() autocmd InsertLeave * call Smartim_SelectDefault () autocmd InsertEnter * call Smartim_SelectSaved() augroup end 这样问题解决。
augroup fmt autocmd! autocmd BufWritePre * Neoformat augroup END 这段代码创建了一个自动化组并命名为fmt,用于将一组命令放在一起,方便管理。 我们首先使用autocmd! 然后用autocmd BufWritePre * Neoformat来完成在写buffer之前,对所有类型的文件都执行Neoformat命令。autocmd表示这是一条自动化命令。 " code format augroup fmt autocmd! " autocmd BufWritePre * undojoin | Neoformat autocmd BufWritePre * Neoformat augroup END " format
客户端 main.py import lib import autocmd lib.make_remote_dict() lib.scp_dict() lib.filedict.clear() compare_result_dict) lib.scp(compare_result_dict) lib.py #coding:utf-8 import hashlib import os import autocmd expect_list = ["yes", "assword"] expect_func = [input_yes,input_password] autocmd.Cmd remote_pwd) expect_list = ["yes", "assword"] expect_func = [input_yes, input_password] autocmd.Cmd print("time out") pobj.close() return 服务器端 main.py import lib import autocmd
NERDTreeShowBookmarks=1 let NERDTreeWinPos="left" " Automatically open a NERDTree if no files where specified autocmd argc() | NERDTree | endif " Close vim if the only window left open is a NERDTree autocmd bufenter * if completeopt=longest,menu "让Vim的补全菜单行为与一般IDE一致(参考VimTip1228)" set runtimepath+=~/.vim/bundle/YouCompleteMe autocmd argc() | NERDTree | endif " Close vim if the only window left open is a NERDTree autocmd bufenter * if completeopt=longest,menu "让Vim的补全菜单行为与一般IDE一致(参考VimTip1228)" set runtimepath+=~/.vim/bundle/YouCompleteMe autocmd
" Python文件 autocmd FileType python setlocal tabstop=4 shiftwidth=4 expandtab softtabstop=4 autocmd FileType python setlocal foldmethod=indent " Markdown文件 autocmd FileType markdown setlocal tabstop= 2 shiftwidth=2 expandtab softtabstop=2 autocmd FileType markdown setlocal wrap linebreak " JSON文件 autocmd FileType json setlocal tabstop=2 shiftwidth=2 expandtab softtabstop=2 autocmd FileType json call s:MkdirIfNotExists(expand('<afile>:p:h'))" 自动切换工作目录(方便 CtrlP 搜索项目文件)autocmd BufEnter * silent!
to let g:user_emmet_mode='a' "enable all function in all mode. let g:user_emmet_install_global=0 autocmd FileType javascript noremap <buffer> <c-f> :call JsBeautify()<cr> autocmd FileType json noremap <buffer > <c-f> :call JsonBeautify()<cr> autocmd FileType jsx noremap <buffer> <c-f> :call JsxBeautify()<cr> autocmd FileType html noremap <buffer> <c-f> :call HtmlBeautify()<cr> autocmd FileType css noremap <buffer > <c-f> :call CSSBeautify()<cr> "vimCSS3syntsx augroup VimCSS3Syntax autocmd!
syntax on set hlsearchendif" Only do this part when compiled with support for autocommands.if has("autocmd filetype plugin indent on " Put these in an autocmd group, so that we can delete them easily. autocmd FileType text setlocal textwidth=78 " When editing a file, always jump to the last known autocmd BufReadPost * \ if line("'\"") > 1 && line("'\"") <= line("$") | \ endif augroup ENDelse set autoindent " always set autoindenting onendif " has("autocmd
syntax on set hlsearch endif" Only do this part when compiled with support for autocommands. if has("autocmd filetype plugin indent on " Put these in an autocmd group, so that we can delete them easily. autocmd FileType text setlocal textwidth=78 " When editing a file, always jump to the last known cursor autocmd BufReadPost * \ if line("'\"") > 1 && line("'\"") <= line("$") | \ exe "normal! \ endif augroup ENDelse set autoindent " always set autoindenting on endif " has("autocmd
call append(5, "__author__ = 'Jiwen Zheng'") normal G normal o normal o endf "tab=4空格 autocmd strftime('%Y-%m-%d %T', localtime())) call append(2, "# author: 郑集文") normal G normal o endf autocmd
””””””””””””””””””””””””””””””””””””””””””””””””””””””” ” 只在下列文件类型被侦测到的时候显示行号,普通文本文件不显示 if has(“autocmd ”) autocmd FileType xml,html,c,cs,java,perl,shell,bash,cpp,python,vim,php,ruby set number autocmd FileType –<ESC>o<ESC>’>o–> autocmd FileType java,c,cpp,cs vmap <C-o> <ESC>'<o autocmd FileType html,text,php,vim ,c,java,xml,bash,shell,perl,python setlocal textwidth=100 ” autocmd Filetype html,xml,xsl source ” F5
set guioptions-=m "不显示菜单 set guioptions-=T "不显示工具栏 set guifont=consolas\ 10 endif if has("autocmd "自动检测文件类型,并载入相关的规则文件 filetype plugin on filetype indent on "智能缩进,使用4空格,使用全局的了 "autocmd FileType python setlocal et | setlocal sta | setlocal sw=4 "autocmd FileType c setlocal et | setlocal sta | setlocal sw=4 "autocmd FileType h setlocal et | setlocal sta | setlocal sw=4 endif 二、vim python