第一视角的VIM菜鸟学习(二)

本文详细介绍如何配置Vim编辑器以提高编程效率。包括设置编码、语法高亮、自动缩进等,还提供了编译和运行多种编程语言的脚本。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

配置VIM使它更适合自己

你安装好vim之后会在目录下有一个vim的配置文件,叫做vimrc。linux在 /etc/vim/vimrc。我是windows在/Vim的根目录叫_vimrc

而且我发现还有一个文件叫vimrc_example既然如此我们就改他它算了。

对于我一句也看不懂。。。。。。

 _vimrc文件内容:

set nocompatible
source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
behave mswin

set diffexpr=MyDiff()
function MyDiff()
  let opt = '-a --binary '
  if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
  if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
  let arg1 = v:fname_in
  if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
  let arg2 = v:fname_new
  if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
  let arg3 = v:fname_out
  if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
  let eq = ''
  if $VIMRUNTIME =~ ' '
    if &sh =~ '\<cmd'
      let cmd = '""' . $VIMRUNTIME . '\diff"'
      let eq = '"'
    else
      let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
    endif
  else
    let cmd = $VIMRUNTIME . '\diff'
  endif
  silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eq
endfunctio

example:

" An example for a vimrc file.
"
" Maintainer:	Bram Moolenaar <Bram@vim.org>
" Last change:	2008 Dec 17
"
" To use it, copy it to
"     for Unix and OS/2:  ~/.vimrc
"	      for Amiga:  s:.vimrc
"  for MS-DOS and Win32:  $VIM\_vimrc
"	    for OpenVMS:  sys$login:.vimrc

" When started as "evim", evim.vim will already have done these settings.
if v:progname =~? "evim"
  finish
endif

" Use Vim settings, rather than Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
set nocompatible

" allow backspacing over everything in insert mode
set backspace=indent,eol,start

if has("vms")
  set nobackup		" do not keep a backup file, use versions instead
else
  set backup		" keep a backup file
endif
set history=50		" keep 50 lines of command line history
set ruler		" show the cursor position all the time
set showcmd		" display incomplete commands
set incsearch		" do incremental searching

" For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries
" let &guioptions = substitute(&guioptions, "t", "", "g")

" Don't use Ex mode, use Q for formatting
map Q gq

" CTRL-U in insert mode deletes a lot.  Use CTRL-G u to first break undo,
" so that you can undo CTRL-U after inserting a line break.
inoremap <C-U> <C-G>u<C-U>

" In many terminal emulators the mouse works just fine, thus enable it.
if has('mouse')
  set mouse=a
endif

" 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")
  syntax on
  set hlsearch
endif

" Only do this part when compiled with support for autocommands.
if has("autocmd")

  " Enable file type detection.
  " Use the default filetype settings, so that mail gets 'tw' set to 72,
  " 'cindent' is on in C files, etc.
  " Also load indent files, to automatically do language-dependent indenting.
  filetype plugin indent on

  " Put these in an autocmd group, so that we can delete them easily.
  augroup vimrcEx
  au!

  " For all text files set 'textwidth' to 78 characters.
  autocmd FileType text setlocal textwidth=78

  " When editing a file, always jump to the last known cursor position.
  " Don't do it when the position is invalid or when inside an event handler
  " (happens when dropping a file on gvim).
  " Also don't do it when the mark is in the first line, that is the default
  " position when opening a file.
  autocmd BufReadPost *
    \ if line("'\"") > 1 && line("'\"") <= line("$") |
    \   exe "normal! g`\"" |
    \ endif

  augroup END

else

  set autoindent		" always set autoindenting on

endif " has("autocmd")

" Convenient command to see the difference between the current buffer and the
" file it was loaded from, thus the changes you made.
" Only define it when not defined already.
if !exists(":DiffOrig")
  command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
		  \ | wincmd p | diffthis
endi

好吧我们开始对他修改修改之前,先看看效果。

好吧没什么变化

这里提供一个范例

" An example for a vimrc file.
"
" Maintainer:	Bram Moolenaar <Bram@vim.org>
" Last change:	2008 Dec 17
"
" To use it, copy it to
"     for Unix and OS/2:  ~/.vimrc
"	      for Amiga:  s:.vimrc
"  for MS-DOS and Win32:  $VIM\_vimrc
"	    for OpenVMS:  sys$login:.vimrc

" When started as "evim", evim.vim will already have done these settings.
if v:progname =~? "evim"
  finish
endif

" Use Vim settings, rather than Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
set nocompatible

" allow backspacing over everything in insert mode
set backspace=indent,eol,start

if has("vms")
  set nobackup		" do not keep a backup file, use versions instead
else
  set backup		" keep a backup file
endif
set history=50		" keep 50 lines of command line history
set ruler		" show the cursor position all the time
set showcmd		" display incomplete commands
set incsearch		" do incremental searching

" For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries
" let &guioptions = substitute(&guioptions, "t", "", "g")

" Don't use Ex mode, use Q for formatting
map Q gq

