我的vim/gvim配置.vimrc

本文永久地址:https://my.oschina.net/bysu/blog/1547768

1.下载:

ftp://ftp.vim.org/pub/vim/pc/vim80-586rt.zip

ftp://ftp.vim.org/pub/vim/pc/gvim80-586.zip

2.把两个压缩文件里面的内容都解压,放到一起(vim),目录结构如下图

3.把目录中的vimrc_example.vim文件重命名为_vimrc,并把下面的配置覆盖进去即可

" An example for a vimrc file.
"
" Maintainer:	Bram Moolenaar <Bram@vim.org>
" Last change:	2016 Jul 28
"
" 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

" Get the defaults that most users want.
source $VIMRUNTIME/defaults.vim

if has("vms")
  set nobackup		" do not keep a backup file,use versions instead
else
  set backup		" keep a backup file (restore to previous version)
  if has('persistent_undo')
    set undofile	" keep an undo file (undo changes after closing)
  endif
endif

if &t_Co > 2 || has("gui_running")
  " Switch on highlighting the last used search pattern.
  set hlsearch
endif

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

  " 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

  augroup END

else

  set autoindent		" always set autoindenting on

endif " has("autocmd")

" Add optional packages.
"
" The matchit plugin makes the % command work better,but it is not backwards
" compatible.
if has('syntax') && has('eval')
  packadd matchit
endif

"==============================去掉启动提示文案:帮助乌干达儿童之类的提示
set shortmess=atI 

"===============================设置主题
colorscheme darkblue

"===============================设置字体大小
set guifont=Consolas:h12  "h12字体大小,bh12中的b表示黑体
"set guifontwide=Microsoft/ YaHei:h12

"=================开启语法高亮提示
syntax on

"==============缩进
set cin nu ts=4 sw=4 sts=4 et acd noswapfile nobackup
set bs=eol,start,indent

"==================隐藏菜单、工具、滚动条============================
":set guioptions-=m  "remove menu bar
":set guioptions-=T  "remove toolbar
":set guioptions-=r  "remove right-hand scroll bar
":set guioptions-=L  "remove left-hand scroll bar
if has("gui_running")
au GUIEnter * simalt ~x " 窗口启动时自动最大化
set guioptions-=m " 隐藏菜单栏
set guioptions-=T " 隐藏工具栏
"set guioptions-=L " 隐藏左侧滚动条
set guioptions-=r " 隐藏右侧滚动条
set guioptions-=b " 隐藏底部滚动条
set showtabline=0 " 隐藏Tab栏
endif

"==========================中文显示乱码
set encoding=utf-8
set fileencodings=utf-8,chinese,latin-1
if has("win32")
set fileencoding=chinese
else
set fileencoding=utf-8
endif
"解决菜单乱码
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
"解决consle输出乱码
language messages zh_CN.utf-8

"================================符号自动补全
inoremap ' ''<ESC>i
inoremap " ""<ESC>i
inoremap ( ()<ESC>i
inoremap [ []<ESC>i
inoremap < <><ESC>i
inoremap { {<CR>}<ESC>O
inoremap ) <c-r>=ClosePair(')')<CR>
inoremap > <c-r>=ClosePair('>')<CR>
inoremap } <c-r>=ClosePair('}')<CR>
inoremap ] <c-r>=ClosePair(']')<CR>

function! ClosePair(char)
  if getline('.')[col('.') - 1] == a:char
    return "\<Right>"
  else
    return a:char
  endif
endf

"=================================设置跳出自动补全的括号
func SkipPair()  
    let str = getline('.')[col('.')-1]
    if str == ')' || str == ']' || str == '"' || str == "'" || str == '}'
	return "\<Right>"
    elseif strpart(getline('.'),col('.')-1)=~'^\s*$'
        return "\<Tab>"  
    else  
        return "\<C-N>"  
    endif  
endfunc  
 " 将tab键绑定为跳出括号  
 inoremap <TAB> <c-r>=SkipPair()<CR>

"=====================小写转换大写
inoremap <C-u> <esc>gUiwea

"=====================插入模式移动光标
inoremap <M-k> <Up>
inoremap <M-j> <Down>
inoremap <M-h> <Left>
inoremap <M-l> <Right>
inoremap <M-a> <Home>
inoremap <M-e> <End>

