我的vim/gvim配置.vimrc-程序员宅基地

技术标签: java  开发工具  c/c++  

本文永久地址: 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 <[email protected]>
" 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('.'),0,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,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 ( ()<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('.'),0,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

 

转载于:https://my.oschina.net/bysu/blog/1547768

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/weixin_34210740/article/details/91505999

智能推荐

十一届蓝桥杯c组--省一国二_蓝桥杯c组国2是什么水平-程序员宅基地

文章浏览阅读977次。文章目录专科生咋样准备蓝桥杯以下我对于《数据结构与算法》的认识对于专科生 零基础怎样去备赛蓝桥杯一些细节 要注意专科生咋样准备蓝桥杯我是一名专科生 和大多数人一样 大学零基础开始,对着计算机充满兴趣,对各种竞赛好奇,对新鲜技术的渴望。这是我自己备赛十一届蓝桥杯省赛和国赛的过程 感兴趣可以看一看 真的很ruo -->备赛心得以下我对于《数据结构与算法》的认识数据结构与算法是从事这个行业必须会的东西,大厂的金钥匙之一。竟然选择以后从事这个行业 那么就一定要学习数据结构与算法,而竞赛就很直_蓝桥杯c组国2是什么水平

银行秋招笔试计算机,2020银行秋招岗位不同,考试内容都一样吗?-程序员宅基地

文章浏览阅读876次。银行有很多的岗位,所有的岗位考试内容都一样吗?弘新教育小编带你分析银行岗位的考试内容。银行考试范围一样吗?各大银行考试一般是由各银行单独组织的,考试范围一样,基本上包括行测、综合知识、英语和性格测试,考试侧重点不同,例如中国工商银行侧重于行测;中国农业银行侧重于英语和行测;建设银行和交通银行英语考得比较少。六大行考试各科目占比如下:EPI:考试题型主要以选择题形式出现。主要包括言语理解、数学运算、..._计算机专业银行的笔试有什么区别吗?

基于Springboot框架广东广州某大学教室自习室预约系统设计与实现 研究背景和意义、国内外现状_基于spring boot 的教室预约管理系统的设计与实现-程序员宅基地

文章浏览阅读756次,点赞20次,收藏9次。终极手撕架构师的学习笔记:分布式+微服务+开源框架+性能优化网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。需要这份系统化的资料的朋友,可以添加V获取:vip1024b (备注Java)一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!9)]一个人可以走的很快,但一群人才能走的更远!

kkfileview安装及使用_安装kkfileview file-online-preview-v4.2.1-程序员宅基地

文章浏览阅读1k次,点赞10次,收藏17次。把源码下载完成之后,用idea打开此项目,再打开maven小界面,点击kkfileview-parent下面的clean和install即可,最后在到server下面的target下面进行查看,查看是否有两个安装包:如图第一个是Linux的安装包,第二个是windows的安装包。2、点击bin目录下的startup.bat,该项目就能启动了,并查看log目录下的kkFileView.log文件查看是否成功启动。6、运行成功后,在本机访问地址为:http://服务器ip地址:8012/即可。_安装kkfileview file-online-preview-v4.2.1

达梦数据库常用功能及命令记录--持续更新-程序员宅基地

文章浏览阅读8.7k次,点赞3次,收藏17次。达梦数据库常用功能及命令记录达梦数据库语句的使用总体来说跟oracle很接近的,这篇文章主要是把常用的情况和语句做了记录,并且后续还会不断的持续更新达梦数据库常用说明1.测试查询语句:select 1;select top 2 from v$dm_ini; select from v$dm_ini limit 2;select * from v$dm_ini where rownum&l..._达梦数据库存储不等于写法

Dev-C++常用的快捷键 最全汇总_devc++快捷键-程序员宅基地