" CTRL-U in insert mode deletes a lot.  Use CTRL-G u to first break undo,
" so that you can undo CTRL-U after inserting a line break.
inoremap <C-U> <C-G>u<C-U>

" In many terminal emulators the mouse works just fine, thus enable it.
if has('mouse')
  set mouse=a
endif

" 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")
  syntax on
  set hlsearch
endif

" Only do this part when compiled with support for autocommands.
if has("autocmd")

  " Enable file type detection.
  " Use the default filetype settings, so that mail gets 'tw' set to 72,
  " 'cindent' is on in C files, etc.
  " Also load indent files, to automatically do language-dependent indenting.
  filetype plugin indent on

  " Put these in an autocmd group, so that we can delete them easily.
  augroup vimrcEx
  au!

  " For all text files set 'textwidth' to 78 characters.
  autocmd FileType text setlocal textwidth=78

  " When editing a file, always jump to the last known cursor position.
  " Don't do it when the position is invalid or when inside an event handler
  " (happens when dropping a file on gvim).
  " Also don't do it when the mark is in the first line, that is the default
  " position when opening a file.
  autocmd BufReadPost *
    \ if line("'\"") > 1 && line("'\"") <= line("$") |
    \   exe "normal! g`\"" |
    \ endif

  augroup END

else

  set autoindent		" always set autoindenting on

endif " has("autocmd")

" Convenient command to see the difference between the current buffer and the
" file it was loaded from, thus the changes you made.
" Only define it when not defined already.
if !exists(":DiffOrig")
  command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
		  \ | wincmd p | diffthis
endif

" 配色方案
colo evening 

"编码设置
set enc=utf-8
set fencs=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936

"设置菜单语言
set langmenu=zh_CN.UTF-8

"导入删除菜单脚本,删除乱码的菜单
source $VIMRUNTIME/delmenu.vim

"导入正常的菜单脚本
source $VIMRUNTIME/menu.vim

"设置提示信息语言
language messages zh_CN.utf-8

"字体设置
set guifont=Monaco:h12:cANSI

"语法高亮
set syntax=on

"自动缩进
set autoindent

"C语言方式缩进
set cindent

"智能缩进
set smartindent
"统一缩进为4
set softtabstop=4
set shiftwidth=4

"默认窗口大小
set lines=30 columns=82

"自动换行
set wrap

"整词换行
set linebreak

"显示行号
set number

"高亮显示匹配的括号
set showmatch

"搜索逐字符高亮和实时搜索
set hlsearch
set incsearch

"匹配括号高亮的时间(单位是十分之一秒)
set matchtime=5

"显示括号配对情况
set showmatch

"代码折叠
set fdm=indent

"选择代码折叠类型
set foldmethod=syntax

"禁止自动折叠
set foldlevel=100

"命令行(在状态行下)的高度,默认为1,这里是2
set cmdheight=2

"历史记录数
set history=1000

"侦测文件类型
filetype on

"为特定文件类型载入相关缩进格式
filetype indent on

"为特定的文件类型载入对应的插件
filetype plugin on
filetype plugin indent on

"不与vi兼容
set nocp

"vim目录树插件
map <F10> :NERDTreeToggle<CR>

"保存全局变量
set viminfo+=!

"带有如下符号的单词不要被换行分割
set iskeyword+=_,$,@,%,#,-

"字符间插入的像素行数目
set linespace=0

"增强模式中的命令行自动完成操作
set wildmenu

"PHP语法提示
autocmd FileType php set omnifunc=phpcomplete

"禁止生成临时文件
set nobackup
set noswapfile

"设置退格键可用
set backspace=2

"快捷键自定义
map <C-s> :w<CR>
imap <C-s> <C-o>:w<CR>

"隐藏工具栏,可用快捷键F2切换
"set guioptions-=T
"map <silent> <F2> :if &guioptions =~# ‘T’ <Bar>
"set guioptions-=T <Bar>
"else <Bar>
"set guioptions+=T <Bar>
"endif<CR>

"能够漂亮地显示.NFO文件
set encoding=utf-8
function! SetFileEncodings(encodings)
let b:myfileencodingsbak=&fileencodings
let &fileencodings=a:encodings
endfunction
function! RestoreFileEncodings()
let &fileencodings=b:myfileencodingsbak
unlet b:myfileencodingsbak
endfunction
au BufReadPre *.nfo call SetFileEncodings(‘cp437′)|set ambiwidth=single
au BufReadPost *.nfo call RestoreFileEncodings()
"F5编译和运行C程序,F6编译和运行C++程序
"C的编译和运行
map <F5> :call CompileRunGcc()<CR>
func! CompileRunGcc()
exec “w”
exec “!gcc -Wall % -o %<”
exec “! ./%<”
endfunc

"C++的编译和运行
map <F6> :call CompileRunGpp()<CR>
func! CompileRunGpp()
exec “w”
exec “!g++ -Wall % -o %<”
exec “! ./%<”
endfunc