" Rubout word / line and enter insert mode
" use <Esc><Right> instead of <C-o>
inoremap <C-w> <Esc>dbcl
" delete
inoremap <C-u> <Esc>d0cl
inoremap <C-k> <Esc><Right>C
inoremap <C-d> <Esc><Right>s
inoremap <C-d> <C-o>de
inoremap <M-d> <C-o>de

"===================编译java、c、c++、python以及sh脚本
"=======================按F5进行编译运行windows,Linux下需在运行的命令里面加当前目录./
map <F5> :call CompileRunGcc()<CR>
imap <F5> <ESC>:call CompileRunGcc()<CR>
func! CompileRunGcc()
    exec "w"
    exec "cd %:p:h"
    if &filetype == 'c'
        exec "!g++ % -o %<"
        exec "! %<"
    elseif &filetype == 'cpp'
        exec "!g++ -std=c++11 -O2 % -o %<"
        exec "! %<"
    elseif &filetype == 'java' 
        exec "!javac %<" 
        exec "!java %<"
	elseif &filetype == 'py'
		exec "!python %<"
    elseif &filetype == 'sh'
        :!./%
    endif
endfunc

"======================<F9>gdb调试c或c++  
map <F9> :call Debug()<CR>
imap <F9> :call Debug()<CR>    
func!  Debug() 
	exec "w"
    exec "cd %:p:h"
    if &filetype == 'c'
        exec "!gcc % -g -o %< -gstabs+"
        exec "!gdb %<"
    elseif &filetype == 'cpp'
        exec "!g++ % -g -o %< -gstabs+"
        exec "!gdb %<"
endfunc   


"=====================AIT+/进行注释
inoremap <M-/> <Home>//
nmap <M-/> <Home>i//<ESC>

"=====================复制粘贴
map <C-A> ggVG                     " 映射全选 ctrl+a
map! <C-A> <Esc>ggVGY
map <C-c> "+y                      " 映射复制到系统剪切板
map! <C-c> "+y                      " 映射复制到系统剪切板
nmap <C-v> "+gp                    " 映射粘贴
imap <C-v> <Esc>"+gp

4.在环境变量path里面加入vim目录的绝对路径,譬如我的

D:\bysu\Application\vim\

注意:如果path里面还有其他路径,且vim是放在最后面,需要输入分号;然后加上你的路径。如:

;D:\bysu\Application\vim\

5.打开运行(Ctrl+r),输入gvim,回车即可打开gvim编辑器(可以把vim目录的中gvim.exe重命名为vi.exe,然后输入vi,回车即可打开gvim编辑器)

linux的vim配置文件

" All system-wide defaults are set in $VIMRUNTIME/debian.vim and sourced by
" the call to :runtime you can find below.  If you wish to change any of those
" settings,you should do it in this file (/etc/vim/vimrc),since debian.vim
" will be overwritten everytime an upgrade of the vim packages is performed.
" It is recommended to make changes after sourcing debian.vim since it alters
" the value of the 'compatible' option.

" This line should not be removed as it ensures that various options are
" properly set to work with the Vim-related packages available in Debian.
runtime! debian.vim

" Vim will load $VIMRUNTIME/defaults.vim if the user does not have a vimrc.
" This happens after /etc/vim/vimrc(.local) are loaded,so it will override
" any settings in these files.
" If you don't want that to happen,uncomment the below line to prevent
" defaults.vim from being loaded.
" let g:skip_defaults_vim = 1

" Uncomment the next line to make Vim more Vi-compatible
" NOTE: debian.vim sets 'nocompatible'.  Setting 'compatible' changes numerous
" options,so any other options should be set AFTER setting 'compatible'.
"set compatible

" Vim5 and later versions support syntax highlighting. Uncommenting the next
" line enables syntax highlighting by default.
 syntax on

" If using a dark background within the editing area and syntax highlighting
" turn on this option as well
"set background=dark

" Uncomment the following to have Vim jump to the last position when
" reopening a file
"if has("autocmd")
"  au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
"endif

" Uncomment the following to have Vim load indentation rules and plugins
" according to the detected filetype.
"if has("autocmd")
"  filetype plugin indent on
"endif

