Git Product home page Git Product logo

.emacs.d's Introduction

谁明我心 👋

I'm daodao2007

Github Overview

  Top Langs

🛠 技术栈 | Tech Stack

  • 💻   C++ GO rust python TypeScript Linux
  • 🌐   HTML5 React Node.js Vue.js
  • 🛢   MySQL PostgreSQL redis
  • 🔧  Git GitHub Markdown

.emacs.d's People

Contributors

facetop avatar

Watchers

 avatar

.emacs.d's Issues

vim

" =======================================
" ===============插件管理================
" =======================================
"
" Specify a directory for plugins
" - For Neovim: stdpath('data') . '/plugged'
" - Avoid using standard Vim directory names like 'plugin'
call plug#begin('~/.vim/plugged')

" Make sure you use single quotes

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

Plug 'morhetz/gruvbox'

Plug 'mhinz/vim-startify'

Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' }

Plug 'tpope/vim-fugitive'

if has('nvim') || has('patch-8.0.902')
  Plug 'mhinz/vim-signify'
else
  Plug 'mhinz/vim-signify', { 'branch': 'legacy' }
endif

Plug 'sheerun/vim-polyglot'

Plug 'editorconfig/editorconfig-vim'

Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }

Plug 'junegunn/fzf.vim'

lug 'junegunn/gv.vim'

Plug 'luochen1990/rainbow'

Plug 'skywind3000/asyncrun.vim'

Plug 'mg979/vim-visual-multi', {'branch': 'master'}

Plug 'tpope/vim-repeat'

Plug 'tpope/vim-surround'

Plug 'tpope/vim-commentary'

Plug 'tpope/vim-sensible'

Plug 'tpope/vim-markdown'

Plug 'preservim/tagbar'

Plug 'haya14busa/incsearch.vim'

Plug 'vim-airline/vim-airline'

Plug 'vim-airline/vim-airline-themes'

Plug 'mbbill/undotree'

" Initialize plugin system
call plug#end()

"================================
"==============配置==============
"================================
"
" 设置leader键"
let mapleader=' '

" vim 按键
set nocompatible

" gui 字体
if has("gui_running")
	set guifont=SourceCodePro-Medium:h14
	set guioptions-=m
	set guioptions-=T

	source $VIMRUNTIME/delmenu.vim
	source $VIMRUNTIME/menu.vim
endif

" 默认更新时间
set updatetime=100

" fold
" set foldmethod=indent

" tab 空格
set tabstop=4
set softtabstop=4
set shiftwidth=4
set noexpandtab 
" expandtab

" 设置剪贴板
set clipboard=unnamed

" 带有如下符号的单词不要被换行分割
set iskeyword+=_,$,@,%,#,-

" 高亮第 80 列,推荐
set colorcolumn=80

"设置水平/和竖直突出显示
set cursorline

" 显示窗口比较小的时候折行展示,不然需要水平翻页,推荐
set linebreak

" 设置行号
set number
set relativenumber

"编码设置
set encoding=utf-8
set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1
set fileformats=unix,dos,mac
set termencoding=utf-8
set formatoptions+=m
set formatoptions+=

" 设置语言
set langmenu=zh_CN.UTF-8
set helplang=cn

" 设置回到vim再上次的位置
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif


" ===================================
" ============== 移动光标============
" ===================================
" J K 快速移动上下五行
noremap <silent> K 5k
noremap <silent> J 5j

"  快速到行首
noremap H 0
"  快速到行尾
noremap L $

" 快速的单词跳转
noremap W 5w
noremap B 5b

" 查找和替换
noremap \s :%s//g<left><left>

" 查找到的内容居中
nnoremap Y y$

" 插入模式下kj返回normal模式
inoremap jk <Esc>

"===============================
"=========== coc.nvim ==========
"===============================
" coc-marketplace/coc-go/coc-rust/coc-explorer
" coc-sh/coc-xml/coc-json/coc-yaml/coc-yank/coc-pyright
" coc-pairs/coc-lists/coc-lua/coc-clangd
" coc-cmake/coc-snippets

" TAB 补全
inoremap <silent><expr> <TAB>
      \ pumvisible() ? "\<C-n>" :
      \ <SID>check_back_space() ? "\<TAB>" :
      \ coc#refresh()
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"

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

" ENTER 补全第一个
inoremap <silent><expr> <cr> pumvisible() ? coc#_select_confirm()
                              \: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"

" 错误诊断跳转
nmap <silent> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <Plug>(coc-diagnostic-next)

" 代码跳转
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)

" <C-u> 删除之前的文本
" 调用CocList
noremap <silent><nowait> <leader>ll :<C-u>CocList<CR>
noremap <silent><nowait> <leader>ld :<C-u>CocList diagnostics<CR>
noremap <silent><nowait> <leader>le :<C-u>CocList extensions<CR>
noremap <silent><nowait> <leader>lc :<C-u>CocList commands<CR>
noremap <silent><nowait> <leader>lo :<C-u>CocList outline<CR>
noremap <silent><nowait> <leader>ls :<C-u>CocList -I symbols<CR>
noremap <silent><nowait> <leader>lp :<C-u>CocListResume<CR>
noremap <silent><nowait> <leader>lm :<C-u>CocList marketplace<CR>
noremap <silent><nowait> <leader>ln :<C-u>CocList snippets<CR>

" yank: coc-yank
noremap <silent><nowait> <leader>ly  :<C-u>CocList -A --normal yank<cr>

" buffers
noremap <silent><nowait> <leader>bb :<C-u>CocList buffers<CR>
noremap <silent><nowait> <leader>bn :<C-u>bn<CR>
noremap <silent><nowait> <leader>bp :<C-u>bp<CR>
noremap <silent><nowait> <leader>bd :<C-u>bd<CR>
noremap <silent><nowait> <leader>bd :<C-u>bd<CR>

" theme
noremap <silent><nowait> <leader>tt :<C-u>CocList colors<CR>

" files
noremap <silent><nowait> <leader>ff :<C-u>CocList files<CR>
noremap <silent><nowait> <leader>ft :<C-u>CocCommand explorer<CR>
noremap <silent><nowait> <leader>fs :<C-u>w<CR>
noremap <silent><nowait> <leader>fg :<C-u>TagbarToggle<CR>
noremap <silent><nowait> <leader>fr :<C-u>Ranger<CR>
noremap <silent><nowait> <leader>fd :<C-u>x<CR>

" git
noremap <silent><nowait> <leader>gg :<C-u>Gstatus<CR>
noremap <silent><nowait> <leader>gf :<C-u>Git fetch<CR>
noremap <silent><nowait> <leader>gs :<C-u>Git stash<CR>
noremap <silent><nowait> <leader>gb :<C-u>Git blame<CR>
noremap <silent><nowait> <leader>gs :<C-u>Git status<CR>
noremap <silent><nowait> <leader>gl :<C-u>Git log<CR>
noremap <silent><nowait> <leader>gi :<C-u>Git init<CR>
noremap <silent><nowait> <leader>gv :<C-u>GV<CR>