"Gvim标签定制
set guitablabel=%{ShortTabLabel()}
function ShortTabLabel ()
let bufnrlist = tabpagebuflist (v:lnum)
let label = bufname (bufnrlist[tabpagewinnr (v:lnum) -1])
let filename = fnamemodify (label, ‘:t’)
return filename
endfunction

"######### 一键保存和编译 ######### “
"编译C源文件
func! CompileGcc()
exec “w”
let compilecmd=”!gcc -Wall -std=c99 ”
let compileflag=”-o %<”
exec compilecmd."% “.compileflag
endfunc

"编译C++源文件
func! CompileCpp()
exec “w”
let compilecmd=”!g++ -Wall ”
let compileflag=”-o %<”
exec compilecmd."% “.compileflag
endfunc

"编译&链接Go源文件
func! CompileGo()
exec “w”
exec “!8g %”
exec “!8l -o %<.exe %<.8″
endfunc

"编译Haskell源文件
func! CompileHaskell()
exec “w”
let compilecmd=”!ghc –make ”
let compileflag=”-o %<”
exec compilecmd."% “.compileflag
endfunc

"编译Java源文件
func! CompileJava()
exec “w”
exec “!javac %”
endfunc

"编译C#源文件
func! CompileCs()
exec “w”
exec “!csc %”
endfunc

"编译Gas源文件
func! CompileGas()
exec “w”
exec “!gcc -Wall -ggdb -o %< %”
endfunc

"运行Shell源文件
func! RunShell()
exec “w”
exec “!sh %”
endfunc

"运行Lua源文件
func! RunLua()
exec “w”
exec “!lua %”
endfunc

"运行Perl源文件
func! RunPerl()
exec “w”
exec “!perl %”
endfunc

"运行Python源文件
func! RunPython()
exec “w”
exec “!python %”
endfunc

"运行Ruby源文件
func! RunRuby()
exec “w”
exec “!ruby %”
endfunc

"根据文件类型自动选择相应的编译函数
func! CompileCode()
exec “w”
if &filetype == “c”
exec “call CompileGcc()”
elseif &filetype == “cpp”
exec “call CompileCpp()”
elseif &filetype == “go”
exec “call CompileGo()”
elseif &filetype == “haskell”
exec “call CompileHaskell()”
elseif &filetype == “java”
exec “call CompileJava()”
elseif &filetype == “cs”
exec “call CompileCs()”
elseif &filetype == “asm”
exec “call CompileGas()”
elseif &filetype == “sh”
exec “call RunShell()”
elseif &filetype == “lua”
exec “call RunLua()”
elseif &filetype == “perl”
exec “call RunPerl()”
elseif &filetype == “python”
exec “call RunPython()”
elseif &filetype == “ruby”
exec “call RunRuby()”
endif
endfunc

"运行可执行文件
func! RunResult()
exec “w”
if &filetype == “c”
exec “! %<”
elseif &filetype == “cpp”
exec “! %<”
elseif &filetype == “go”
exec “! %<”
elseif &filetype == “haskell”
exec “! %<”
elseif &filetype == “java”
exec “!java %<”
elseif &filetype == “cs”
exec “! %<”
elseif &filetype == “asm”
exec “! %<”
elseif &filetype == “sh”
exec “!sh %<.sh”
elseif &filetype == “lua”
exec “!lua %<.lua”
elseif &filetype == “perl”
exec “!perl %<.pl”
elseif &filetype == “python”
exec “!python %<.py”
elseif &filetype == “ruby”
exec “!ruby %<.rb”
endif
endfunc




内容概要:本文档详细介绍了Analog Devices公司生产的AD8436真均方根-直流(RMS-to-DC)转换器的技术细节及其应用场景。AD8436由三个独立模块构成:轨到轨FET输入放大器、高动态范围均方根计算内核和精密轨到轨输出放大器。该器件仅体积小巧、功耗低,而且具有广泛的输入电压范围和快速响应特性。文档涵盖了AD8436的工作原理、配置选项、外部组件选择(如电容)、增益调节、单电源供电、电流互感器配置、接地故障检测、三相电源监测等方面的内容。此外,还特别强调了PCB设计注意事项和误差源分析,旨在帮助工程师更好地理解和应用这款高性能的RMS-DC转换器。 适合人群:从事模拟电路设计的专业工程师和技术人员,尤其是那些需要精确测量交流电信号均方根值的应用开发者。 使用场景及目标:①用于工业自动化、医疗设备、电力监控等领域,实现对交流电压或电流的精准测量;②适用于手持式数字万用表及其他便携式仪器仪表,提供高效的单电源解决方案;③在电流互感器配置中,用于检测微小的电流变化,保障电气安全;④应用于三相电力系统监控,优化建立时间和转换精度。 其他说明:为了确保最佳性能,文档推荐使用高质量的电容器件,并给出了详细的PCB布局指导。同时提醒用户关注电介质吸收和泄漏电流等因素对测量准确性的影响。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值