首页 > 其他分享 >Vim——.vimrc配置

Vim——.vimrc配置

时间:2023-11-24 14:23:51浏览次数:26  
标签:set vimrc 配置 Vim call ycm let line append

vim是一个很好用的文本编辑工具,支持丰富的插件、定制化。
主要在home目录下放置.vimrc,即~/.vimrc,即可实现诸多插件配置。
这里,共享一份笔者在用的.vimrc。

set nocompatible              " be iMproved, required
set backspace=indent,eol,start
filetype off                  " required

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
Plugin 'Valloric/YouCompleteMe'
"Plugin 'vim-airline/vim-airline'
"Plugin 'vim-airline/vim-airline-themes'
Plugin 'jiangmiao/auto-pairs'
Plugin 'scrooloose/nerdcommenter'
Plugin 'scrooloose/nerdtree'
"Plugin 'flazz/vim-colorschemes'
"Plugin 'altercation/vim-colors-solarized'
Plugin 'Yggdroot/LeaderF'
Plugin 'majutsushi/tagbar'
"Plugin 'airblade/vim-gitgutter'
"Plugin 'tpope/vim-fugitive'
"Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
call vundle#end()            " required
filetype plugin indent on    " required
" To ignore plugin indent changes, instead use:
"
" Brief help
" :PluginList       - lists configured plugins
" :PluginInstall    - installs plugins; append `!` to update or just :PluginUpdate
" :PluginSearch foo - searches for foo; append `!` to refresh local cache
" :PluginClean      - confirms removal of unused plugins; append `!` to auto-approve removal
"
" see :h vundle for more details or wiki for FAQ
" Put your non-Plugin stuff after this line

let mapleader=";"                    "将';'设置为leader
set nu

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

nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l
nnoremap <C-b> :bp<CR>
nnoremap <C-n> :bn<CR>

" code
set mouse=a
"set tw=4 this line will make shell auto enter...
set et
set smarttab
"set encoding=utf-8
set tabstop=4
set shiftwidth=4
set autoindent
set expandtab

" syntax
syntax enable

" search
set incsearch
set hlsearch
set ic "ignore case

" code jump
nnoremap <F7> <ESC><ESC>:!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR><CR>
set tags=tags;/
set tags+=./tags "add current directory's generated tags file
set tags+=tags,/usr/include/tags,~/.
set cscopequickfix=s-,c-,d-,i-,t-,e-        "使用quickfix显示cscope的结果

" theme
syntax on
syntax enable
set t_Co=256
set background=dark
colorscheme molokai

"syntax enable
"set background=dark
"colorscheme solarized
"let g:solarized_termcolors=256
"let g:solarized_termtrans = 1
"let g:solarized_diffmode = "normal"
"let g:solarized_use16 = 1

 "file
au BufRead,BufNewFile *.{sh}   set filetype=sh
au BufRead,BufNewFile *.{c}    set filetype=c
au BufRead,BufNewFILE *.{py}   set filetype=python
au BufRead,BufNewFILE *.{java} set filetype=java
au BufRead,BufNewFile *.{md,mdown,mkd,mkdn,markdown,mdwn}   set filetype=mkd
au BufRead,BufNewFile *.{go}   set filetype=go
au BufRead,BufNewFile *.{js}   set filetype=javascript
au BufRead,BufNewFile *.{log}  set filetype=log

