我的nvim配置

" __ _____ __ __ ____ ____ ____ ___ _ _ _____ ___ ____
" \ \ / /_ | / | _ \ / | / / _ | \ | | | / |
" \ \ / / | || |/| | |
) | | | | | | | | | | |
| | | _
" \ V / | || | | | _ <| |
| |
| |
| | |\ | | | | || |
" _/ |
|
| |
|| _\| __/|| _|| |___|
"
"
" ===
" === Auto load for first time uses
" ===首次使用自动加载

if empty(glob(‘~/.config/nvim/autoload/plug.vim‘))
silent !curl -fLo ~/.config/nvim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif

let mapleader=" "
let g:SnazzyTransparent = 1
let g:lightline = {
\ ‘colorscheme‘: ‘snazzy‘,
\ }
let &t_SI = "<Esc>]50;CursorShape=1\x7"
let &t_SR = "<Esc>]50;CursorShape=2\x7"
let &t_EI = "<Esc>]50;CursorShape=0\x7"

filetype on
filetype indent on
filetype plugin on
filetype plugin indent on

set fileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936
set termencoding=utf-8
set encoding=utf-8

set relativenumber
set number
set mouse=a
let &t_ut=‘‘
set expandtab
set tabstop=4
set shiftwidth=4
set softtabstop=4
set list
set listchars=tab:?\ ,trail:?
set scrolloff=7
set tw=0
set indentexpr=
set backspace=indent,eol,start
"set foldmethod=indent
set foldlevel=99
set foldenable
set viewoptions=cursor,folds,slash,unix
set laststatus=2
set autochdir
au BufReadPost * if line("‘"") > 1 && line("‘"") <= line("$") | exe "normal! g‘"" | endif
set nocompatible
set number
set cursorline
syntax on
set wrap
set wildmenu
set showcmd
set incsearch
set hlsearch
set ignorecase
set clipboard=unnamedplus
"set clipboard+=unnamed

" noremap tab

noremap K 5k
noremap J 5j
noremap q h
noremap e l
noremap :nohlsearch
"noremap z v
noremap X c

"spelling check keyboard
map ck :set spell!
noremap ss [s
noremap s ]s
noremap mo eas
inoremap eas

map W :w
map Q :q
map S :wq
map shell :r!
map R :source $MYVIMRC
map rg :RnvimrToggle
" map os :w !sudo tee %

" spilling vim windos
map sl :set splitright:vsplit
map sh :set nosplitright:vsplit
map sj :set nosplitbelow:split
map sk :set splitbelow:split
" focus or resize the vim window
map dl l
map dh h
map dj j
map dk k

map :res +5
map :res -5
map :vertical resize-5
map :vertical resize+5

" create a new vim window and focus
map tj :tabe
map th :-tabnext
map tl :+tabnext

"Ctrl+a
map ggVG
map! ggVGY
map gg=G
"Ctrl+c
vmap "+y

" Rotate screens
noremap srh bK
noremap srv bH

" make markdown notes become html
" map html :%TOhtmlS

" press space twice to jump next
map /<++>:nohlsearchc4l

"some useful function
" :inoremap ( (<++>) /<++>:nohlsearchc4l
" :inoremap ) a()i
" :inoremap { {<++>} /<++>:nohlsearchc4l
" :inoremap } a{}i
" :inoremap [ [<++>] /<++>:nohlsearchc4l
" :inoremap ] a[]i
":inoremap " ""<++>""<++>/"<++>":nohlsearchc6l
" :inoremap ‘ ‘‘i
"":inoremap < <>i
"":inoremap > i<>i

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""new file tital:
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"first build the *.c, *.cpp, .sh, .sh and auto insert file headers
autocmd BufNewFile .cpp,.[ch],
.sh,
.java exec ":call SetTitle()"