" The following are commented out as they cause vim to behave a lot
" differently from regular Vi. They are highly recommended though.
"set showcmd		" Show (partial) command in status line.
"set showmatch		" Show matching brackets.
"set ignorecase		" Do case insensitive matching
"set smartcase		" Do smart case matching
"set incsearch		" Incremental search
"set autowrite		" Automatically save before commands like :next and :make
"set hidden		" Hide buffers when they are abandoned
"set mouse=a		" Enable mouse usage (all modes)

" Source a global configuration file if available
if filereadable("/etc/vim/vimrc.local")
  source /etc/vim/vimrc.local
endif
set shortmess=atI 

"===============================设置主题
colorscheme darkblue

""===============================设置字体大小
set guifont=Consolas:h12  "h12字体大小,bh12中的b表示黑体
"set guifontwide=Microsoft/ YaHei:h12

""=================开启语法高亮提示
syntax on

"==============缩进
set cin nu ts=4 sw=4 sts=4 et acd noswapfile nobackup
set bs=eol,indent

"==================隐藏菜单、工具、滚动条============================
"set guioptions-=m  "remove menu bar
"set guioptions-=T  "remove toolbar
"set guioptions-=r  "remove right-hand scroll bar
":set guioptions-=L  "remove left-hand scroll bar
if has("gui_running")
	au GUIEnter * simalt ~x " 窗口启动时自动最大化
	set guioptions-=m " 隐藏菜单栏
	set guioptions-=T " 隐藏工具栏
	"set guioptions-=L " 隐藏左侧滚动条
	"set guioptions-=r " 隐藏右侧滚动条
	"set guioptions-=b " 隐藏底部滚动条
	"set showtabline=0 " 隐藏Tab栏
endif
"
""==========================中文显示乱码
set encoding=utf-8
set fileencodings=utf-8,latin-1
if has("win32")
	set fileencoding=chinese
else
	set fileencoding=utf-8
endif
"解决菜单乱码
"source $VIMRUNTIME/delmenu.vim
"source $VIMRUNTIME/menu.vim
""解决consle输出乱码
language messages zh_CN.utf-8

"================================符号自动补全
""inoremap ' ''<ESC>i
""inoremap " ""<ESC>i
""inoremap ( ()<ESC>i
""inoremap [ []<ESC>i
""inoremap < <><ESC>i
""inoremap { {<CR>}<ESC>O
inoremap ( ()<ESC>i
inoremap ) <c-r>=ClosePair(')')<CR>
inoremap { {}<ESC>i
inoremap } <c-r>=ClosePair('}')<CR>
inoremap [ []<ESC>i
inoremap ] <c-r>=ClosePair(']')<CR>
inoremap < <><ESC>i
inoremap > <c-r>=ClosePair('>')<CR>
inoremap " ""<ESC>i
inoremap ' ''<ESC>i

function! ClosePair(char)
  if getline('.')[col('.') - 1] == a:char
      return "\<Right>"
  else
      return a:char
  endif
endf

"=================================设置跳出自动补全的括号
func SkipPair()
	let str = getline('.')[col('.')-1]'')]'')
	if str == ')' || str == ']' || str == '"' || str == "'" || str == '}'
		return "\<Right>"
	elseif strpart(getline('.'),col('.')-1)=~'^\s*$'
		return "\<Tab>"
	else
		return "\<C-N>"
	endif
endfunc

" 将tab键绑定为跳出括号  
inoremap <TAB> <c-r>=SkipPair()<CR>

"=====================小写转换大写
inoremap <C-u> <esc>gUiwea

""=====================插入模式移动光标
inoremap <C-k> <Up>
inoremap <C-j> <Down>
inoremap <C-h> <Left>
inoremap <C-l> <Right>
inoremap <C-a> <Home>
inoremap <C-e> <End>
  
"Rubout word / line and enter insert mode
" use <Esc><Right> instead of <C-o>
inoremap <C-w> <Esc>dbcl
" delete
inoremap <C-u> <Esc>d0cl
inoremap <M-k> <Esc><Right>C
inoremap <C-d> <Esc><Right>s
inoremap <C-d> <C-o>de
inoremap <M-d> <C-o>de