autocmd BufNewFile *.cpp,*.[ch],*.sh,*.java,*.py exec ":call SetTitle()" 
func SetTitle() 
    if &filetype == 'sh' 
        call setline(1, "\###############################################################") 
        call append(line(".")+0, " \# Copyright(c) 2005-".strftime("%Y")." TriHappy Technologies Co. Ltd.") 
        call append(line(".")+1, " \# All right reserved.") 
        call append(line(".")+2, " \#") 
        call append(line(".")+3, " \# Filename		:	".expand("%")) 
        call append(line(".")+4, " \# Version		:	1.0") 
        call append(line(".")+5, " \# Abstract		:	") 
        call append(line(".")+6, " \# Author		:	Cyril Zheng") 
        call append(line(".")+7, " \# Created Date	:	".strftime("%Y.%m.%d")) 
        call append(line(".")+8, " \#") 
        call append(line(".")+9, " \# Modified History:") 
        call append(line(".")+10, " \# 1.Create file.	".strftime("%Y.%m.%d")."  Cyril Zheng") 
        call append(line(".")+11, "\###############################################################") 
        call append(line(".")+12, "\#!/bin/sh") 
    elseif &filetype == 'python'
        call setline(1,"#!/usr/bin/env python3")
        call append(line(".")+0,"# -*- coding: UTF-8 -*-")
        call append(line(".")+1,"")
        call append(line(".")+2,"def main():")
        call append(line(".")+3,"    print(\'hello world\')")
        call append(line(".")+4,"")
        call append(line(".")+5,"if __name__ == \'__main__\':")
        call append(line(".")+6,"    main()")
	else 
        call setline(1, "/***************************************************************") 
        call append(line(".")+0, " * Copyright(c) 2005-".strftime("%Y")." TriHappy Technologies Co. Ltd.") 
        call append(line(".")+1, " * All right reserved.") 
        call append(line(".")+2, " *") 
        call append(line(".")+3, " * Filename		:	".expand("%")) 
        call append(line(".")+4, " * Version		:	1.0") 
        call append(line(".")+5, " * Abstract		:	") 
        call append(line(".")+6, " * Author		:	Cyril Zheng") 
        call append(line(".")+7, " * Created Date	:	".strftime("%Y.%m.%d")) 
        call append(line(".")+8, " *") 
        call append(line(".")+9, " * Modified History:") 
        call append(line(".")+10, " * 1.Create file.	".strftime("%Y.%m.%d")."  Cyril Zheng") 
        call append(line(".")+11, " ***************************************************************/") 
        call append(line(".")+12, "") 
    endif

	if expand("%:e") == 'cpp'
        call append(line(".")+13, "#include <iostream>")
        call append(line(".")+14, "using namespace std;")
        call append(line(".")+15, "")
		call append(line(".")+16, "int main(int argc, char const *argv[])")
        call append(line(".")+17, "{")
        call append(line(".")+18, "	return 0;")
        call append(line(".")+19, "}")
    endif

    if &filetype == 'c'
        call append(line(".")+13, "#include <stdio.h>")
        call append(line(".")+14, "#include <stdlib.h>")
        call append(line(".")+15, "#include <string.h>")
        call append(line(".")+16, "#include <stdbool.h>")
        call append(line(".")+17, "")
        call append(line(".")+18, "#define print(fmt, args...) printf(\"\\033[1m[ \%s ] \%03d\: \"fmt\"\\033\[0m\\n\\r\", __FUNCTION__, __LINE__, ##args)")
        call append(line(".")+19, "")
		call append(line(".")+20, "int main(int argc, char const *argv[])")
        call append(line(".")+21, "{")
        call append(line(".")+22, "	return 0;")
        call append(line(".")+23, "}")
	endif

	if expand("%:e") == 'h'
		call append(line(".")+13, "#ifndef _".toupper(expand("%:t:r"))."_H_")
		call append(line(".")+14, "#define _".toupper(expand("%:t:r"))."_H_")
		call append(line(".")+15, "")
		call append(line(".")+16, "")
		call append(line(".")+17, "")
		call append(line(".")+18, "#endif")
	endif

	if &filetype == 'java'
		call append(line(".")+13,"public class ".expand("%:t:r")." {")
		call append(line(".")+14,"	public static void main(String[] args) {")
		call append(line(".")+15,"	}")
		call append(line(".")+16,"}")
	endif
endfunc 
autocmd BufNewFile * normal G

autocmd BufNewFile,BufRead * :syntax match cfunctions "\<[a-zA-Z_][a-zA-Z_0-9]*\>[^()]*)("me=e-2 
autocmd BufNewFile,BufRead * :syntax match cfunctions "\<[a-zA-Z_][a-zA-Z_0-9]*\>\s*("me=e-1

"nerdtree
nnoremap <silent> <F3> :NERDTreeToggle<CR>
nnoremap <leader>j :%!python -m json.tool<CR>

" tagbar
let g:tagbar_width=35
let g:tagbar_autofocus=0
nmap <F6> :TagbarToggle<CR>

" LeaderF
let g:Lf_ShortcutB='<leader>b'
let g:Lf_DefaultMode='NameOnly'
let g:Lf_CursorBlink=0
let g:Lf_HideHelp=1
let g:Lf_ShowHidden=1
let g:Lf_ShowDevIcons=0
noremap <Leader>s :<C-U><C-R>=printf("Leaderf! rg -e \"%s\"", expand("<cword>"))<CR>
let g:Lf_PreviewInPopup = 1
let g:Lf_WindowPosition = 'popup'
"let g:Lf_StlSeparator = { 'left': "\ue0b0", 'right': "\ue0b3", 'font': "DejaVu Sans Mono for Powerline" }
let g:Lf_StlSeparator = { 'left': '', 'right': '' }
let g:Lf_PreviewResult = {'Function': 1, 'BufTag': 0 }
let g:Lf_ShowDevIcons = 1
let g:Lf_ShortcutF = "<leader>ff"
noremap <leader>fb :<C-U><C-R>=printf("Leaderf buffer %s", "")<CR><CR>
noremap <leader>fm :<C-U><C-R>=printf("Leaderf mru %s", "")<CR><CR>
noremap <leader>ft :<C-U><C-R>=printf("Leaderf bufTag %s", "")<CR><CR>
noremap <leader>fl :<C-U><C-R>=printf("Leaderf line %s", "")<CR><CR>