文章浏览阅读3.1w次,点赞30次,收藏205次。一、最常用的快捷键【Ctrl+N】新建源代码;【Ctrl+O】打开工程或文件;【Ctrl+S】保存;【Ctrl+F9】编译程序; 【Ctrl+F10】运行; 【F9】编译并运行;【F8】调试程序; 【Ctrl+w】查看变量; 【Ctrl+Alt+F2】终止程序;【Ctrl+.】注释;【Ctrl+M】取消注释;【Ctrl+鼠标滚轮】放大缩小字体大小;代码补全功能:Dev-C++具有代码补..._devc++快捷键

随便推点

记录ASP.NET CORE 3 部署过程-程序员宅基地

文章浏览阅读715次。环境为:window server 2008 IIS6.1 net core 3 首先时安装net.core 运行时。地址为:https://dotnet.microsoft.com/download/dotnet-core/3.0 大家找对应的版本进行下载安装。 IIS中创建网站,配置应用程序池.NET FrameWork 版本,选择 无托管代码。..._.net core3 发布部署

Java中的设计模式在代码重构中的应用-程序员宅基地

文章浏览阅读1.1k次,点赞18次,收藏7次。设计模式是在软件开发中经常使用的一种经验总结,用于解决在特定上下文中重复出现的问题。在代码重构中,设计模式可以帮助我们改善代码的结构、可读性和可维护性。下面是几个常见的设计模式及其在代码重构中的应用。

scrapy 解决IP代理池的三种方法_scrapy代理ip池-程序员宅基地

文章浏览阅读1.5w次,点赞11次,收藏57次。一.手动更新ip池 1.1在setting配置文件中新增ip池 IPPOOL=[ {“ipaddr”:”61.129.70.131:8080”}, {“ipaddr”:”61.152.81.193:9100”}, {“ipaddr”:”120.204.85.29:3128”}, {“ipaddr”:”219.228.126.86:8123”}, {“ipaddr”:”61.152.8..._scrapy代理ip池

智慧物业—建设智慧社区的实践_物业智慧社区-程序员宅基地

文章浏览阅读1.7k次。智慧社区的特征•高度信息化、网络化 智慧社区应当充分利用信息技术、互联网(及移动互联网)技术、云计算技术,开发、集成、利用信息资源,促进信息交流和知识共享。•社区与社区之间不是信息孤岛,而是互联、互通形成社区网络。•高度智能化、自动化 在智慧社区里,智能控制、智能管理、智能仪表、智能家居及相关自动化技术得到广泛应用。•高度人性化、便捷化智慧社区应当利用信息技术、互联网技术,结合本地服务优势,围绕广大业主的需求,开展丰富的社区服务、增值服务,让广大业主足不出户便..._物业智慧社区

AJAX DataSet的使用心得-程序员宅基地

文章浏览阅读311次。无论是VB、Delphi、.NET还是Java,都有提供对数据结果集的操作,有了数据结果集,我们只需要使用结果集的方法移动记录,获取记录字段数据,再结合界面,就可以很容易地完成一个数据库应用的编程,现在都流行用AJAX做基于web的系统了。老大决定新版要用AJAX来做,给了我们用AJAX做一些试验和原型的任务,可是当我们的技术组在预研时,才发现到了web上完全不是那么回事呀,仅仅通过form表单来操作和提交数据要实现我们的设备管理真的很麻烦,以前都是用delphi三层结构,有Clie

virtualenv教程_virtualenv使用-程序员宅基地

文章浏览阅读1.8k次,点赞5次,收藏11次。一、参考资料virtualenvvirtualenv简单使用virtualenv的介绍及基本使用(所有命令解释)二、相关介绍irtualenv通过创建一个虚拟化的python运行环境,将我们所需的依赖安装进去的,便于不同的项目在同一台机器上开发运行,不同项目之间相互不干扰,即在一台机器上创建多个独立的python运行环境。如下所示:使用 VirtualEnv 的理由:隔离项目之间的第三方包依赖,如A项目依赖django1.2.5,B项目依赖django1.3。为部署应用提供方便,把开发环_virtualenv使用

推荐文章

热门文章

相关标签