"===================编译java、c、c++、python以及sh脚本
""=======================按F5进行编译运行windows,Linux下需在运行的命令里面加当前目录./
map <F5> :call CompileRunGcc()<CR>
imap <F5> <ESC>:call CompileRunGcc()<CR>
func! CompileRunGcc()
	exec "w"
	exec "cd %:p:h"
	if &filetype == 'c'
	    exec "!g++ % -o %<"
            exec "! ./%<"
	elseif &filetype == 'cpp'
	    exec "!g++ -std=c++11 -O2 % -o %<"
            exec "! ./%<"
        elseif &filetype == 'java' 
            exec "!javac %" 
            exec "!java %<"
	elseif &filetype == 'py'
	    exec "!python %<"
    elseif &filetype == 'sh'  
	    :!./%
    endif
endfunc

"======================<F9>gdb调试c或c++  
map <F9> :call Debug()<CR>
imap <F9> :call Debug()<CR>    
func!  Debug() 
    exec "w"
    exec "cd %:p:h"
    if &filetype == 'c'
        exec "!gcc % -g -o %< -gstabs+"
        exec "!gdb ./%<"
    elseif &filetype == 'cpp'
        exec "!g++ % -g -o %< -gstabs+"
        exec "!gdb ./%<"
endfunc  

"=====================复制粘贴
map <C-A> ggVG                     " 映射全选 ctrl+a
map! <C-A> <Esc>ggVGY
map <C-c> "+y                      " 映射复制到系统剪切板
map! <C-c> "+y                      " 映射复制到系统剪切板
"nmap <C-v> "+gp                    " 映射粘贴
"imap <C-v> <Esc>"+gp

参考:

http://vim.wikia.com/wiki/Hide_toolbar_or_menus_to_see_more_text

https://blog.alswl.com/2012/04/vim-emacs-key-binding/

http://blog.csdn.net/lalor/article/details/7437258

http://www.pythonclub.org/vim/map-basic

https://segmentfault.com/q/1010000004870420

https://www.w3cschool.cn/vim/drcj1pu5.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


解决方案:解决linux下vim乱码的情况:(修改vimrc的内容)全局的情况下:即所有用户都能用这个配置文件地址:/etc/vimrc在文件中添加:setfileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936settermencoding=utf-8setencoding=utf-8如果只修改个人的vim配置情况:需要把/etc/
Linuxvi/vim所有的UnixLike系统都会内建vi文书编辑器,其他的文书编辑器则不一定会存在。但是目前我们使用比较多的是vim编辑器。vim具有程序编辑的能力,可以主动的以字体颜色辨别语法的正确性,方便程序设计。相关文章:史上最全Vim快捷键键位图—入门到进阶什么是vim
      vim正则匹配:空行:/^$/  /^[\t]*$/注释行:/^#/ /^[\t]*#/:1,$s/\([Rr]\)oot/\1ename/:1,$s/\(square\)and\(fair\)/\2and\1/ 