func SetTitle()
"shell:
if &filetype == ‘sh‘
call setline(1,"#########################################################################")
call append(line("."), "# File Name: ".expand("%"))
call append(line(".")+1, "# Author: sorria")
call append(line(".")+2, "# mail: ")
call append(line(".")+3, "# Created Time: ".strftime("%c"))
call append(line(".")+4, "#########################################################################")
call append(line(".")+5, "#!/bin/bash")
call append(line(".")+6, "")
endif
if &filetype == ‘cpp‘
call append(line(".")+6, "#include")
call append(line(".")+7, "using namespace std;")
call append(line(".")+8, "int main(int argc,char *argv[]){")
call append(line(".")+9, " ")
call append(line(".")+10," return 0;")
call append(line(".")+11, "}")
endif
if &filetype == ‘c‘
call append(line(".")+6, "#include<stdio.h>")
call append(line(".")+7, "int main(int argc,char *argv[]){")
call append(line(".")+8, " ")
call append(line(".")+9," return 0;")
call append(line(".")+10, "}")
endif
"after build the file, auto locate to file-tail
autocmd BufNewFile * normal G
endfunc
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

" ====Plugins

call plug#begin(‘~/.config/nvim/plugged‘)
"Vim theme plugs
Plug ‘vim-airline/vim-airline‘
Plug ‘vim-airline/vim-airline-themes‘
Plug ‘lervag/vimtex‘
let g:airline_theme=‘simple‘
let g:airline_powerline_fonts = 1
let g:airline#extensions#branch#enabled = 1
let g:airline#extensions#syntastic#enabled = 1
let g:airline_detect_paste = 1
let g:airline#extensions#whitespace#enabled = 1
let g:airline_detect_modified = 1
let g:airline#extensions#tagbar#enabled = 1
let g:airline#extensions#tagbar#flags = ‘p‘

Plug ‘connorholyday/vim-snazzy‘
Plug ‘tomasr/molokai‘
Plug ‘altercation/vim-colors-solarized‘
let g:solarized_termcolors = 256
let g:solarized_termtrans = 1
let g:solarized_contrast = "normal"
let g:solarized_visibility = "low"

Plug ‘bling/vim-bufferline‘
"Plug ‘liuchengxu/eleline.vim‘
Plug ‘makerj/vim-pdf‘
let g:rehash256 = 1
let g:molokai_original = 1

" error checking
" Plug ‘w0rp/ale‘

" File navigation
Plug ‘scrooloose/nerdtree‘, { ‘on‘: ‘NERDTreeToggle‘ }
Plug ‘Xuyuanp/nerdtree-git-plugin‘
Plug ‘jistr/vim-nerdtree-tabs‘

" prople
" Taglist
Plug ‘majutsushi/tagbar‘, { ‘on‘: ‘TagbarOpenAutoClose‘ }
map T :Tagbar