" bookmarks & Memo
noremap <silent><nowait> <leader>mm :<C-u>BookmarkToggle<CR>
noremap <silent><nowait> <leader>mi :<C-u>BookmarkAnnotate<CR>
noremap <silent><nowait> <leader>mn :<C-u>BookmarkNext<CR>
noremap <silent><nowait> <leader>mp :<C-u>BookmarkPrev<CR>
noremap <silent><nowait> <leader>ma :<C-u>BookmarkShowAll<CR>
noremap <silent><nowait> <leader>mc :<C-u>BookmarkClear<CR>
noremap <silent><nowait> <leader>mx :<C-u>BookmarkClearAll<CR>

noremap <silent><nowait> <leader>mo :<C-u>MemoNew<CR>
noremap <silent><nowait> <leader>ml :<C-u>MemoList<CR>

"" help
noremap <silent><nowait> <leader>hh :<C-u>CocList helptags<CR>
noremap <silent><nowait> <leader>hk :<C-u>CocList maps<CR>

"" windows
noremap <silent><nowait> <leader>ww :<C-u>CocList windows<CR>
noremap <silent><nowait> <leader>ws :<C-u>split<CR>
noremap <silent><nowait> <leader>wv :<C-u>vsplit<CR>
noremap <silent><nowait> <leader>wd :<C-u>q<CR>
noremap <silent><nowait> <leader>w1 :<C-u>only<CR>
noremap <silent><nowait> <leader>wo <C-w>w<CR>
noremap <silent><nowait> <leader>wh <C-w>h<CR>
noremap <silent><nowait> <leader>wj <C-w>j<CR>
noremap <silent><nowait> <leader>wk <C-w>k<CR>
noremap <silent><nowait> <leader>wl <C-w>l<CR>
noremap <silent><nowait> <leader>w= <C-w>=<CR>
noremap <silent><nowait> <leader>w<up>:<C-u>res +5<CR>
noremap <silent><nowait> <leader>w<down> :<C-u>res -5<CR>
noremap <silent><nowait> <leader>w<left> :<C-u>vertical resize -5<CR>
noremap <silent><nowait> <leader>w<right> :<C-u>veritcal resize +5<CR>

" search
noremap <silent><nowait> <leader>ss :<C-u>CocList words<CR>
noremap <silent><nowait> <leader>sa :<C-u>CocList grep<CR>
noremap <silent><nowait> <leader>sn :<C-u><nohlsearch<CR>

" isearch
map /  <Plug>(incsearch-forward)
map ?  <Plug>(incsearch-backward)
map g/ <Plug>(incsearch-stay)

map n  <Plug>(incsearch-nohl-n)
map N  <Plug>(incsearch-nohl-N)
map *  <Plug>(incsearch-nohl-*)
map #  <Plug>(incsearch-nohl-#)
map g* <Plug>(incsearch-nohl-g*)
map g# <Plug>(incsearch-nohl-g#)

" misc rename: 重命名
nnoremap <silent><nowait> <leader>rn <Plug>(coc-rename)
nnoremap <silent><nowait> <leader>ut :UndotreeToggle<CR>

""""go"""""
" go tags
autocmd FileType go noremap mta :<C-u>GoAddTags json<CR>
autocmd FileType go noremap mty :<C-u>GoAddTags yaml<CR>
autocmd FileType go noremap mtx :<C-u>GoAddTags xml<CR>
autocmd FileType go noremap mtd :<C-u>GoRemoveTags<CR>

" run & build
autocmd FileType go noremap mxx :<C-u>GoRun .<CR>
autocmd FileType go noremap mxb :<C-u>GoBuild .<CR>

" go debug
autocmd FileType go noremap mdd :<C-u>GoDebugBreakpoint<CR>
autocmd FileType go noremap mds :<C-u>GoDebugStart<CR>
autocmd FileType go noremap mdc :<C-u>GoDebugContinue<CR>
autocmd FileType go noremap mdk :<C-u>GoDebugStop<CR>

" check
autocmd FileType go noremap mee :<C-u>GoMetaLinter<CR>
autocmd FileType go noremap mev :<C-u>GoVet<CR>
autocmd FileType go noremap mel :<C-u>GoLint<CR>
autocmd FileType go noremap mec :<C-u>GoErrCheck<CR>

" impl
autocmd FileType go noremap mii :<C-u>GoImpl<CR>
autocmd FileType go noremap mim :<C-u>GoImplements<CR>
autocmd FileType go noremap mir :<C-u>GoReferres<CR>



"================================
"===========coc-pairs============
"================================
autocmd FileType tex let b:coc_pairs = [["$", "$"]]


"================================
"==========vim.go & coc-go=======
"================================
let g:go_fmt_command = "goimports"
let g:go_fmt_autosave = 1


"================================
"==========range.vim=============
"================================
let g:ranger_map_keys = 0


"================================
"===========rainbow==============
"================================
let g:rainbow_active = 1


"================================
"============theme=============
"================================
colorscheme gruvbox
set background=dark


"===============================
"========vim-commentary=========
"===============================
"为python和shell等添加注释
autocmd FileType python,shell set commentstring=#\ %s
"修改注释风格
autocmd FileType c,cpp,go,rust set commentstring=//\ %s


"==============================
"========incsearch.vim=========
"==============================
let g:incsearch#auto_nohlsearch = 1


"=============================
"==========Ack.vim============
"=============================
if executable('ag')
    let g:ackprg = 'ag --nogroup --nocolor --column'
endif


"=============================
"========vim-bookmarks========
"=============================
highlight BookmarkSign ctermbg=NONE ctermfg=160
highlight BookmarkLine ctermbg=194 ctermfg=NONE
let g:bookmark_no_default_key_mappings = 1


"=============================
"========asyncrun.vim=========
"=============================
let g:asyncrun_open = 8



.spacemacs

 auto-completion
 better-defaults
 git
 helm
 lsp
 (go :variables
     go-tab-width 4
     go-format-before-save t
     gofmt-command "goimports"
     go-use-golangci-lint t)

 (c-c++ :variables
        c-c++-backend 'lsp-clangd
        c++-enable-organize-includes-on-save t
        c-c++-enable-clang-format-on-save t
        c-c++-default-mode-for-headers 'c++-mode
        c-c++-enable-google-style t
        c-c++-enable-google-newline t
        c-c++-lsp-enable-semantic-highlight 'rainbow
        c-c++-adopt-subprojects t)

 (python :variables
         python-backend 'lsp
         python-lsp-server 'pyright
         python-test-runner 'pytest
         python-formatter 'black
         python-format-on-save t
         python-sort-imports-on-save t)
 (dart :variables
       lsp-dart-sdk-dir "~/flutter-sdk/bin/cache/dart-sdk/"
       lsp-enable-on-type-formatting t)
 rust
 emacs-lisp
 lua
 common-lisp
 markdown
 dap
 multiple-cursors
 org
 (shell :variables
        shell-default-height 30
        shell-default-position 'bottom)
 spell-checking
 syntax-checking
 version-control
 treemacs

slim

;;; init.el --- load the full configuration
;;; Commentary:

;; This file contains all config for my Emacs

;;; Code:

;; @see https://github.com/moscribe/emacs.d
;; @see https://github.com/seagle0128/.emacs.d
;; @see https://github.com/purcell/emacs.d

;;;;;;;;;;;;;;;
;;;; define
;;;;;;;;;;;;;;;;
(defvar default-package-mirror '(("melpa" . "https://melpa.org/packages/")
("org" . "https://orgmode.org/elpa/")
("gnu" . "https://elpa.gnu.org/packages/")))
(defvar emacs-china-package-mirror '(("gnu" . "http://elpa.emacs-china.org/gnu/")
("melpa" . "http://elpa.emacs-china.org/melpa/")
("org" . "http://elpa.emacs-china.org/org/")))
(defvar tuna-package-mirror '(("gnu" . "http://mirrors.tuna.tsinghua.edu.cn/elpa/gnu/")
("melpa" . "http://mirrors.tuna.tsinghua.edu.cn/elpa/melpa/")
("org" . "http://mirrors.tuna.tsinghua.edu.cn/elpa/org/")))

