Ubuntu下Vim配置

2024-09-02 22:18
文章标签 配置 ubuntu vim

本文主要是介绍Ubuntu下Vim配置,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

 这几周突然对linux感兴趣。于是装了Ubuntu的虚拟机。在下边自己配置Vim,走了不少弯路。今天算是终于初步配出来了。现将自己的配置的功能简述如下:

    1、实现语法高亮;按照语言格式自动缩进;括号匹配;支持鼠标等基本功能;

    2、安装TagList插件;

    3、自动补全及加速自动补全的插件SuperTab

   注:此过程参考http://blog.csdn.net/wooin/archive/2007/10/31/1858917.aspx

   其中ctags-5.8.tar.gz的安装过程如下: 
 1)到http://ctags.sourceforge.net/下载ctags源码ctags-5.8.tar.gz 
 2)解压并安装 
   命令行:cd ctags-5.8 
   命令行:./configure && make &&make install


    我的Vimrc文件配置如下:

 " Allsystem-wide defaults are set in $VIMRUNTIME/debian.vim (usually just 
" /usr/share/vim/vimcurrent/debian.vim) and sourced by the call to:runtime 
" you can find below.  If you wish to change any of thosesettings, you should 
" do it in this file (/etc/vim/vimrc), since debian.vim will beoverwritten 
" everytime an upgrade of the vim packages is performed.  It isrecommended to 
" make changes after sourcing debian.vim since it alters the value ofthe 
" 'compatible' option. 

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

" 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. Uncommentingthe 
" following enables syntax highlighting by default. 
if has("syntax") 
  syntax on 
endif 

" If using a dark background within the editing area and syntaxhighlighting 
" 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 andplugins 
" 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 matchingbrackets. 
set ignorecase        " Do caseinsensitive matching 
set smartcase        " Do smart casematching 
set incsearch        " Incrementalsearch 
set autowrite        " Automaticallysave before commands like :next and :make 
set hidden          "Hide buffers when they are abandoned 
set mouse=a            "Enable mouse usage (all modes) 