" Markdown
Plug ‘iamcco/markdown-preview.nvim‘, { ‘do‘: { -> mkdp#util#install_sync() }, ‘for‘ :[‘markdown‘, ‘vim-plug‘] }
Plug ‘dhruvasagar/vim-table-mode‘, { ‘on‘: ‘TableModeToggle‘ }
Plug ‘vimwiki/vimwiki‘

" Bookmarks
Plug ‘kshenoy/vim-signature‘

" Dependencies
Plug ‘MarcWeber/vim-addon-mw-utils‘
Plug ‘kana/vim-textobj-user‘
Plug ‘fadein/vim-FIGlet‘

" coc
Plug ‘neoclide/coc.nvim‘, {‘branch‘: ‘release‘}

" nerd commentater
Plug ‘preservim/nerdcommenter‘
noremap C \c

" ranger with flow window
Plug ‘kevinhwang91/rnvimr‘, {‘do‘: ‘make sync‘}

" Far.vim makes it easier to find and replace text through multiple files.
Plug ‘brooth/far.vim‘

let g:SnazzyTransparent = 1
"color snazzy

"let g:airline#extensions#tabline#enabled = 1

" Undo tree
Plug ‘mbbill/undotree‘

" vim startify
Plug ‘mhinz/vim-startify‘

" fzf
Plug ‘junegunn/fzf‘, { ‘dir‘: ‘~/.fzf‘, ‘do‘: ‘./install --all‘ }
Plug ‘junegunn/fzf.vim‘
Plug ‘mattn/emmet-vim‘
call plug#end()

"colorscheme snazzy
colorscheme molokai

" 编译函数
" Compile function
map run :call CompileRunGcc()
func! CompileRunGcc()
exec "w"
if &filetype == ‘c‘
exec "!g++ % -o %<"
exec "! ./%<"
elseif &filetype == ‘cpp‘
exec "!g++ % -o %<"
exec "! ./%<"
elseif &filetype == ‘java‘
exec "!javac %"
exec "!time java %<"
elseif &filetype == ‘sh‘
:! bash %
elseif &filetype == ‘python‘
silent! exec "!clear"
exec "!time python3 %"
elseif &filetype == ‘html‘
exec "!google-chrome-stable % &"
elseif &filetype == ‘markdown‘
exec "MarkdownPreview"
elseif &filetype == ‘vimwiki‘
exec "MarkdownPreview"
endif
endfunc

" ===
" === Jekyll preview
" ===
" Automatically browse your Jekyll article on web browsers.
map :term bash start-serve.sh

" ===
" === NERDTree
" ===
map tt :NERDTreeToggle
let NERDTreeMapOpenExpl = ""
let NERDTreeMapUpdir = ""
let NERDTreeMapUpdirKeepOpen = "l"
let NERDTreeMapOpenSplit = ""
let NERDTreeOpenVSplit = ""
let NERDTreeMapActivateNode = "i"
let NERDTreeMapOpenInTab = "o"
let NERDTreeMapPreview = ""
let NERDTreeMapCloseDir = "n"
let NERDTreeMapChangeRoot = "y"
let NERDTreeShowLineNumbers=1
let NERDTreeShowHidden=1
let NERDTreeWinSize=25
" automatically startup NERDTree when open a file using nvim then focus the file instead of nerdtree toggle.
autocmd vimenter * NERDTree
autocmd vimenter * NERDTreeFocusToggle
let g:nerdtree_tabs_smart_startup_focus=2
" automatically startup NERDTree when open a directory using nvim
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * if argc() == 1 && isdirectory(argv()[0]) && !exists("s:std_in") | exe ‘NERDTree‘ argv()[0] | wincmd p | ene | exe ‘cd ‘.argv()[0] | endif

" ==
" == NERDTree-git
" ==
" It will show some statuses of file which is github repository using some icons like following that
let g:NERDTreeIndicatorMapCustom = {
\ "Modified" : "?",
\ "Staged" : "?",
\ "Untracked" : "?",
\ "Renamed" : "?",
\ "Unmerged" : "═",
\ "Deleted" : "?",
\ "Dirty" : "?",
\ "Clean" : "??",
\ "Unknown" : "?"
\ }

" ===
" === MarkdownPreview
" ===
" When you with your md file you will see your contents on web browsers
let g:mkdp_auto_start = 0
let g:mkdp_auto_close = 1
let g:mkdp_refresh_slow = 0
let g:mkdp_command_for_global = 0
let g:mkdp_open_to_the_world = 0
let g:mkdp_open_ip = ‘‘
let g:mkdp_browser = ‘google-chrome-stable‘
let g:mkdp_echo_preview_url = 0
let g:mkdp_browserfunc = ‘‘
let g:mkdp_preview_options = {
\ ‘mkit‘: {},
\ ‘katex‘: {},
\ ‘uml‘: {},
\ ‘maid‘: {},
\ ‘disable_sync_scroll‘: 0,
\ ‘sync_scroll_type‘: ‘middle‘,
\ ‘hide_yaml_meta‘: 1
\ }
let g:mkdp_markdown_css = ‘‘
let g:mkdp_highlight_css = ‘‘
let g:mkdp_port = ‘‘
let g:mkdp_page_title = ‘「${name}」‘

" ===
" === some keys
" ===
source ~/.config/nvim/snappits.vim

" ===
" === vim-table-mode
" ===
" It will automatically full up md syntax of table.
map tm :TableModeToggle

" ===
" === coc-key-mapping
" ===
" It includes many useful language extensions.
" if hidden is not set, TextEdit might fail.
set hidden

" Some servers have issues with backup files, see #649
set nobackup
"(不保留备份文件)
set noswapfile
"不生成交换文件
set nowritebackup

" Better display for messages
set cmdheight=2

" You will have bad experience for diagnostic messages when it‘s default 4000.
set updatetime=300

" don‘t give |ins-completion-menu| messages.
set shortmess+=c

" always show signcolumns
set signcolumn=yes

" Use tab for trigger completion with characters ahead and navigate.
" Use command ‘:verbose imap ‘ to make sure tab is not mapped by other plugin.
inoremap
\ pumvisible() ? "<C-n>" :
\ check_back_space() ? "<TAB>" :
\ coc#refresh()
inoremap pumvisible() ? "<C-p>" : "<C-h>"

function! s:check_back_space() abort
let col = col(‘.‘) - 1
return !col || getline(‘.‘)[col - 1] =~# ‘\s‘
endfunction

" Use to trigger completion.
inoremap coc#refresh()

" Use to confirm completion, <C-g>u means break undo chain at current position.
" Coc only does snippet and additional edit on confirm.
inoremap pumvisible() ? "<C-y>" : "<C-g>u<CR>"
" Or use complete_info if your vim support it, like:
" inoremap complete_info()["selected"] != "-1" ? "<C-y>" : "<C-g>u<CR>"

" Use [g and ]g to navigate diagnostics
nmap [g (coc-diagnostic-prev)
nmap ]g (coc-diagnostic-next)

" Remap keys for gotos
nmap gd (coc-definition)
nmap gy (coc-type-definition)
nmap gi (coc-implementation)
nmap gr (coc-references)

" Use K to show documentation in preview window
"nnoremap K :call show_documentation()

function! s:show_documentation()
if (index([‘vim‘,‘help‘], &filetype) >= 0)
execute ‘h ‘.expand(‘‘)
else
call CocAction(‘doHover‘)
endif
endfunction

" Highlight symbol under cursor on CursorHold
autocmd CursorHold * silent call CocActionAsync(‘highlight‘)

" Remap for rename current word
nmap rn (coc-rename)

" Remap for format selected region
xmap f (coc-format-selected)
nmap f (coc-format-selected)

augroup mygroup
autocmd!
" Setup formatexpr specified filetype(s).
autocmd FileType typescript,json setl formatexpr=CocAction(‘formatSelected‘)
" Update signature help on jump placeholder
autocmd User CocJumpPlaceholder call CocActionAsync(‘showSignatureHelp‘)
augroup end

" Remap for do codeAction of selected region, ex: <leader>aap for current paragraph
xmap a (coc-codeaction-selected)
nmap a (coc-codeaction-selected)

" Remap for do codeAction of current line
nmap ac (coc-codeaction)
" Fix autofix problem of current line
nmap qf (coc-fix-current)

" Create mappings for function text object, requires document symbols feature of languageserver.
xmap if (coc-funcobj-i)
xmap af (coc-funcobj-a)
omap if (coc-funcobj-i)
omap af (coc-funcobj-a)

" Use for select selections ranges, needs server support, like: coc-tsserver, coc-python
nmap (coc-range-select)
xmap (coc-range-select)

" Use :Format to format current buffer
command! -nargs=0 Format :call CocAction(‘format‘)
map cf :Fold
" Use :Fold to fold current buffer
command! -nargs=? Fold :call CocAction(‘fold‘, )

" use :OR for organize import of current buffer
command! -nargs=0 OR :call CocAction(‘runCommand‘, ‘editor.action.organizeImport‘)

" Add status line support, for integration with other plugin, checkout :h coc-status
set statusline^=%{coc#status()}%{get(b:,‘coc_current_function‘,‘‘)}

" Using CocList
" Show all diagnostics
nnoremap a :CocList diagnostics
" Manage extensions
nnoremap e :CocList extensions
" Show commands
nnoremap c :CocList commands
" Find symbol of current document
nnoremap o :CocList outline
" Search workspace symbols
nnoremap s :CocList -I symbols
" Do default action for next item.
nnoremap j :CocNext
" Do default action for previous item.
nnoremap k :CocPrev
" Resume latest coc list
nnoremap p :CocListResume

" fix the most annoying bug that coc has
silent! au BufEnter,BufRead,BufNewFile * silent! unmap if
let g:coc_global_extensions = [‘coc-python‘, ‘coc-vimlsp‘, ‘coc-html‘, ‘coc-json‘, ‘coc-css‘, ‘coc-tsserver‘, ‘coc-yank‘, ‘coc-lists‘, ‘coc-gitignore‘, ‘coc-vimlsp‘, ‘coc-tailwindcss‘, ‘coc-stylelint‘]
set statusline^=%{coc#status()}%{get(b:,‘coc_current_function‘,‘‘)}
" use for trigger completion and navigate to the next complete item
function! s:check_back_space() abort
let col = col(‘.‘) - 1
return !col || getline(‘.‘)[col - 1] =~ ‘\s‘
endfunction
inoremap
\ pumvisible() ? "<C-n>" :
\ check_back_space() ? "<Tab>" :
\ coc#refresh()
inoremap pumvisible() ? "<C-p>" : "<S-Tab>"
inoremap coc#refresh()
" Useful commands
nnoremap y :CocList -A --normal yank
nmap gd (coc-definition)
nmap gy (coc-type-definition)
nmap gi (coc-implementation)
nmap gr (coc-references)
nmap rn (coc-rename)

" ===
" === fastfold (some function have been replace by COC)
" ===

"noremap o zo
"
"nmap zuz (FastFoldUpdate)
"let g:fastfold_savehook = 1
"let g:fastfold_fold_command_suffixes = [‘x‘,‘X‘,‘a‘,‘A‘,‘o‘,‘O‘,‘c‘,‘C‘]
"let g:fastfold_fold_movement_commands = [‘]z‘, ‘[z‘, ‘ze‘, ‘zu‘]
"
"let g:markdown_folding = 1
"let g:tex_fold_enabled = 1
"let g:vimsyn_folding = ‘af‘
"let g:xml_syntax_folding = 1
"let g:javaScript_fold = 1
"let g:sh_fold_enabled= 7
"let g:ruby_fold = 1
"let g:perl_fold = 1
"let g:perl_fold_blocks = 1
"let g:r_syntax_folding = 1
"let g:rust_fold = 1
"let g:php_folding = 1

" ===
" === Far.vim
" ===
noremap f :F %
"set lazyredraw " improve scrolling performance when navigating through large results
"set regexpengine=1 " use old regexp engine
"set ignorecase smartcase " ignore case only when the pattern contains no capital letters
"" shortcut for far.vim find
"nnoremap :Farf
"vnoremap :Farf
"" shortcut for far.vim replace
"nnoremap :Farr
"vnoremap :Farr

" ===
" === Undotree
" ===
noremap L :UndotreeToggle
let g:undotree_DiffAutoOpen = 1
let g:undotree_SetFocusWhenToggle = 1
let g:undotree_ShortIndicators = 1
let g:undotree_WindowLayout = 2
let g:undotree_DiffpanelHeight = 8
let g:undotree_SplitWidth = 24
function g:Undotree_CustomMap()
nmap u UndotreeNextState
nmap e UndotreePreviousState
nmap U 5UndotreeNextState
nmap E 5UndotreePreviousState
endfunc
"
"Markers
"
"Every change has a sequence number and it is displayed before timestamps.
"The current state is marked as > number <.
"The next state which will be restored by :redo or is marked as { number }.
"The [ number ] marks the most recent change.
"The undo history is sorted by timestamps.
"Saved changes are marked as s and the big S indicates the most recent saved change.
"

" ===
" === FZF
" ===

map ff :FZF

" ===
" === emmet
" ===
let g:user_emmet_leader_key=‘‘

相关推荐