系统相关
首页 > 系统相关> > vim配置(Linux)

vim配置(Linux)

作者:互联网

" Setting some decent VIM settings for programming
" This source file comes from git-for-windows build-extra repository (git-extra/vimrc)

ru! defaults.vim                " Use Enhanced Vim defaults
set mouse=a                     " Use mouse
aug vimStartup | au! | aug END  " Revert last positioned jump, as it is defined below
let g:skip_defaults_vim = 1     " Do not source defaults.vim again (after loading this system vimrc)

"Filetype based mappings----{
    "C Compiler:
    autocmd Filetype c map <buffer> <F9> :!gcc "%" -o "./bin/%<" -g -Wl,--stack=1000000000 -std=c11 -static-libgcc -Wall -Wextra -fexec-charset=GBK <CR>
    "-Wconversion

    "C++ Compiler
    autocmd Filetype cpp map <buffer> <F9> :!g++ "%" -o "./bin/%<" -g -O2 -Wl,--stack=1000000000 -std=c++17 -static-libgcc -Wall -Wextra -fexec-charset=GBK <CR>

    autocmd Filetype c,cpp map <buffer> <F8> :!"./bin/%<" <CR>
    autocmd Filetype c,cpp inoremap <buffer> <CR> <c-r>=Indent()<CR>
"}
imap jj <Esc>
nmap <tab> :bn<CR>

colo gruvbox
set background=dark
set nocompatible
syntax on
set showcmd
set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1
set encoding=utf-8
filetype indent on
filetype on
filetype plugin on
set cindent
set tabstop=4
set shiftwidth=4        " 缩进
set expandtab            " 将tab转为空格
set softtabstop=4
set number                " 显示行数
" set cmdheight=2
" set cursorline        " 当前行高亮
" set textwidth=20        " 行宽
set wrap                " 自动拆行
set linebreak            " 不会在单词中间拆行
set wrapmargin=2        " 折行处与边缘空出的字符数
set hlsearch            " 搜索时高亮显示匹配结果
set incsearch            " 搜索模式每输一个字符自动到第一个匹配结果
set ignorecase smartcase    " 忽略大小写 搜索词有大写字母时不忽略
set undofile            " 保留撤销历史
set nobackup
set noswapfile
set backupdir=~/.vim/.backup//  
set directory=~/.vim/.swp//
set undodir=~/.vim/.undo//
set autochdir            " 自动切换工作目录
set noerrorbells        " 出错时不发出声音
set history=100            " 记住多少次历史操作
set autoread            " 文件被外部改变发出提示
set autowrite
set wildmenu
set wildmode=longest:list,full    " 命令模式下,底部操作指令按下 Tab 键自动补全。第一次按下 Tab,会显示所有匹配的操作指令的清单;第二次按下 Tab,会依次选择各个指令。
" set listchars=tab:>-,trail:-    " 行尾空格和tab显示
" set foldenable            " 开始折叠
" set foldmethod=syntax        " 语法折叠
" set foldcolumn=0        " 折叠区域宽度
" setlocal foldlevel=1        " 设置折叠层数为
" set foldclose=all        " 设置为自动关闭折叠 
" nnoremap <space> @=((foldclosed(line('.')) < 0) ? 'zc' : 'zo')<CR>
" 用空格键来开关折叠

" 插件
call plug#begin('/usr/share/vim/vim82/plugged')

    " Plug 'jiangmiao/auto-pairs'
    " Plug 'dense-analysis/ale'       " 语法错误检查
    Plug 'tpope/vim-commentary'     "注释
    Plug 'vim-airline/vim-airline'
    Plug 'vim-airline/vim-airline-themes'
    Plug 'Yggdroot/indentLine'
    Plug 'luochen1990/rainbow'

call plug#end()

" configuration
let g:airline_theme='bubblegum'
let g:airline#extensions#tabline#enabled=1
let g:airline#extensions#tabline#formatter='unique_tail_improved'
let g:airline_powerline_fonts = 1
let g:indentLine_color_term = 239
" let g:indentLine_defaultGroup = 'SpecialKey'
let g:rainbow_active = 1

inoremap <tab> <c-r>=Tabout()<CR>
function! Tabout()
    let line = getline('.')
    let col = col('.')
    if index([")","]","}",">","\"","'"],line[col-1]) != -1
        return "\<Right>"
    else 
        return "\<tab>"
    endif
endfunction

"

set ai                          " set auto-indenting on for programming
set showmatch                   " automatically show matching brackets. works like it does in bbedit.
set vb                          " turn on the "visual bell" - which is much quieter than the "audio blink"
set laststatus=2                " make the last line where the status is two lines deep so you can see status always
set showmode                    " show the current mode
set clipboard=unnamed           " set clipboard to unnamed to access the system clipboard under windows
set wildmode=list:longest,longest:full   " Better command line completion