$select-editorSelectaneditor.Tochangelater,run'select-editor'.1./bin/ed2./binano<----easiest3./usr/bin/code4./usr/bin/vim.basic5./usr/bin/vim.tinyChoose1-5[2]:4
上次手贱忘了保存,这次就简单做个备忘吧,把踩过的坑记一下预览图安装工具:u盘、manjarokdeminimal20.0.3、win32DiskImager提取码:qt9f进bios、选择u盘启动、改语言、改时区、挂载分区(文件系统ext4、在200M左右的一个FAT分区上挂载/boot/efi)、安装安装很简单,按提示
Linux之文本编译器小结vim的优势所有的UNIX-LIKE习通都会内置vi文本编译器,其他的文本编译器则不一定存在很多软件的编译接口都会主动调用vivim有很强的程序编译能力,可以主动的一字体颜色辨别语法的正确性,方便程序设计因为程序简单,编译速度相当快vi的使用一般命令模
主机名字太长,怎么修改?  1.sudovim/etc/hostname 修改内容为wel,  本地主机名 2.sudovim/etc/hosts      修改主机名为wel,用于网络连接中主机名的识别 3.reboot 
目录#事故现场#事故原因#解决方法方法一:使用notepad转换方法二:使用vscode转换方法三:使用vim转换#参考#事故现场执行shell脚本文件,报错::notfound.sh:6:coreinstall.sh:查看脚本文件第6行,发现是空行;#事故原因window下的换行是回车符+换行符,也就是\r\n,而unix下是换行符\n
1、保存并退出linux下安装好了vim以及gcc后,我们开始新建一个c文件,例如:vimtest.c之后进入vim的编辑框中,点击i进入插入模式,开始编辑程序,当你编写好自己的程序之后,按Esc退出插入编辑状态,然后输入冒号加wq,点击Enter即可,完整的命令如下:wq如下图:  退出后,如果想要编译
概述使用VIM作简单字数统计背景想做一个简单的字数统计环境OSwin10shellmintty-2.9.41.需求概述需求需求统计文段内字符的数量支持自定义字符集2.方案1:vim自带统计概述vim自带方案操作定位到文段内某行vi
经典版下面这个键位图应该是大家最常看见的经典版了。对应的简体中文版其实经典版是一系列的入门教程键位图的组合结果,下面是不同编辑模式下的键位图。 
ssh是一个安全连接协议。作用两个:1.远程连接协议,2.远程文件传输协议协议默认端口为:22。 修改默认端口,再到ssh服务配置文件位置  vim/etc/ssh/ssh_config这条命令就可以修改了。按下ESC键,再输入:x 也可以退出vim。(和:q! 相同)修改注意:1.端口号在0-65535之间。2.别人
Vim是一个类似于Vi的著名的功能强大、高度可定制的文本编辑器,在Vi的基础上改进和增加了很多特性。VIM是自由软件。Vim普遍被推崇为类Vi编辑器中最好的一个,事实上真正的劲敌来自Emacs的不同变体。1999年Emacs被选为Linuxworld文本编辑分类的优胜者,Vim屈居第二。但在2000年2月Vim赢
在Vim中,有时需要将tab转换成space。使用ret命令(replacetab)。[range]ret[ab]![new-tabstop]举例:将第一行到文件尾的tab转换成space,每个tab用4个space替代。:setexpandtab:%ret!4如果没有给定4,则用当前的tab宽度设定替换为space。 相关配置文件命令::settabstop=4设
分屏命令记不得文件名就输入.可浏览文件命令英文功能:sp[文件名]split横向分屏:vsp[文件名]verticalsplit纵向分屏    切换分屏窗口先按Ctrlw切换窗口命令英文功能 wwindow切换下一个窗口 rreverse互换窗口 c
1查看ctags支持的语言ctags--list-languages2查看语言和扩展名的对应关系ctags--list-maps 3对当前目录下所有ctags支持的语言格式文件生成tagsctags-R*缺点很明显,tags会非常大,tags生成会非常慢,而且代码跳转会卡顿。4只对特定文件生成tagsctags`find-name"*.h"`ct
vim基本命令 $vimtutor可以查看基本的vim操作1h(left)j(down)k(up)l(right)q!wqi:insertbeforethecursor(insert)插队嘛,肯定在光标前面A:appendaftertheline(appending)2dw:删除一个单词,保留光标前面部分d$:删除光标之后的同行
~/.vimrc内容如下:setnocompatiblefiletypeoffsetrtp+=~/.vim/bundle/Vundle.vimcallvundle#begin()Plugin'VundleVim/Vundle.vim'Plugin'tpope/vim-fugitive'Plugin'tpope/vim-unimpaired'Plugin'tpope/vim-repeat'Plu
程序:硬盘静态的代码  占用磁盘空间进程:内存运行计算的代码 占用CPU运行内存父进程与子进程  树型结构进程唯一标识: PID僵尸进程找到父进程杀掉  孤儿进程疯狂要内存  危害大 pstree [选项]-a显示完整命令行   -p 查看PID [PID或用户
~/.vimrc"Configurationfileforvimsetmodelines=0 "CVE-2007-2438setnumber"setrelativenumber"显示相对行号(这个非常重要,慢慢体会)setcursorlinesetcursorcolumnsetrulersetscrollbindsetencoding=utf-8colormolokaisyntaxon"开启