" _
" ______ _ ___| |__ __ _ _ __ _ _
"|_ / _` |/ __| '_ \ / _` | '__| | | |
" / / (_| | (__| | | | (_| | | | |_| |
"/___\__,_|\___|_| |_|\__,_|_| \__, |
" |___/
" ===
" === Auto load for first time uses
" ===
"source ~/.config/nvim/_machine_specific.vim
" ====================
" ===== [config] =====
" ====================
" set nocompatible " close vi compatibility mode
syntax on
filetype on " open file classic check
"filetype plugin indent on " turn on auto-completion
"set completeopt=longest,menu
"filetype indent on "针对不同的文件类型采用不同的缩进格式
filetype plugin on " allow plugin
set encoding=utf-8 " set coding is utf-8
set fileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936
set termencoding=utf-8
set pyxversion=3
set autoread
"let g:python3_host_prog="/usr/bin/python3.8"
" ======= basic formant settings ==============
" 设置空白字符的视觉提示
set list listchars=extends:❯,precedes:❮,tab:▸\ ,trail:˽
set cursorline " highlight current line
set number " show line number
set ruler " show ruler
set syntax=on " turn on syntax highlight
" auto identation ===========
set autoindent
set cindent " same ident with pre line, also can identify braces
" --------------------------------------------
set wrap " auto wrap
set ts=4 " Tab's width
set softtabstop=4 " INSERT ident length
set shiftwidth=4 " ident length
set expandtab " tab replace black space
set showmatch " bracket highlight
set matchtime=2 " bracket match highlight time(0.2s)
set showcmd " show input message
set wildmenu " enable command-line completion in enhanced mode
set ignorecase " ignore case when you search
set hlsearch " highlight search result
" code fold setting ===========================
set foldenable " allow flod (help fold)
set foldmethod=marker " option: [manual indent marker]
"au BufWinLeave * silent mkview
"set mouse=r " mouse set
" allow backspace to upper line or lower line-
set backspace=eol,start,indent
set whichwrap+=<,>,h,l
" --------------------------------------------
set scrolloff=5 " reserve at least 5 lines when you scrol
"================= status bar set ============{{{
set laststatus=2 " up show status row(1), always show status(2)
function! Buf_total_num()
return len(filter(range(1, bufnr('$')), 'buflisted(v:val)'))
endfunction
function! File_size(f)
let l:size = getfsize(expand(a:f))
if l:size == 0 || l:size == -1 || l:size == -2
return ''
endif
if l:size < 1024
return l:size.' bytes'
elseif l:size < 1024*1024
return printf('%.1f', l:size/1024.0).'k'
elseif l:size < 1024*1024*1024
return printf('%.1f', l:size/1024.0/1024.0) . 'm'
else
return printf('%.1f', l:size/1024.0/1024.0/1024.0) . 'g'
endif
endfunction
set statusline=%<%1*[B-%n]%* " current buffer number
set statusline+=%2*\ [%{File_size(@%)}]\ %* " show file's size
set statusline+=%3*\%<%.30F\ " show file name and path
set statusline+=%=%4*\%y%m%r%h%w\ %* " show file classic and statut
set statusline+=%5*\%{&ff}\[%{&fenc}]\ %* " show file coding
set statusline+=%6*\ row:%l\|%L/col:%c\/%* " show current cursor's row and column
set statusline+=%7*\%p%%\ %* " current percent
set statusline+=%8*[ORZ:%{Buf_total_num()}]%* " ORZ is an abbreviation for total
hi User1 cterm=bold ctermfg=226 ctermbg=0
hi User2 cterm=none ctermfg=250 ctermbg=0
hi User3 cterm=none ctermfg=208 ctermbg=0
hi User4 cterm=none ctermfg=33 ctermbg=0
hi User5 cterm=none ctermfg=245 ctermbg=0
hi User6 cterm=none ctermfg=245 ctermbg=0
hi User7 cterm=none ctermfg=245 ctermbg=0
hi User8 cterm=none ctermfg=245 ctermbg=0
" --------------------------------------------}}}
" 代码补充的键位替换
"inoremap <expr><tab> pumvisible() ? "\<c-n>" : "\<tab>"
"inoremap <expr><S-TAB> pumvisible() ? "\<c-pl
>" : "\<TAB>"
hi Normal ctermfg=252 ctermbg=none " let bg transparent
" ======== set undo ==================
"silent !mkdir -p ~/.config/nvim/tmp/backup
"silent !mkdir -p ~/.config/nvim/tmp/undo
"silent !mkdir -p ~/.config/nvim/tmp/sessions
"set backupdir=~/.config/nvim/tmp/backup,.
"set directory=~/.config/nvim/tmp/backup,.
"if has('persistent_undo')
" set undofile
" set undodir=~/.config/nvim/tmp/undo,.
"endif
" --------------------------------------------
" ============ KEY MAP ======================
" set leader is <space>
let mapleader=" "
"map <LEADER> :retab!<CR>
" cancel the highlight search
nnoremap <LEADER><CR> :nohlsearch<CR>
" ===
" === file option
" ===
" Disable the default s key
map s <nop>
" save
map S :w<CR>
" quit
map Q :q<CR>
" make Y to copy till the end of the line
nnoremap Y y$
" Copy to system clipboard
vnoremap Y "+y
" Indentation
nnoremap < <<
nnoremap > >>
" select all
map <C-a> ggVG
" replace ESC
"inoremap <LEADER>[ <ESC>
"===
"=== cursor movement
"===
" ^
" i
" < j l >
" k
" v
" new cursor movment
noremap <silent> i k
noremap <silent> j h
noremap <silent> J H
noremap <silent> k j
"noremap <silent> l l
" new INSERT key
noremap r i
noremap R I
" faster navigation
noremap <silent> I 7k
noremap <silent> K 7j
" Ctrl + U or E will move up/down the view port without moving the cursor
nnoremap <C-L> 5<C-y>
nnoremap <C-J> 5<C-e>
" Insert and Command Mode Cursor Movement
noremap! <C-a> <Home>
noremap! <C-s> <End>
noremap! <C-i> <Up>
noremap! <C-k> <Down>
noremap! <C-j> <Left>
noremap! <C-l> <Right>
noremap! <M-j> <S-Left>
noremap! <M-l> <S-Right>
" Disable the default t key
noremap t <nop>
" Use t + arrow keys for moving the cursor around windows
noremap tl <C-w>l
noremap ti <C-w>k
noremap tk <C-w>j
noremap tj <C-w>h
"===
"=== windwo management
"===
" split the screens to up (horizontal), down (horizontal), left (vertical), right (vertical)
map si :set nosplitbelow<CR>:split<CR>:e
map sk :set splitbelow<CR>:split<CR>:e
map sj :set nosplitright<CR>:vsplit<CR>:e
map sl :set splitright<CR>:vsplit<CR>:e
" Resize splits with arrow keys
map <up> :res +5<CR>
map <down> :res -5<CR>
map <left> :vertical resize-5<CR>
map <right> :vertical resize+5<CR>
" Disable the default c key
"map c <nop>
" Place the two screens up and down
noremap ch <C-w>t<C-w>K
" Place the two screens side by side
noremap cv <C-w>t<C-w>H
"===
"=== tabe management
"===
" 新建标签页, w filepath_and_name
map <c-t> :tabe<CR>
" 前一标签页
map t- :-tabnext<CR>
" 后一标签页
map t= :+tabnext<CR>
" 上一个buffer
map b- :bp<CR>
" 下一个buffer
map b= :bn<CR>
"===
"=== other
"===
" Open the vimrc file anytime
nnoremap <LEADER>rc :e ~/.config/nvim/init.vim<CR>
" Opening a terminal window
nnoremap <LEADER>/ :set splitbelow<CR>:split<CR>:res +10<CR>:term<CR>
" Open up pudb, a python debug,(pip install --user pudb)
noremap <c-d> :tab sp<CR>:term python3 -m pudb %<CR>
" find two same word
nmap <LEADER>fd /\(\<\w\+\>\)\_s*\1
" Press space twice to jump to the next '<++>' and edit it
nnoremap <LEADER><LEADER> <ESC>/<++><CR>:nohlsearch<CR>c4l
" Spelling Check with <space>sc
nnoremap <LEADER>sc :set spell!<CR>
" Auto change directory to current dir
autocmd BufEnter * silent! lcd %:p:h
" resource neovim config
"map rc :source $MYVIMRC<CR>
"imap <c-j> <esc>f"a
" --------------------------------------------
" when you open file, back to last edit position
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
" =============== ipython run ================
noremap ,i :sp<CR><C-w>j:term ipython<CR> i %run
" --------------------------------------------
" === Compile function ======================={{{
map <F9> :call CompileRunGcc()<CR>
func! CompileRunGcc()
exec "w"
if &filetype == 'c'
exec "!g++ % -o %<"
exec "!time ./%<"
elseif &filetype == 'cpp'
set splitbelow
exec "!g++ -std=c++11 % -Wall -o %<"
:sp
:res -15
:term ./%<
elseif &filetype == 'java'
exec "!javac %"
exec "!time java %<"
elseif &filetype == 'sh'
:!time bash %
elseif &filetype == 'python'
set splitbelow
:sp
:term python3 %
elseif &filetype == 'html'
silent! exec "!".g:mkdp_browser." % &"
elseif &filetype == 'markdown'
exec "MarkdownPreview"
elseif &filetype == 'tex'
silent! exec "VimtexStop"
silent! exec "VimtexCompile"
elseif &filetype == 'dart'
CocCommand flutter.run
elseif &filetype == 'go'
set splitbelow
:sp
:term go run .
endif
endfunc
" --------------------------------------------}}}
" === Annotate function ======================{{{
" 设置注释快捷键
"map t' :call Note()<CR>
"func! Note()
"if &filetype == 'python'
"normal 0i#
"elseif &filetype == 'sh'
"normal 0i#
"elseif &filetype == 'vim'
"normal 0i"
"elseif &filetype == 'plaintex'
"normal 0i%
"elseif &filetype == 'tex'
"normal 0i%
"elseif &filetype == 'c'
"normal 0i//
"elseif &filetype == 'cpp'
"normal 0i//
"elseif &filetype == 'java'
"normal 0i//
"endif
"endfunc
" 设置取消注释
"map o' 0df j
" --------------------------------------------}}}
" === Format function ========================{{{
"map ,f :call FormartSrc()<CR>
"定义FormartSrc()
"func FormartSrc()
"exec "w"
"if &filetype == 'c'
"exec "!astyle --style=ansi --one-line=keep-statements -a --suffix=none %"
"elseif &filetype == 'cpp' || &filetype == 'hpp'
"exec "r !astyle --style=ansi --one-line=keep-statements -a --suffix=none %> /dev/null 2>&1"
"elseif &filetype == 'perl'
"exec "!astyle --style=gnu --suffix=none %"
"elseif &filetype == 'py'||&filetype == 'python'
"exec "r !autopep8 -i --aggressive %"
"elseif &filetype == 'java'
"exec "!astyle --style=java --suffix=none %"
"elseif &filetype == 'jsp'
"exec "!astyle --style=gnu --suffix=none %"
"elseif &filetype == 'xml'
"exec "!astyle --style=gnu --suffix=none %"
"endif
"exec "e! %"
"endfunc
" --------------------------------------------}}}
" === make file header ======================{{{
"autocmd BufNewFile * call SetTitle()
nmap tit :call SetTitle()<CR>
func! SetTitle()
if &filetype == 'python'
call setline(1,"#!/usr/bin/env python3")
call append(line("."),"# -*- coding:UTF-8 -*-")
call append(line(".")+1, "__author__ = 'zachary'")
call append(line(".")+2, '"""')
call append(line(".")+3, "File Name: ".expand("%"))
call append(line(".")+4, "Created Time: ".strftime("%c"))
call append(line(".")+5, "Last Modified: ")
call append(line(".")+6, '"""')
call append(line(".")+7, "<++>")
elseif &filetype == 'c'
call setline(1, "#include <stdio.h>")
call append(line("."), "/************************************************************")
call append(line(".")+1, "Copyright(C) 1997-".strftime("%Y").", Tech. Co.,Ltd.")
call append(line(".")+2, "FileName: ".expand("%"))
call append(line(".")+3, "Author: zachary")
call append(line(".")+4, "Date: ".strftime("%c"))
call append(line(".")+5, "Last Modified: ")
call append(line(".")+6, "Version: <++>")
call append(line(".")+7, "Description: <++>")
call append(line(".")+8, "***********************************************************/")
call append(line(".")+9, "<++>")
elseif &filetype == 'java'
call setline(1, "/**")
call append(line("."), "* @description <++>")
call append(line(".")+1, "* @author zachary")
call append(line(".")+2, "* @version <++>")
call append(line(".")+3, "* @date ".strftime("%c"))
call append(line(".")+4, "*/")
call append(line(".")+5, "<++>")
elseif &filetype == "sh"
call setline(1, "\#!/bin/bash")
call append(line("."), "")
call append(line(".")+1, "\#########################################################################")
call append(line(".")+2, "\# File Name: ".expand("%"))
call append(line(".")+3, "\# Created Time: ".strftime("%c"))
call append(line(".")+4, "\# Author: zachary")
call append(line(".")+5, "\# Last Modified: ")
call append(line(".")+6, "\# Description: <++>")
call append(line(".")+7, "\#########################################################################")
call append(line(".")+8, "<++>")
elseif &filetype == 'plaintex'
call setline(1,"% -*- coding:UTF-8 -*-")
call append(line("."),"% #########################################################################")
call append(line(".")+1, "% File Name: ".expand("%"))
call append(line(".")+2, "% Author: stubborn vegeta")
call append(line(".")+3, "% Created Time: ".strftime("%c"))
call append(line(".")+4, "% #########################################################################")
call append(line(".")+5, "\\documentclass[UTF8]{<++>}")
call append(line(".")+6, "\\usepackage{graphicx}")
call append(line(".")+7, "\\usepackage{booktabs}")
call append(line(".")+8, "\\usepackage{geometry}")
call append(line(".")+9, "\\geometry{left=2.5cm,right=2.5cm,top=2.5cm,bottom=2.5cm}")
call append(line(".")+10, "\\pagestyle{plain}")
call append(line(".")+11, "\\begin{document}")
call append(line(".")+12, "<++>")
call append(line(".")+13, "\\end{document}")
elseif &filetype == 'tex'
call setline(1,"% -*- coding:UTF-8 -*-")
call append(line("."),"% #########################################################################")
call append(line(".")+1, "% File Name: ".expand("%"))
call append(line(".")+2, "% Author: stubborn vegeta")
call append(line(".")+3, "% Created Time: ".strftime("%c"))
call append(line(".")+4, "% #########################################################################")
call append(line(".")+5, "\\documentclass[UTF8]{<++>}")
call append(line(".")+6, "\\usepackage{graphicx}")
call append(line(".")+7, "\\usepackage{booktabs}")
call append(line(".")+8, "\\usepackage{geometry}")
call append(line(".")+9, "\\geometry{left=2.5cm,right=2.5cm,top=2.5cm,bottom=2.5cm}")
call append(line(".")+10, "\\pagestyle{plain}")
call append(line(".")+11, "\\begin{document}")
call append(line(".")+12, "<++>")
call append(line(".")+13, "\\end{document}")
endif
" normal G
endfunc
" --------------------------------------------}}}
" === Modify datetime ======================={{{
function SetLastModifiedTime(lineno)
let modif_time = strftime("%Y-%m-%d %H:%M:%S")
if a:lineno == "-1"
let line = getline(7)
else
let line = getline(a:lineno)
endif
if line =~ '\sLast Modified:'
let line = strpart(line, 0, stridx(line, ":")) . ": " . modif_time
endif
if a:lineno == "-1"
call setline(7, line)
else
call append(a:lineno, line)
endif
endfunc
" map the SetLastModifiedTime command automatically
noremap upd :call SetLastModifiedTime(-1)<CR>
" -------------------------------------------}}}
" ===
" === Necessary Commands to Execute
" ===
exec "nohlsearch"
simple vim config
最新推荐文章于 2021-04-13 11:14:00 发布