" Show EOL type and last modified timestamp, right after the filename
" Set the statusline
set statusline=%f               " filename relative to current $PWD
set statusline+=%h              " help file flag
set statusline+=%m              " modified flag
set statusline+=%r              " readonly flag
set statusline+=\ [%{&ff}]      " Fileformat [unix]/[dos] etc...
set statusline+=\ (%{strftime(\"%H:%M\ %d/%m/%Y\",getftime(expand(\"%:p\")))})  " last modified timestamp
set statusline+=%=              " Rest: right align
set statusline+=%l,%c%V         " Position in buffer: linenumber, column, virtual column
set statusline+=\ %P            " Position in buffer: Percentage

if &term =~ 'xterm-256color'    " mintty identifies itself as xterm-compatible
  if &t_Co == 8
    set t_Co = 256              " Use at least 256 colors
  endif
  " set termguicolors           " Uncomment to allow truecolors on mintty
endif
"------------------------------------------------------------------------------
" Only do this part when compiled with support for autocommands.
if has("autocmd")
    " Set UTF-8 as the default encoding for commit messages
    autocmd BufReadPre COMMIT_EDITMSG,MERGE_MSG,git-rebase-todo setlocal fileencoding=utf-8

    " Remember the positions in files with some git-specific exceptions"
    autocmd BufReadPost *
      \ if line("'\"") > 0 && line("'\"") <= line("$")
      \           && &filetype !~# 'commit\|gitrebase'
      \           && expand("%") !~ "ADD_EDIT.patch"
      \           && expand("%") !~ "addp-hunk-edit.diff" |
      \   exe "normal! g`\"" |
      \ endif

      autocmd BufNewFile,BufRead *.patch set filetype=diff

      autocmd Filetype diff
      \ highlight WhiteSpaceEOL ctermbg=red |
      \ match WhiteSpaceEOL /\(^+.*\)\@<=\s\+$/
endif " has("autocmd")


"括号补全
inoremap ' <c-r>=QuoteDelim("'")<CR>
inoremap " <c-r>=QuoteDelim('"')<CR>
inoremap [ <c-r>=OpenPair('[',']')<CR>
inoremap ( <c-r>=OpenPair('(',')')<CR>
inoremap { <c-r>=OpenPair('{','}')<CR>
inoremap ) <c-r>=ClosePair(')')<CR>
inoremap } <c-r>=ClosePair('}')<CR>
inoremap ] <c-r>=ClosePair(']')<CR>
inoremap <BS> <c-r>=Removepairs()<CR>
function! Checkinpair()
    let line = getline('.')
    let col = col('.')
    if line[col-1] == "\"" || line[col-1] == "'"
        return 1
    else 
        return 0
    endif
endfunction
    
function! OpenPair(char1,char2)
    let op = Checkinpair()
    if op == 1
        return a:char1
    else 
        return a:char1.a:char2."\<ESC>i"
    endif
endfunction

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

function! QuoteDelim(char)
    let op = Checkinpair()
    if op == 1
        return a:char
    endif 
    let line = getline('.')
    let col = col('.')
    if line[col - 2] == "\\"
        "Inserting a quoted quotation mark into the string
        return a:char
    elseif line[col - 1] == a:char
        "Escaping out of the string
        return "\<Right>"
    else
        "Starting a string
        return a:char.a:char."\<Esc>i"
    endif
endfunction

function! Rightpair(char)
    if a:char == "("
        return ")"
    elseif a:char == "["
        return "]"
    elseif a:char == "{"
        return "}"
    elseif a:char == "'"
        return "'"
    elseif a:char == "\""
        return "\""
    else 
        return -1
    endif
endfunction

function! Removepairs()
    let line = getline('.')
    let col = col('.')
    let rightpair = Rightpair(line[col-2])
    if rightpair == -1
        return "\<BS>"
    elseif line[col-1] == rightpair
        return "\<Right>\<BS>\<BS>"
    else 
        return "\<BS>"
    end
endfunction

function! Align(now,goal)
    if a:goal == 0
        return "\<ESC>A"
    elseif a:now == a:goal
        return "\<Space>"
    elseif a:now + 4 <= a:goal
        return "\<Tab>".Align(a:now+4,a:goal)
    else
        return "\<Space>".Align(a:now+1,a:goal)
    endif
endfunction

function! Indent()
    let line = getline('.')
    let col = col('.')
    if line[col-1] == "}" && line[col-2] == "{"
        return "\<CR>\<ESC>O"
    elseif line[col-2] == ")"
        return "\<CR>\<ESC>i".Align(1,indent(line('.')))
    else 
        return "\<CR>"
    endif
endfunction

 

View Code

 

标签:set,return,配置,vim,char,let,Linux,line,col
来源: https://www.cnblogs.com/sto324/p/16559942.html