2023-03-17其他00
请注意,本文编写于 350 天前,最后修改于 350 天前,其中某些信息可能已经过时。

Neovim

我的配置截图

image.png

从实战角度出发 真正教会你如何使用neovim进行开发

附上我的neovim配置 init.vim

https://gitee.com/mao-chaoying/mac_nvim

let mapleader = " "
syntax on
noremap L $
noremap H 0
noremap J 5j
noremap K 5k
noremap <LEADER><CR> :nohlsearch<CR>
map sl :set splitright<CR>:vsplit<CR>
map sj :set splitbelow<CR>:split<CR>
map sk :set nosplitbelow<CR>:split<CR>
map sh :set nosplitright<CR>:vsplit<CR>
map <LEADER>l <C-w>l
map <LEADER>k <C-w>k
map <LEADER>j <C-w>j
map <LEADER>h <C-w>h
map <up> :res +5<CR>
map <down> :res -5<CR>
map <left> :vertical resize-5<CR>
map <right> :vertical resize+5<CR>

map s <nop>
map S :w<CR>
map Q :q<CR>
map R :source $MYVIMRC<CR>

au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
set laststatus=2
set autochdir
set encoding=utf-8
let &t_ut=''
set expandtab
set tabstop=2
set shiftwidth=2
set softtabstop=2
set list
set listchars=tab:▸\ ,trail:set scrolloff=5
set tw=0
set indentexpr=
set backspace=indent,eol,start
set foldmethod=indent
set foldlevel=99
set nocompatible
filetype on
filetype indent on
filetype plugin on
filetype plugin indent on
set number
set relativenumber
set cursorline
set wrap
set showcmd
set wildmenu
set hlsearch
set incsearch
exec "nohlsearch"
set ignorecase
set smartcase
set clipboard=unnamedplus

silent !mkdir -p $HOME/.config/nvim/tmp/backup
set backupdir=$HOME/.config/nvim/tmp/backup,.
set directory=$HOME/.config/nvim/tmp/backup,.

" 设置buffer切换
map <LEADER>n :bp<CR>
map <LEADER>m :bn<CR>
map <LEADER>d :bdelete<CR>

" Indentation
nnoremap < <<
nnoremap > >>

call plug#begin('~/.config/nvim/autoload')
Plug 'vim-airline/vim-airline'
Plug 'sainnhe/everforest'
Plug 'easymotion/vim-easymotion'
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'tomtom/tcomment_vim' " type <space>cn to comment a line, type <space>cu to uncomment a line
Plug 'jiangmiao/auto-pairs'
Plug 'alvan/vim-closetag'
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
Plug 'voldikss/vim-floaterm'
Plug 'windwp/nvim-autopairs'
Plug 'prabirshrestha/vim-lsp'
Plug 'mattn/vim-lsp-settings'
Plug 'thomasfaingnaert/vim-lsp-snippets'
Plug 'thomasfaingnaert/vim-lsp-ultisnips'
Plug 'honza/vim-snippets'
Plug 'iamcco/markdown-preview.nvim', { 'do': 'cd app && yarn install' }
Plug 'ellisonleao/gruvbox.nvim'

Plug 'neovim/nvim-lspconfig'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/cmp-path'
Plug 'hrsh7th/cmp-cmdline'
Plug 'hrsh7th/nvim-cmp'

Plug 'gelguy/wilder.nvim'

call plug#end()

" wildmenu
call wilder#setup({'modes': [':', '/', '?']})
" gruvbox
" set background=dark " or light if you want light mode
" colorscheme gruvbox


" everforest
set background=dark
let g:everforest_background = 'hard'
let g:airline_theme = 'everforest'
let g:everforest_better_performance = 1
colorscheme everforest

" tcomment_vim
let g:tcomment_textobject_inlinecomment = ''
nmap <LEADER>cn g>c
vmap <LEADER>cn g>
nmap <LEADER>cu g<c
vmap <LEADER>cu g<

" airline
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#formatter = 'unique_tail'

" easy-motion
map <LEADER>w <Plug>(easymotion-bd-w)

" coc.nvim
" 配置tab切换提示
inoremap <silent><expr> <TAB>
      \ coc#pum#visible() ? coc#pum#next(1) :
      \ CheckBackspace() ? "\<Tab>" :
      \ coc#refresh()
inoremap <expr><S-TAB> coc#pum#visible() ? coc#pum#prev(1) : "\<C-h>"
" 配置回车选中
inoremap <silent><expr> <CR> coc#pum#visible() ? coc#pum#confirm()
                              \: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"

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

" GoTo code navigation
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gr <Plug>(coc-references)

" Use LEADER h to show documentation in preview window
nnoremap <silent> <LEADER>h :call ShowDocumentation()<CR>

function! ShowDocumentation()
  if CocAction('hasProvider', 'hover')
    call CocActionAsync('doHover')
  else
    call feedkeys('K', 'in')
  endif
endfunction

" 配置coc list
let g:coc_global_extensions = ['coc-json', 'coc-css', 'coc-cssmodules', 'coc-dot-complete', 'coc-docker', 'coc-explorer', 'coc-html', 'coc-html-css-support', 'coc-prettier', 'coc-rome', 'coc-snippets', 'coc-sql', 'coc-vetur', 'coc-vimlsp', 'coc-tsserver', 'coc-yank']

" 开启coc的目录树
nmap mm :CocCommand explorer --quit-on-open<CR>

" fzf
let g:fzf_preview_window = 'right:40%'
let g:fzf_commits_log_options = '--graph --color=always --format="%C(auto)%h%d %s %C(black)%C(bold)%cr"'
noremap <silent> <LEADER>h :History<CR>
noremap <silent> <LEADER>f :FZF<CR>

" floaterm
noremap <LEADER>q :FloatermToggle<CR> 

" coc-yank
nnoremap <silent> <space>p  :<C-u>CocList -A --normal yank<cr>

" markdown preview
noremap <silent> <c-p> :MarkdownPreviewToggle<CR>

我相信,我配置的快捷键,绝对是你开发前端最舒服的快捷键。

想学习neovim的,或者有想知道的,留言评论,我会给大家出相应的详细教程。

本文作者:前端小毛

本文链接:

版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!