"ycm
let g:ycm_collect_identifiers_from_tags_files = 1
let g:ycm_seed_identifiers_with_syntax = 0
let g:ycm_min_num_of_chars_for_completion=2
let g:ycm_autoclose_preview_window_after_completion = 1
let g:ycm_complete_in_comments = 1
let g:ycm_complete_in_strings = 1
let g:ycm_collect_identifiers_from_comments_and_strings = 1
let g:ycm_confirm_extra_conf = 0
let g:ycm_show_diagnostics_ui = 0

let g:ycm_global_ycm_extra_conf='~/.ycm_extra_conf.py'
let g:ycm_use_clangd = 1
let g:ycm_clangd_binary_path = "/usr/bin/clangd"
let g:ycm_clangd_uses_ycmd_caching = 1
let g:ycm_add_preview_to_completeopt = 0

"AutoPairsFlyMode
let g:AutoPairsFlyMode = 0

let NERDTreeIgnore=['.*\.pyc$','.*\.o$','.*\.ko$']  " 忽略.pyc .o .ko 结尾的文件
"fonts
let laststatus = 2
let g:airline_powerline_fonts = 1   "use fonts that powerline has patched
let g:Powerline_symbols='fancy'

标签:set,vimrc,配置,Vim,call,ycm,let,line,append
From: https://www.cnblogs.com/adam-zheng/p/17853626.html

相关文章

  • mac端 安卓UI自动化安装环境配置
    安装JDK 官网下载安装包https://www.oracle.com/java/technologies/javase/javase8u211-later-archive-downloads.html 选择对应mac版本的dmg文件下载安装 配置Java环境终端执行命令vi~/.bash_profile文件,/Library/Java/JavaVirtualMachines/jdk-17.jdk/Content......
  • Spring Boot应用中Tomcat建议配置
    在SpringBoot框架中,我们使用最多的是Tomcat,这是SpringBoot默认的容器技术,而且是内嵌式的Tomcat。Tomcat是Apache基金下的一个轻量级的Servlet容器,支持Servlet和JSP。Tomcat服务器本身具有Web服务器的功能,可以作为独立的Web服务器来使用。一、SpringBoot应用......
  • 华为交换机配置静态mac
    华为交换机静态arp绑定vlan的地址和mac 在华为交换机上,可以通过以下命令来配置静态ARP绑定,并将其关联到特定的VLAN。请注意,确保你有足够的权限执行这些命令,并根据你的网络配置进行适当的调整。进入系统视图:plaintext[Switch]system-view[Switch]_选择......
  • 实训课 - wireshark和网络配置基本知识
    接上文:实训课-计算机网络技术基础笔记https://blog.51cto.com/youyeye/8363907WireShark的基本抓包使用安装wireshark先在虚拟机上安装wireshark(直接在本机上将exe文件复制,然后切换到虚拟机上粘贴)然后工具栏capture–optionsInterface是接口,然后旁边的将是网卡,有两个选项,选择in......
  • ElasticSearch之配置
    ElasticSearch主要的配置文件,如下:elasticsearch.yml,ElasticSearch的相关参数。jvm.options,JVM的相关参数。log4j2.properties,日志的相关参数。默认情况下,ElasticSearch从$ES_HOME/config目录下读取上述配置文件。启动ElasticSearch时可以使用环境变量ES_PATH_CONF,指定配置......
  • springboot定时任务线程池配置拾遗--利用配置类进行配置
    springboot定时任务线程池配置拾遗--利用配置类进行配置目录springboot定时任务线程池配置拾遗--利用配置类进行配置1springboot自动装配1.1通过TaskSchedulingProperties获取yaml参数1.2TaskSchedulingAutoConfiguration自动配置类根据TaskSchedulingProperties的配置装配线......
  • 虚拟机linux系统配置安装redis(每日总结11.23)
    1.进入到root模式下cd/export/server/2.下载wgethttp://download.redis.io/releases/redis-5.0.7.tar.gz3.解压tar-zvxfredis-5.0.7.tar.gz4.把文件移动到redis文件夹里mvredis-5.0.7/export/server/redis5.进入redis文件夹里cdredis6.编译m......
  • docker和虚拟化,docker安装和配置, 镜像操作,容器操作
    1docker和虚拟化......
  • centos 和ubuntu 配置ssh key登录。
    vim/etc/ssh/sshd_configRSAAuthenticationyes #开启RSA验证PubkeyAuthenticationyes #使用公钥验证AuthorizedKeysFile.ssh/authorized_keys #公钥保存位置所以需要把公钥写到对应用户的目录的.ssh/authorized_keys下,然后重启ssh服务systemctlrestartsshd......
  • 【最新最全指南】Vue项目安装eslint配置说明
    本指南都适配windows和mac下的开发项目第一步:安装1、全局安装:eslint(最好全局安装1个,配置出错debug方便)npminstalleslint-g2、项目本地dev安装:eslint(也可不安装,后面安装eslint-plugin-vue时候,默认会一起安装eslint)npminstalleslint-D3、项目本地dev安装插件:eslint-plu......