"""""""""""""""""""""""""""""""""""""" 
语法着色与高亮设置 
""""""""""""""""""""""""""""""""""""""" 
" 
" "开启语法高亮 
syntax enable 
syntax on 
" 
" "配色 
colorscheme murphy 

" "设置高亮搜索 
set hlsearch 
" 
""""""""""""""""""""""""""""""""""""""" 
" " 文件设置 
""""""""""""""""""""""""""""""""""""""" 
" 
set encoding=utf-8 
set fileencoding=chinese 
set fileencodings=ucs-bom,utf-8,chinese 
set ambiwidth=double 
" 
" "检测文件的类型 
filetype on


" "默认无备份 
set nobackup 
set nowritebackup 
" 
""""""""""""""""""""""""""""""""""""""" 
" " 鼠标设置 
""""""""""""""""""""""""""""""""""""""" 
" "鼠标支持 
if has('mouse') 
set mouse=a 
endif 
" 
" "使鼠标用起来象微软 Windows,似乎正好解决连续多行缩进问题、退格问题 
behave mswin 
" 
""""""""""""""""""""""""""""""""""""""" 
" " 编辑器设置 
""""""""""""""""""""""""""""""""""""""" 
" 
"显示行号 
set number 
" 
"Tab 宽度 
set ts=4 
" 
" "自动缩进 
set sw=4 
" 
" "C/C++ 风格的自动缩进 
set cin 
" "设定 C/C++ 风格自动缩进的选项 
set cino=:0g0t0(sus 
" 
" "打开普通文件类型的自动缩进 
set ai 
" 
" "在编辑过程中,在右下角显示光标位置的状态行 
set ruler 
" 
" "显示匹配括号 
set showmatch 
" 
" "insert模式下能用删除键进行删除 
set backspace=indent,eol,start 
" 
" "代码折叠命令 za 
set foldmethod=syntax 
set foldlevel=100  "启动vim时不要自动折叠代码 
" 
" "设置字体 
set guifont=文泉驿等宽微米黑\ 13 
" 
" "当右键单击窗口的时候,弹出快捷菜单 
set mousemodel=popup 
" 
" "自动换行 
if (has("gui_running")) "图形界面下的设置 
" 
" "指定不折行。如果一行太长,超过屏幕宽度,则向右边延伸到屏幕外面 
set nowrap 
" "添加水平滚动条。如果你指定了不折行,那为窗口添加一个水平滚动条就非常有必要 
 
set guioptions+=b 
" 
" else "字符界面下的设置 
set wrap 
endif 
" 
""""""""""""""""""""""""""""""""""""""" 
" " 快捷键设置 
""""""""""""""""""""""""""""""""""""""" 
" "<F1> 菜单栏与工具栏隐藏与显示动态切换 
" set guioptions-=m 
" set guioptions-=T 
" map <silent> <F1> :if &guioptions =~# 'T'<Bar> 
" \set guioptions-=T <Bar> 
" \set guioptions-=m <bar> 
" \else <Bar> 
" \set guioptions+=T <Bar> 
" \set guioptions+=m <Bar> 
" \endif<CR> 
" 
" "<F2>code_complete.vim插件:函数自动完成 
if !exists("g:completekey") 
let g:completekey = "<F2>"   "hotkey 
endif 
" 
" "<F3><F4>大小写转换 
" map <F3> gu 
" map <F4> gU 
" 
" "当前目录生成tags语法文件,用于自动完成,函数提示:code_complete.vim 
"OmniCppComplete.vim ... 
map <F5> :!ctags -R --c-kinds=+p --fields=+S . <CR> 
map <F5> :!ctags -R --c-kinds=+p --c++-kinds=+p --fields=+iaS--extra=+q . 
"<CR> 
" 
" "函数和变量列表 
map <F6> :TlistToggle<CR> 
" 
" "文件浏览器 
map <F7> :WMToggle<CR> 
let g:winManagerWindowLayout = "FileExplorer" 
" 
" "文件树状列表 
map <F8> :NERDTree<CR> 
" 
" "映射复制、粘贴、剪贴ctrl+c ctrl+v ctrl+x 
map <C-V> "+pa<Esc> 
map! <C-V> <Esc>"+pa 
map <C-C> "+y 
map <C-X> "+x 
" 
" " 映射全选 ctrl+a 
map <C-A> ggVG 
map! <C-A> <Esc>ggVG 
" 
" " 多行缩进 
map <Tab> > 
map <S-Tab> < 
" 
""""""""""""""""""""""""""""""""""""""" 
" " 插件设置 
""""""""""""""""""""""""""""""""""""""" 
" 
" "开启OmniCppComplete.vim 
set nocp 
filetype plugin on 
" 
" "2Html插件,启用XHtml css 
" :let html_number_lines=1 
" :let html_use_css=1 
" :let use_xhtml=1 
" 
" "fencview.vim 插件设置 
let g:fencview_autodetect = 1  "打开文件时自动识别编码 
let g:fencview_checklines = 10 "检查前后10行来判断编码 
" 
"autocomplpop.vim & supertab.vim 插件设置 
let g:AutoComplPop_IgnoreCaseOption=1 
set ignorecase 
" 
""""""""""""""""""""""""""""""""""""""" 
" " 其他设置 
""""""""""""""""""""""""""""""""""""""" 
" 
" "去掉讨厌的有关vi一致性模式,避免以前版本的一些bug和局限 
set nocompatible 

"使用taglist 
let Tlist_Show_One_File=1 
let Tlist_Exit_OnlyWindow=1 

"使用C.vim 
filetype plugin on 

"所有用户使用vim功能一样 
set nu 

"设置自动补齐 
filetype plugin indent on 
set completeopt=longest,menu 


if has("autocmd") && exists("+omnifunc") 
     autocmd Filetype * 
   \ if &omnifunc == "" | 
   \   setlocal omnifunc=syntaxcomplete#Complete | 
   \ endif 
endif 

let g:SuperTabDefaultCompletionType="<C-X><C-]>" 
设置按下<Tab>后默认的补全方式默认是<C-P>, 
现在改为<C-X><C-L>(其为根据自己定义的结构体自动补齐). 
关于<C-P>的补全方式, 
还有其他的补全方式你可以看看下面的一些帮助: 
" :help ins-completion 
" :help compl-omni 

let g:SuperTabRetainCompletionType=2 
" 0 - 不记录上次的补全方式 
" 1 - 记住上次的补全方式,直到用其他的补全命令改变它 
" 2 - 记住上次的补全方式,直到按ESC退出插入模式为止 

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

这篇关于Ubuntu下Vim配置的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1131221

相关文章

Linux云服务器手动配置DNS的方法步骤

《Linux云服务器手动配置DNS的方法步骤》在Linux云服务器上手动配置DNS(域名系统)是确保服务器能够正常解析域名的重要步骤,以下是详细的配置方法,包括系统文件的修改和常见问题的解决方案,需要... 目录1. 为什么需要手动配置 DNS?2. 手动配置 DNS 的方法方法 1:修改 /etc/res

mysql8.0.43使用InnoDB Cluster配置主从复制

《mysql8.0.43使用InnoDBCluster配置主从复制》本文主要介绍了mysql8.0.43使用InnoDBCluster配置主从复制,文中通过示例代码介绍的非常详细,对大家的学习或者... 目录1、配置Hosts解析(所有服务器都要执行)2、安装mysql shell(所有服务器都要执行)3、

在Ubuntu上打不开GitHub的完整解决方法

《在Ubuntu上打不开GitHub的完整解决方法》当你满心欢喜打开Ubuntu准备推送代码时,突然发现终端里的gitpush卡成狗,浏览器里的GitHub页面直接变成Whoathere!警告页面... 目录一、那些年我们遇到的"红色惊叹号"二、三大症状快速诊断症状1:浏览器直接无法访问症状2:终端操作异常

java程序远程debug原理与配置全过程

《java程序远程debug原理与配置全过程》文章介绍了Java远程调试的JPDA体系,包含JVMTI监控JVM、JDWP传输调试命令、JDI提供调试接口,通过-Xdebug、-Xrunjdwp参数配... 目录背景组成模块间联系IBM对三个模块的详细介绍编程使用总结背景日常工作中,每个程序员都会遇到bu

Ubuntu向多台主机批量传输文件的流程步骤

《Ubuntu向多台主机批量传输文件的流程步骤》:本文主要介绍在Ubuntu中批量传输文件到多台主机的方法,需确保主机互通、用户名密码统一及端口开放,通过安装sshpass工具,准备包含目标主机信... 目录Ubuntu 向多台主机批量传输文件1.安装 sshpass2.准备主机列表文件3.创建一个批处理脚

JDK8(Java Development kit)的安装与配置全过程

《JDK8(JavaDevelopmentkit)的安装与配置全过程》文章简要介绍了Java的核心特点(如跨平台、JVM机制)及JDK/JRE的区别,重点讲解了如何通过配置环境变量(PATH和JA... 目录Java特点JDKJREJDK的下载,安装配置环境变量总结Java特点说起 Java,大家肯定都

linux配置podman阿里云容器镜像加速器详解

《linux配置podman阿里云容器镜像加速器详解》本文指导如何配置Podman使用阿里云容器镜像加速器:登录阿里云获取专属加速地址,修改Podman配置文件并移除https://前缀,最后拉取镜像... 目录1.下载podman2.获取阿里云个人容器镜像加速器地址3.更改podman配置文件4.使用po

Vue3 如何通过json配置生成查询表单

《Vue3如何通过json配置生成查询表单》本文给大家介绍Vue3如何通过json配置生成查询表单,本文结合实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录功能实现背景项目代码案例功能实现背景通过vue3实现后台管理项目一定含有表格功能,通常离不开表单

mybatis映射器配置小结

《mybatis映射器配置小结》本文详解MyBatis映射器配置,重点讲解字段映射的三种解决方案(别名、自动驼峰映射、resultMap),文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定... 目录select中字段的映射问题使用SQL语句中的别名功能使用mapUnderscoreToCame

Linux下MySQL数据库定时备份脚本与Crontab配置教学

《Linux下MySQL数据库定时备份脚本与Crontab配置教学》在生产环境中,数据库是核心资产之一,定期备份数据库可以有效防止意外数据丢失,本文将分享一份MySQL定时备份脚本,并讲解如何通过cr... 目录备份脚本详解脚本功能说明授权与可执行权限使用 Crontab 定时执行编辑 Crontab添加定