;;;;;;;;;;;;;;;;;
;;;; vars
;;;;;;;;;;;;;;;;;
(defvar user/emacs-min-version "26"
"User defined Use Emacs min Version.")
(defvar user/custom-file
(expand-file-name "cache/custom.el" user-emacs-directory))
(defvar user/emacs-ispell-dict
(expand-file-name "cache/hunspell_dict.txt" user-emacs-directory)
"User Ispell Dict Dir.")
(defvar user/org-note-dir "~/org"
"User defined notes directory.")
(defvar user/org-download-image-dir
(expand-file-name "images" user/org-note-dir)
"User defined org image download dir.")

(defvar user/normal-gc-cons-threshold (* 20 1024 1024))
(defvar user/init-gc-cons-threshold (* 128 1024 1024))
(defvar user/package-mirror tuna-package-mirror)
(defvar user/enable-benchmark-init t)
(defvar user/emacs-font "Source Code Pro Medium 14")

;;;;;;;;;;;;;;;;;;;;;;;
;;;; Initialize
;;;;;;;;;;;;;;;;;;;;;;;
(when (version< emacs-version user/emacs-min-version)
(error "Emacs %s or higher is required" user/emacs-min-version))

;; const
(defconst is-mac (eq system-type 'darwin))
(defconst is-win64 (eq system-type 'windows-nt))
(defconst is-linux (or (eq system-type 'gnu/linux) (eq system-type 'linux)))

(add-to-list 'load-path (expand-file-name "elisp" user-emacs-directory))
(add-to-list 'load-path (expand-file-name "lisp" user-emacs-directory))

;; adjust garbage collection thresholds during startup, and thereafter
(setq file-name-handler-alist nil)
(setq gc-cons-threshold user/init-gc-cons-threshold)
(add-hook 'emacs-startup-hook
(lambda () (setq gc-cons-threshold user/normal-gc-cons-threshold)))

;; custome-file
(setq custom-file user/custom-file)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; package
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq package-archives user/package-mirror)
(setq package-enable-at-startup nil)
(package-initialize) ;; 初始化

;; use-package installtion
(unless (package-installed-p 'use-package)
(package-refresh-contents)
(package-install 'use-package))

(require 'use-package)
(setq use-package-always-ensure t)

(use-package quelpa)
(use-package quelpa-use-package)

;;;;;;;;;;;;;;;;;;;;;;;;
;;;; benchmark
;;;;;;;;;;;;;;;;;;;;;;;;
(when user/enable-benchmark-init
(define-advice define-obsolete-function-alias (:filter-args (ll) fix-obsolete)
(let ((obsolete-name (pop ll))
(current-name (pop ll))
(when (if ll (pop ll) "1"))
(docstring (if ll (pop ll) nil)))
(list obsolete-name current-name when docstring)))
;; benchmark
(use-package benchmark-init
:hook (after-init . benchmark-init/deactivate)
:init (benchmark-init/activate)))

;;;;;;;;;;;;;;;;;;
;;;; config
;;;;;;;;;;;;;;;;;;

;; bar-mode 隐藏导航
(tool-bar-mode -1)
(menu-bar-mode -1)
(scroll-bar-mode -1)

;; frame 屏幕的状态栏显示异常
(setq-default
window-resize-pixelwise t
frame-resize-pixelwise t)

;; Suppress GUI features
(setq use-file-dialog nil)
(setq use-dialog-box nil)
(setq inhibit-startup-screen t)

;; 默认配置
(setq-default
blink-cursor-interval 0.4 ;; 光标闪烁
bookmark-default-file (locate-user-emacs-file ".bookmark.el") ;; 书签文件
column-number-mode t ;; 列数显示
fill-column 80 ;; 满列80
word-wrap t ;; 折叠
truncate-lines nil ;; 自动折行
truncate-partial-width-windows nil
scroll-step 1 ;; 滚动步数1
auto-image-file-mode t ;; 图片文件显示
indent-tabs-mode nil ;; tab缩进
tab-width 4 ;; tab缩进4空格
tab-always-indent nil ;; tab缩进
tooltip-delay 1.5 ;; tooltip 延迟时间
create-lockfiles nil ;; 不创建 lockfile
auto-save-default nil ;; 去掉自动保存
mouse-yank-at-point t ;; 鼠标复制粘贴
make-backup-files nil ;; 去掉备份文件
save-interprogram-paste-before-kill t ;; clipboard和kill ring交互
scroll-preserve-screen-position 'always
set-mark-command-repeat-pop t
)

;; font 字体大小
(when (not is-win64)
(set-face-attribute 'default nil :font user/emacs-font))

;; warn
(setq visible-bell nil
ring-bell-function 'ignore)

;; exec-path-from-shell
(when (not is-win64)
(use-package exec-path-from-shell
:config
(exec-path-from-shell-initialize)))

;; auto-package-update
(use-package auto-package-update
:defer 2
:init
(setq auto-package-update-delete-old-versions t
auto-package-update-hide-results t)
(defalias 'upgrade-packages #'auto-package-update-now))

;; restart-emcas
(use-package restart-emacs
:defer 2)

;; posframe
(use-package posframe
:defer 2)

;; auto revert
(use-package autorevert
:hook (after-init . global-auto-revert-mode)
:config
(setq global-auto-revert-non-file-buffers t
auto-revert-verbose nil))

;; saveplace
(use-package saveplace
:hook (after-init . save-place-mode))

;; hl-line
(use-package hl-line
:hook (after-init . global-hl-line-mode))

;; hideshow
(use-package hideshow
:diminish hs-minor-mode
:hook (prog-mode . hs-minor-mode)
:custom
(hs-special-modes-alist
(mapcar 'purecopy
'((c-mode "{" "}" "/[/]" nil nil)
(c++-mode "{" "}" "/[
/]" nil nil)
(go-mode "{" "}" "/[/]" nil nil)
(rust-mode "{" "}" "/[
/]" nil nil)))))

;; whitespace
(use-package whitespace
:hook ((prog-mode markdown-mode conf-mode) . whitespace-mode)
:config
(setq whitespace-style '(face trailing)))

;; so-long
(use-package so-long
:when (fboundp 'so-long-mode)
:config (global-so-long-mode 1))

;; vlf 大文件
(use-package vlf
:config
(defun ffap-vlf ()
"Find file at point with VLF."
(interactive)
(let ((file (ffap-file-at-point)))
(unless (file-exists-p file)
(error "File does not exist: %s" file))
(vlf file))))

;; subword
(use-package subword
:hook (after-init . global-subword-mode))

;; newcomment
(use-package newcomment
:ensure nil
:bind ([remap comment-dwim] . #'comment-or-uncomment)
:config
(defun comment-or-uncomment ()
(interactive)
(if (region-active-p)
(comment-or-uncomment-region (region-beginning) (region-end))
(if (save-excursion
(beginning-of-line)
(looking-at "\s-*$"))
(call-interactively 'comment-dwim)
(comment-or-uncomment-region (line-beginning-position) (line-end-position)))))
:custom
(comment-auto-fill-only-comments t))

;; calendar
(use-package calendar
:ensure nil
:custom (calendar-mark-holidays-flag t)
:config (setq calendar-chinese-all-holidays-flag t))

;; webjump
(use-package webjump
:ensure nil
:custom
(webjump-sites '(
;; Emacs.
("Emacs Home Page" .
"www.gnu.org/software/emacs/emacs.html")
("Savannah Emacs page" .
"savannah.gnu.org/projects/emacs")

               ;; Internet search engines.
               ("Baidu" .
                [simple-query "baidu.com"
                              "www.baidu.com/s?wd=" ""])
               ("DuckDuckGo" .
                [simple-query "duckduckgo.com"
                              "duckduckgo.com/?q=" ""])
               ("Google" .
                [simple-query "www.google.com"
                              "www.google.com/search?q=" ""])
               ("Google Groups" .
                [simple-query "groups.google.com"
                              "groups.google.com/groups?q=" ""])
               ("Wikipedia" .
                [simple-query "wikipedia.org" "wikipedia.org/wiki/" ""]))))

;; delsel 删除
(use-package delsel
:hook (after-init . delete-selection-mode))

;; recentf 最近文件
(use-package recentf
:hook (after-init . recentf-mode)
:config
(setq-default
recentf-max-saved-items 1000
recentf-exclude `("/tmp/" "/ssh:" ,(concat package-user-dir "/.*-autoloads\.el\'"))))

;; dired 目录
(use-package dired :ensure nil)

;; winner-mode 窗口恢复和重启
(use-package winner-mode
:ensure nil
:defer 2
:hook (after-init . winner-mode))

;; zoom 自动调整平衡
(use-package zoom
:defer 2)

;; zoom-window 单独显示某个窗口
(use-package zoom-window
:defer 2
:config
(custom-set-variables
'(zoom-window-mode-line-color "Dark")))

;; ranger 文件浏览器
(when (not is-win64)
;; ranger: https://github.com/ralesi/ranger.el
(use-package ranger
:defer 2))

;; paren 括号匹配
(use-package paren
:hook (after-init . show-paren-mode)
:config
(setq show-paren-when-point-inside-paren t
show-paren-when-point-in-periphery t))

;; smartparent 自动匹配
(use-package smartparens
:defer 2
:config
(require 'smartparens-config)
(smartparens-global-mode))

;; ispell 拼音检测
(use-package ispell
:config
(setq ispell-dictionary "en_US"
ispell-program-name "hunspell"
ispell-personal-dictionary user/emacs-ispell-dict))

;; selectrum补全框架
(use-package selectrum
:hook (after-init . selectrum-mode))

;; marginalia旁注
(use-package marginalia
:hook (after-init . marginalia-mode)
:config
(setq-default marginalia-annotators '(marginalia-annotator-heavy)))

;; selectrum-prescient 推荐
(use-package selectrum-prescient
:after selectrum
:bind (([remap execute-extended-command] . nil)
([remap execute-extended-command] . execute-extended-command))
:config
(selectrum-prescient-mode +1)
(prescient-persist-mode +1))

;; orderless 排序
(use-package orderless
:after selectrum
:config
(setq completion-styles '(orderless))
(setq orderless-skip-highlighting (lambda () selectrum-is-active))
(setq selectrum-highlight-candidates-function #'orderless-highlight-matches)
)

;; savehist保存历史
(use-package savehist
:init
(savehist-mode))

;; consult 补全框架
(use-package consult
:bind (([remap switch-to-buffer] . consult-buffer)
([remap switch-to-buffer-other-window] . consult-buffer-other-window)
([remap switch-to-buffer-other-frame] . consult-buffer-other-frame)
([remap goto-line] . consult-goto-line))
)

;; 目录和项目
(use-package consult-dir
:after consult
:config
(setq consult-dir-project-list-function #'consult-dir-projectile-dirs)
)

;; consult-flycheck
(use-package consult-flycheck
:after consult)

;; projectile 项目
(use-package projectile
:hook (after-init . projectile-mode)
:config
(setq-default consult-project-root-function 'projectile-project-root)
(setq-default projectile-mode-line-prefix " Proj"))

;; helpful 帮助
(use-package helpful)

;; doom-themes 主题
(use-package doom-themes
:init (load-theme 'doom-one t)
:config
(doom-themes-visual-bell-config)
(doom-themes-org-config)
(setq
doom-themes-enable-bold t
doom-themes-enable-italic t))

;; language 语言协议框架
(use-package eglot
:hook (prog-mode .(lambda ()
(unless (derived-mode-p 'emacs-lisp-mode 'lisp-mode 'makefile-mode)
(eglot-ensure))))
:config
(add-hook 'eglot-managed-mode-hook (lambda () (flymake-mode -1)))
)

;; modeline 状态栏
(use-package simple-modeline
:hook (after-init . simple-modeline-mode))

;; yasnippet 代码片段
(use-package yasnippet
:defer 2
:hook (prog-mode . yas-minor-mode)
:config
(setq yas-snippet-dirs
'("~/.emacs.d/snippets"))
(use-package yasnippet-snippets))

;; compnay 补全框架
(use-package company
:defer 2
:hook (after-init . global-company-mode)
:diminish company-mode
:bind (("M-C-/" . company-complete)
:map company-mode-map
("M-/" . company-complete)
([remap completion-at-point] . company-complete)
([remap indent-for-tab-command] . company-indent-or-complete-common)
:map company-active-map
("M-/" . company-other-backend)
("C-n" . company-select-next)
("C-p" . company-select-previous)
("C-d" . company-show-doc-buffer)
("M-." . company-show-location)
("RET" . company-complete-selection)
("" . company-complete-common-or-cycle)
("" . my/company-yasnippet)
)
:init
(defun my/company-yasnippet ()
"Hide the current completions and sho snippets"
(interactive)
(company-abort)
(call-interactively 'company-yasnippet))

:config
(setq
company-tooltip-align-annotations t
company-tooltip-limit 12
company-idle-delay 0
company-echo-delay (if (display-graphic-p) nil 0)
company-minimum-prefix-length 2
company-require-match nil
)

(defun company-yasnippet/disable-after-dot (fun command &optional arg &rest _ignore)
(if (eq command 'prefix)
(let ((prefix (funcall fun 'prefix)))
(when (and prefix (not
(eq
(char-before (- (point) (length prefix)))
?.)))
prefix))
(funcall fun command arg)))

(advice-add #'company-yasnippet :around #'company-yasnippet/disable-after-dot)
)

;; company-prescient 候选人排序
(use-package company-prescient
:after company
:hook (company-mode . company-prescient-mode))

;; quickhelp company快速帮助
(use-package company-quickhelp
:after company
:hook (global-company-mode . company-quickhelp-mode)
:defines company-quickhelp-delay
:bind (:map company-active-map
([remap company-show-doc-buffer] . company-quickhelp-manual-begin))
:init (setq company-quickhelp-delay 0.5)
)

;; flycheck 错误检查框架
(use-package flycheck
:defer 2
:hook (prog-mode . flycheck-mode)
:config
(setq flycheck-display-errors-function #'flycheck-display-error-messages-unless-error-list)
)

;; flycheck-posframe 错误检查弹框
(use-package flycheck-posframe
:after flycheck
:custom-face
(flycheck-posframe-face ((t (:foreground ,(face-foreground 'success)))))
(flycheck-posframe-info-face ((t (:foreground ,(face-foreground 'success)))))
:hook (flycheck-mode . flycheck-posframe-mode)
:init
(setq flycheck-posframe-border-width 4
flycheck-posframe-inhibit-functions
'((lambda (&rest _) (bound-and-true-p company-backend)))))

;; flycheck color
(use-package flycheck-color-mode-line
:after flycheck
:hook (flycheck-mode . flycheck-color-mode-line-mode))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; git
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; diff-hl git修改高亮
(use-package diff-hl
:config
(global-diff-hl-mode t)
(diff-hl-dired-mode t))

;; hl-todo 高亮TODO
(use-package hl-todo
:defer t
:hook (after-init . global-hl-todo-mode)
:config
(setq hl-todo-keyword-faces
'(("TODO" . "#FF0000")
("FIXME" . "#FF0000")
("DEBUG" . "#A020F0")
("GOTCHA" . "#FF4500")
("STUB" . "#1E90FF")))
)

;; magit git客户端
(use-package magit
:config
(when is-mac
(add-hook 'magit-mode-hook (lambda () (local-unset-key [(meta h)]))))
(setq-default magit-diff-refine-hunk t)
(setq auto-revert-check-vc-info t)
(setq magit-completing-read-function #'selectrum-completing-read))

;; fullframe
(use-package fullframe
:after magit
:config
(fullframe magit-status magit-mode-quit-window))

;; git todo 标识
(use-package magit-todos)

;; git-timemachine 时间线
(use-package git-timemachine)

;; git-commit
(use-package git-commit
:hook (git-commit-mode . goto-address-mode))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; python
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(use-package python
:ensure nil
:hook (inferior-python-mode . (lambda ()
(process-query-on-exit-flag
(get-process "Python"))))
:init
(setq python-shell-completion-native-enable nil)
:config
(when (and (executable-find "python3")
(string= python-shell-interpreter "python"))
(setq python-shell-interpreter "python3"))
)

;; live-py-mode
(use-package live-py-mode)

;; pip
(use-package pip-requirements)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; rust
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(use-package rustic
:config
(setq rustic-lsp-client 'eglot)
;; (setq rustic-lsp-server 'rls)
(setq rustic-analyzer-command '("~/.cargo/bin/rust-analyzer")))

;; rust-playground 教练场
(use-package rust-playground)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; go
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(use-package go-mode
:defer 2
:hook (go-mode . yas-minor-mode)
:bind
(:map go-mode-map
("C-c R" . go-remove-unused-imports)
("C-c D" . godoc-at-point))
:config
(setq tab-width 2)
;; Env vars
(when (not is-win64)
(with-eval-after-load 'exec-path-from-shell
(exec-path-from-shell-copy-envs '("GOPATH" "GO111MODULE" "GOPROXY")))
)
(setq gofmt-command "goimports")
(add-hook 'before-save-hook #'gofmt-before-save)

;; Install or update tools
(defvar go--tools '("golang.org/x/tools/gopls"
"golang.org/x/tools/cmd/goimports"
"honnef.co/go/tools/cmd/staticcheck"
"github.com/kisielk/errcheck"
"github.com/go-delve/delve/cmd/dlv"
"github.com/zmb3/gogetdoc"
"github.com/josharian/impl"
"github.com/cweill/gotests/..."
"github.com/fatih/gomodifytags"
"github.com/davidrjenni/reftools/cmd/fillstruct"
"github.com/golangci/golangci-lint/cmd/golangci-lint"
)
"All necessary go tools.")

(defun go-update-tools ()
"Install or update go tools."
(interactive)
(unless (executable-find "go")
(user-error "Unable to find go' in exec-path'!"))

(message "Installing go tools...")
(dolist (pkg go--tools)
  (set-process-sentinel
   (start-process "go-tools" "*Go Tools*" "go" "install" "-v" "-x" (concat pkg "@latest"))
   (lambda (proc _)
     (let ((status (process-exit-status proc)))
       (if (= 0 status)
           (message "Installed %s" pkg)
         (message "Failed to install %s: %d" pkg status))))))

(unless (executable-find "gopls")
  (go-update-tools))))

;; godoctor 重构
(use-package godoctor)

;; go-dlv 调试
(use-package go-dlv)
;; go-fill-struct 填充结构体
(use-package go-fill-struct)
;; gotest 测试
(use-package gotest)
;; go-impl 实现接口
(use-package go-impl)
;; go-gen-test 生产test文件
(use-package go-gen-test)

;; emacs-go-tag 添加tag
(use-package go-tag
:init (setq go-tag-args (list "-transform" "snakecase")))

;; go-playground
(use-package go-playground
:diminish
:commands (go-playground-mode))

;; go-errcheck 检测
(use-package go-errcheck)

;; flycheck-golangci-lint
(use-package flycheck-golangci-lint
:if (executable-find "golangci-lint")
:after flycheck
:defines flycheck-disabled-checkers
:hook (go-mode . (lambda ()
"Enable golangci-lint"
(setq flycheck-disabled-checkers '(go-gofmt
go-golint
go-vet
go-build
go-test
go-errcheck))
(flycheck-golangci-lint-setup))))

;; go-eldoc
(use-package go-eldoc
:hook (go-mode . go-eldoc-setup))

;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; cc
;;;;;;;;;;;;;;;;;;;;;;;;;;
(use-package cc-mode
:ensure nil
:bind (:map c-mode-base-map
("C-c c" . compile))
:hook (c-mode-common . (lambda () (c-set-style "stroustrup")))
:init (setq-default c-basic-offset 4))

(use-package modern-cpp-font-lock
:diminish
:hook (cc-mode . modern-c++-font-lock-global-mode))

(use-package cmake-ide
:init (cmake-ide-setup))

;;;;;;;;;;;;;;;;;;;;;;;;
;; lua
;;;;;;;;;;;;;;;;;;;;;;;;
(use-package lua-mode
:defer t
:delight "Λ "
:mode ("//.lua'" . lua-mode)
:interpreter ("lua" . lua-mode))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; elisp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(use-package elisp-mode
:ensure nil
:delight "ξ ")

;; eldoc
(use-package eldoc
:defer 2
:hook (emacs-lisp-mode . eldoc-mode))

;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; misc
;;;;;;;;;;;;;;;;;;;;;;;;;

;; youdao-dict 有道词典
(use-package youdao-dictionary)

;; docker 容器
(use-package docker)

;; docker compose 容器集合
(use-package docker-compose-mode)

;; dockerfile 容器配置
(use-package dockerfile-mode
:delight "δ "
:mode "Dockerfile\'")

;; sql-indent sql对齐
(use-package sql-indent
:after (:any sql sql-interactive-mode)
:delight sql-mode "Σ ")

;; ini 配置
(use-package ini-mode
:defer 2
:delight "I "
:mode ("\.ini\'"))

;; json 配置
(use-package json-mode
:defer t
:delight "J "
:mode "\.json\'")

;; yaml 配置
(use-package yaml-mode
:defer t
:delight "ψ "
:mode "\.yml\'")

;; restclient http客户端
(use-package restclient
:defer t)

;; rainbow parent 彩虹括号
(use-package rainbow-delimiters
:defer t
:hook (prog-mode . rainbow-delimiters-mode))

;; color-indentifier-mode 颜色标识
(use-package color-identifiers-mode
:defer t
:hook (after-init . global-color-identifiers-mode))

;; dumb-jump 跳转
(use-package dumb-jump
:defer t
:config
(add-hook 'xref-backend-functions #'dumb-jump-xref-activate))

;; format-all 格式化
(use-package format-all
:hook (go-mode . format-all-mode)
:hook (rust-mode . format-all-mode))

;; aggressive-indent 对齐
(use-package aggressive-indent
:hook (emacs-lisp-mode . aggressive-indent-mode)
:hook (rust-mode . aggressive-indent-mode)
:hook (go-mode . aggressive-indent-mode)
:hook (c-mode . aggressive-indent-mode)
:hook (c++-mode . aggressive-indent-mode)
:config
(add-to-list
'aggressive-indent-dont-indent-if
'(and (derived-mode-p 'c++-mode)
(null (string-match "\([;{}]\|\b\(if\|for\|while\)\b\)"
(thing-at-point 'line))))))

;; pomidor 番茄计时
(use-package pomidor
:config (setq pomidor-sound-tick nil
pomidor-sound-tack nil)
:hook (pomidor-mode . (lambda ()
(display-line-numbers-mode -1) ; Emacs 26.1+
(setq left-fringe-width 0 right-fringe-width 0)
(setq left-margin-width 2 right-margin-width 0)
;; force fringe update
(set-window-buffer nil (current-buffer)))))

;; markdown 标记文本
(use-package markdown-mode
:mode ("//.md//'" . markdown-mode))

;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; org
;;;;;;;;;;;;;;;;;;;;;;;;;
(use-package org)

;; org-superstar 修改样式
(use-package org-superstar
:after org
:defer t
:hook (org-mode . org-superstar-mode)
:init
(setq org-superstar-prettify-item-bullets t
org-superstar-headline-bullets-list '("◉" "✸" "⚫" "○" "•")
org-superstar-leading-bullet ?\s
org-hide-leading-stars t
org-superstar-item-bullet-alist '((?* . ?●)
(?+ . ?➤)
(?- . ?—))))

;; org-download 下载
(use-package org-download
:defer t
:after org
:config
(setq org-download-image-dir user/org-download-image-dir))

;; toc-org 目录标题
(use-package toc-org
:defer t
:after org
:hook (org-mode . toc-org-mode))

;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; vim
;;;;;;;;;;;;;;;;;;;;;;;;;;

;; evil vim按键模式模拟
(use-package evil
:init
(setq evil-want-keybinding nil
evil-ex-substitute-global t)
:config
(evil-mode 1)
;;; relative line number
(defun my-enable-relative-line-number ()
(interactive)
(display-line-numbers-mode -1)
(setq display-line-numbers-type 'relative)
(display-line-numbers-mode 1))

(defun my-disable-relative-line-number ()
(interactive)
(display-line-numbers-mode -1)
(setq display-line-numbers-type t)
(display-line-numbers-mode 1))

(add-hook 'evil-normal-state-entry-hook 'my-enable-relative-line-number)
(add-hook 'evil-insert-state-entry-hook 'my-disable-relative-line-number)
(add-hook 'evil-insert-state-exit-hook 'my-enable-relative-line-number))

;; evil-escape vim退出
(use-package evil-escape
;; :hook (evil-mode . evil-escape-mode)
:init(evil-escape-mode 1)
:bind ("C-g" . evil-escape)
:config (progn
(setq-default evil-escape-key-sequence "jk")
(setq-default evil-escape-delay 0.2)))

;; function tools
(defun my/open-init-file ()
"Edit the use-init-file, in another window."
(interactive)
(find-file user-init-file))

(defun my/kill-other-buffers ()
"Kill all buffers but the current one.
Doesn't mess with special buffers."
(interactive)
(seq-each
#'kill-buffer
(delete (current-buffer) (seq-filter #'buffer-file-name (buffer-list)))))

(defun my/save-all-buffers ()
"Save all buffers."
(interactive)
(seq-each
#'save-buffer (buffer-list)))

(defun my/fullscreen ()
"Set Fullscreen."
(interactive)
(set-frame-parameter nil 'fullscreen
(if (frame-parameter nil 'fullscreen) nil 'fullboth)))

(defun my/increase-window ()
"Increase window width and height."
(interactive)
(progn (evil-window-increase-width 25)
(evil-window-increase-height 25)))

(defun my/decrease-window ()
"Decrease window width and height."
(interactive)
(progn (evil-window-decrease-width 25)
(evil-window-decrease-height 25)))

;; general
(use-package general
:config
(general-evil-setup)

(general-define-key
:states '(normal visual motion)
:keymaps 'override
"gd" 'xref-find-definitions)

(general-define-key
:states '(normal visual motion)
:keymaps 'override
"gb" 'xref-find-references)

(general-define-key
:states '(normal visual motion)
:keymaps 'override
"C-o" 'xref-pop-marker-stack)

(general-define-key
:states)

(general-create-definer leader-key
:states '(normal visual motion emacs)
:prefix "SPC"
:keymaps 'override)

;; command
(leader-key "SPC" 'execute-extended-command) ;; 调用M-x

;; align
(leader-key
"aa" 'align-regexp
)

;; buffer
(leader-key
"b1" 'my/kill-other-buffers
"bb" 'consult-buffer
"bd" 'evil-delete-buffer
"bD" 'my/kill-other-buffers
"bn" 'evil-next-buffer
"bp" 'evil-prev-buffer
"bc" 'evil-buffer-new
"bm" 'consult-bookmark
"br" 'bookmark-delete
)

;; comment
(leader-key
"cc" 'comment-or-uncomment
"cr" 'comment-or-uncomment-region
)

;; diff & docker
(leader-key
"d3" 'ediff3
"dd" 'ediff-files
"db" 'ediff-buffers
"do" 'docker
)

;; file
(leader-key
"ff" 'find-file
"fo" 'consult-outline
"fc" 'dired-create-empty-file
"fd" 'dired-create-directory
"fs" 'save-buffer
"fr" 'ranger
"ft" 'dired
"fm" 'follow-mode
"fv" 'ediff
"fF" 'consult-find
"fS" 'my/save-all-buffers
"fR" 'rename-file
"FD" 'delete-file
)

;; git
(leader-key
"gs" 'magit-status
"gg" 'magit-dispatch
"gv" 'git-timemachine-toggle
"gr" 'consult-git-grep
)

;; windows
(leader-key
"w1" 'delete-other-windows
"w+" 'my/increase-window
"w-" 'my/decrease-window
"wu" 'winner-undo
"wr" 'winner-redo
"ws" 'evil-window-split
"wv" 'evil-window-vsplit
"wd" 'evil-window-delete
"wh" 'evil-window-left
"wj" 'evil-window-bottom
"wk" 'evil-window-up
"wl" 'evil-window-right
"wo" 'other-window
"wf" 'toggle-frame-fullscreen
"wz" 'zoom-window-zoom
"ww" 'zoom-window-next
"wD" 'delete-other-frames
)

;; search
(leader-key
"ss" 'consult-line
"sS" 'consult-line-multi
"sc" 'consult-compile-error
"sf" 'consult-flycheck
"sr" 'consult-ripgrep
"si" 'consult-imenu
"sI" 'consult-imenu-multi
)

;; project
(leader-key
"pp" 'consult-dir
"pa" 'projectile-add-known-project
)

;; org
(leader-key
"oo" 'consult-org-agenda
"oa" 'org-agenda
"oc" 'org-capture
"ob" 'org-switchb
"ow" 'org-refile
)

;; theme & dictionary
(leader-key
"tt" 'consult-theme
"tr" 'youdao-dictionary-search-at-point-posframe
"tR" 'youdao-dictionary-search-from-input
)

;; help
(leader-key
"hh" 'helpful-callable
"ha" 'consult-apropos
"hc" 'helpful-command
"hf" 'helpful-function
"hi" 'consult-man
"hk" 'helpful-key
"hm" 'helpful-macro
"hv" 'helpful-variable
"hp" 'helpful-at-point
)

;; view & browser
(leader-key
"vw" 'webjump
"vt" 'type-break
"vo" 'pomidor
"vl" 'consult-goto-line
)

;; emacs & package
(leader-key
"qq" 'save-buffers-kill-emacs
"qr" 'restart-emacs
"qu" 'upgrade-packages
)

;; go-mode-map
(leader-key go-mode-map
"ma" 'go-import-add
"mg" 'go-gen-test-dwim
"mR" 'go-remove-unused-imports
"md" 'dlv-current-func
"mD" 'dlv
"ml" 'go-impl
"ma" 'go-tag-add
"mr" 'go-tag-remove
"ms" 'go-fill-struct
"mf" 'gofmt-before-save
"m." 'godoc-at-point
"mx" 'go-run
"mp" 'go-playground
"mtf" 'go-test-current-file
"mtt" 'go-test-current-test
"mtp" 'go-test-current-project
"mtb" 'go-test-current-benchmark
"mtc" 'go-test-current-coverage
)

;; rustic-mode
(leader-key rustic-mode-map
"mx" 'rustic-compile
"ma" 'rustic-cargo-add
"mr" 'rustic-cargo-rm
"mu" 'rustic-cargo-upgrade
"mtt" 'rustic-cargo-current-test
"mtp" 'rustic-cargo-test
"mff" 'rustic-format-file
"mfb" 'rustic-format-buffer
"mfp" 'rustic-cargo-fmt
"mo" 'rustic-cargo-outdated
"my" 'rustic-cargo-clippy
)

)

(provide 'init)

;;; init.el ends here

slim vim

" =======================================
" ===============插件管理================
" =======================================
"
" Specify a directory for plugins
" - For Neovim: stdpath('data') . '/plugged'
" - Avoid using standard Vim directory names like 'plugin'
call plug#begin('~/.vim/plugged')

" Make sure you use single quotes

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

Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' }

Plug 'morhetz/gruvbox'

Plug 'mhinz/vim-startify'

Plug 'tpope/vim-fugitive'

if has('nvim') || has('patch-8.0.902')
  Plug 'mhinz/vim-signify'
else
  Plug 'mhinz/vim-signify', { 'branch': 'legacy' }
endif

Plug 'luochen1990/rainbow'

Plug 'skywind3000/asyncrun.vim'

Plug 'mg979/vim-visual-multi', {'branch': 'master'}

Plug 'tpope/vim-repeat'

Plug 'tpope/vim-surround'

Plug 'tpope/vim-commentary'

Plug 'tpope/vim-sensible'

Plug 'tpope/vim-markdown'

Plug 'haya14busa/incsearch.vim'

Plug 'vim-airline/vim-airline'

Plug 'vim-airline/vim-airline-themes'

Plug 'mbbill/undotree'

" Initialize plugin system
call plug#end()

"================================
"==============配置==============
"================================
"
" 设置leader键"
let mapleader=' '

" vim 按键
set nocompatible

" gui 字体
if has("gui_running")
	set guifont=SourceCodePro-Medium:h14
	set guioptions-=m
	set guioptions-=T

	source $VIMRUNTIME/delmenu.vim
	source $VIMRUNTIME/menu.vim
endif

" 默认更新时间
set updatetime=100

" fold
" set foldmethod=indent

" tab 空格
set tabstop=4
set softtabstop=4
set shiftwidth=4
set noexpandtab 
" expandtab

" 设置剪贴板
set clipboard=unnamed

" 带有如下符号的单词不要被换行分割
set iskeyword+=_,$,@,%,#,-

" 高亮第 80 列,推荐
set colorcolumn=80

"设置水平/和竖直突出显示
set cursorline

" 显示窗口比较小的时候折行展示,不然需要水平翻页,推荐
set linebreak

" 设置行号
set number
set relativenumber

"编码设置
set encoding=utf-8
set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1
set fileformats=unix,dos,mac
set termencoding=utf-8
set formatoptions+=m
set formatoptions+=

" 设置语言
set langmenu=zh_CN.UTF-8
set helplang=cn

" 设置回到vim再上次的位置
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif


" ===================================
" ============== 移动光标============
" ===================================
" J K 快速移动上下五行
noremap <silent> K 5k
noremap <silent> J 5j

"  快速到行首
noremap H 0
"  快速到行尾
noremap L $

" 快速的单词跳转
noremap W 5w
noremap B 5b

" 查找和替换
noremap \s :%s//g<left><left>

" 查找到的内容居中
nnoremap Y y$

" 插入模式下kj返回normal模式
inoremap jk <Esc>

"===============================
"=========== coc.nvim ==========
"===============================
" coc-marketplace/coc-go/coc-rust/coc-explorer
" coc-sh/coc-xml/coc-json/coc-yaml/coc-yank/coc-pyright
" coc-pairs/coc-lists/coc-lua/coc-clangd
" coc-cmake/coc-snippets

" TAB 补全
inoremap <silent><expr> <TAB>
      \ pumvisible() ? "\<C-n>" :
      \ <SID>check_back_space() ? "\<TAB>" :
      \ coc#refresh()
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"

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

" ENTER 补全第一个
inoremap <silent><expr> <cr> pumvisible() ? coc#_select_confirm()
                              \: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"

" 错误诊断跳转
nmap <silent> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <Plug>(coc-diagnostic-next)

" 代码跳转
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)

" <C-u> 删除之前的文本
" 调用CocList
noremap <silent><nowait> <leader>ll :<C-u>CocList<CR>
noremap <silent><nowait> <leader>ld :<C-u>CocList diagnostics<CR>
noremap <silent><nowait> <leader>le :<C-u>CocList extensions<CR>
noremap <silent><nowait> <leader>lc :<C-u>CocList commands<CR>
noremap <silent><nowait> <leader>lo :<C-u>CocList outline<CR>
noremap <silent><nowait> <leader>ls :<C-u>CocList -I symbols<CR>
noremap <silent><nowait> <leader>lp :<C-u>CocListResume<CR>
noremap <silent><nowait> <leader>lm :<C-u>CocList marketplace<CR>
noremap <silent><nowait> <leader>ln :<C-u>CocList snippets<CR>

" yank: coc-yank
noremap <silent><nowait> <leader>ly  :<C-u>CocList -A --normal yank<cr>

" buffers
noremap <silent><nowait> <leader>bb :<C-u>CocList buffers<CR>
noremap <silent><nowait> <leader>bn :<C-u>bn<CR>
noremap <silent><nowait> <leader>bp :<C-u>bp<CR>
noremap <silent><nowait> <leader>bd :<C-u>bd<CR>
noremap <silent><nowait> <leader>bd :<C-u>bd<CR>

" theme
noremap <silent><nowait> <leader>tt :<C-u>CocList colors<CR>

" files
noremap <silent><nowait> <leader>ff :<C-u>CocList files<CR>
noremap <silent><nowait> <leader>ft :<C-u>CocCommand explorer<CR>
noremap <silent><nowait> <leader>fs :<C-u>w<CR>
noremap <silent><nowait> <leader>fg :<C-u>TagbarToggle<CR>
noremap <silent><nowait> <leader>fr :<C-u>Ranger<CR>
noremap <silent><nowait> <leader>fd :<C-u>x<CR>

" git
noremap <silent><nowait> <leader>gg :<C-u>Gstatus<CR>
noremap <silent><nowait> <leader>gf :<C-u>Git fetch<CR>
noremap <silent><nowait> <leader>gs :<C-u>Git stash<CR>
noremap <silent><nowait> <leader>gb :<C-u>Git blame<CR>
noremap <silent><nowait> <leader>gs :<C-u>Git status<CR>
noremap <silent><nowait> <leader>gl :<C-u>Git log<CR>
noremap <silent><nowait> <leader>gi :<C-u>Git init<CR>
noremap <silent><nowait> <leader>gv :<C-u>GV<CR>

"" help
noremap <silent><nowait> <leader>hh :<C-u>CocList helptags<CR>
noremap <silent><nowait> <leader>hk :<C-u>CocList maps<CR>

"" windows
noremap <silent><nowait> <leader>ww :<C-u>CocList windows<CR>
noremap <silent><nowait> <leader>ws :<C-u>split<CR>
noremap <silent><nowait> <leader>wv :<C-u>vsplit<CR>
noremap <silent><nowait> <leader>wd :<C-u>q<CR>
noremap <silent><nowait> <leader>w1 :<C-u>only<CR>
noremap <silent><nowait> <leader>wo <C-w>w<CR>
noremap <silent><nowait> <leader>wh <C-w>h<CR>
noremap <silent><nowait> <leader>wj <C-w>j<CR>
noremap <silent><nowait> <leader>wk <C-w>k<CR>
noremap <silent><nowait> <leader>wl <C-w>l<CR>
noremap <silent><nowait> <leader>w= <C-w>=<CR>
noremap <silent><nowait> <leader>w<up>:<C-u>res +5<CR>
noremap <silent><nowait> <leader>w<down> :<C-u>res -5<CR>
noremap <silent><nowait> <leader>w<left> :<C-u>vertical resize -5<CR>
noremap <silent><nowait> <leader>w<right> :<C-u>veritcal resize +5<CR>

" search
noremap <silent><nowait> <leader>ss :<C-u>CocList words<CR>
noremap <silent><nowait> <leader>sa :<C-u>CocList grep<CR>
noremap <silent><nowait> <leader>sn :<C-u><nohlsearch<CR>

" isearch
map /  <Plug>(incsearch-forward)
map ?  <Plug>(incsearch-backward)
map g/ <Plug>(incsearch-stay)

map n  <Plug>(incsearch-nohl-n)
map N  <Plug>(incsearch-nohl-N)
map *  <Plug>(incsearch-nohl-*)
map #  <Plug>(incsearch-nohl-#)
map g* <Plug>(incsearch-nohl-g*)
map g# <Plug>(incsearch-nohl-g#)

" misc rename: 重命名
nnoremap <silent><nowait> <leader>rn <Plug>(coc-rename)
nnoremap <silent><nowait> <leader>ut :UndotreeToggle<CR>

""""go"""""
" go tags
autocmd FileType go noremap mta :<C-u>GoAddTags json<CR>
autocmd FileType go noremap mty :<C-u>GoAddTags yaml<CR>
autocmd FileType go noremap mtx :<C-u>GoAddTags xml<CR>
autocmd FileType go noremap mtd :<C-u>GoRemoveTags<CR>

" run & build
autocmd FileType go noremap mxx :<C-u>GoRun .<CR>
autocmd FileType go noremap mxb :<C-u>GoBuild .<CR>

" go debug
autocmd FileType go noremap mdd :<C-u>GoDebugBreakpoint<CR>
autocmd FileType go noremap mds :<C-u>GoDebugStart<CR>
autocmd FileType go noremap mdc :<C-u>GoDebugContinue<CR>
autocmd FileType go noremap mdk :<C-u>GoDebugStop<CR>

" check
autocmd FileType go noremap mee :<C-u>GoMetaLinter<CR>
autocmd FileType go noremap mev :<C-u>GoVet<CR>
autocmd FileType go noremap mel :<C-u>GoLint<CR>
autocmd FileType go noremap mec :<C-u>GoErrCheck<CR>

" impl
autocmd FileType go noremap mii :<C-u>GoImpl<CR>
autocmd FileType go noremap mim :<C-u>GoImplements<CR>
autocmd FileType go noremap mir :<C-u>GoReferres<CR>



"================================
"===========coc-pairs============
"================================
autocmd FileType tex let b:coc_pairs = [["$", "$"]]


"================================
"==========vim.go & coc-go=======
"================================
let g:go_fmt_command = "goimports"
let g:go_fmt_autosave = 1

"================================
"===========rainbow==============
"================================
let g:rainbow_active = 1


"================================
"============theme=============
"================================
colorscheme gruvbox
set background=dark


"===============================
"========vim-commentary=========
"===============================
"为python和shell等添加注释
autocmd FileType python,shell set commentstring=#\ %s
"修改注释风格
autocmd FileType c,cpp,go,rust set commentstring=//\ %s


"==============================
"========incsearch.vim=========
"==============================
let g:incsearch#auto_nohlsearch = 1

"=============================
"========asyncrun.vim=========
"=============================
let g:asyncrun_open = 8

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.