Install Neovim


Để cài NeoVim trên Arch Linux ta dùng lệnh sau.

sudo pacmain -S vim neovim nodejs npm python-pynvim

Cấu hình file vimrc của mình như sau.

syntax on
set number
set paste
set mouse=a
set relativenumber
set shiftwidth=2
set tabstop=2

call plug#begin('~/.vim/plugged')
Plug 'doums/darcula'
Plug 'mattn/emmet-vim'
"Plug 'tpope/vim-surround'coc-tsserver
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'tpope/vim-commentary'
Plug 'pangloss/vim-javascript'
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'

Plug 'voldikss/vim-floaterm'
Plug 'preservim/nerdtree'
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
" hightlight close tag
Plug 'gregsexton/matchtag'

" Change close tag
Plug 'andrewradev/tagalong.vim'
" auto close tag 
Plug 'tpope/vim-ragtag'

call plug#end()


command! -nargs=0 Prettier :CocCommand prettier.formatFile
"autocmd BufNewFile,BufRead *.php set syntax=html
"autocmd BufNewFile,BufRead *.php set filetype=html
"

" close all buffer except current and previous
nnoremap <leader>ca :w <bar> %bd <bar> e# <bar> bd# <CR>

noremap <leader>0 :tablast<cr>


" next tab
noremap <leader>w gt
" previous tab
noremap <leader>q gT

" Go to last active tab

au TabLeave coc-tsserver* let g:lasttab = tabpagenr()
nnoremap <silent> <c-l> :exe "tabn ".g:lasttab<cr>
vnoremap <silent> <c-l> :exe "tabn ".g:lasttab<cr>
" let g:netrw_keepdir=0


" copy from cursor to end
noremap Y y$

" move line up /down


vnoremap J :m '>+1<CR>gv=gv
vnoremap K :m '<-2<CR>gv=gv
inoremap <C-j> <esc>:m .+1<CR>==
inoremap <C-k> <esc>:m .-2<CR>==

nnoremap <leader>j :m .+1<CR>==
nnoremap <leader>k :m .-2<CR>==

let g:fzf_layout = {'window': {'width':0.8, 'height':0.8}}
let $FZF_DEFAULT_OPTS='--reverse'
nnoremap <silent> <C-p> :Files<CR>
nnoremap <silent> <Leader>f :Ag<CR>
nnoremap <silent> <Leader>b :Buffers<CR>

" floaterm
" new
let g:floaterm_keymap_new = '<Leader>ft'
" toggle
let g:floaterm_keymap_toggle = '<Leader>t'
" NERDTree
nnoremap <F1> :NERDTree<CR>
nnoremap <F2> :NERDTreeToggle<CR>
" faster
let g:airline#extensions#tagbar#enabled = 0

" php beautifull code
map <leader>h :set ft=html<CR>
map <leader>p :set ft=php<CR>

autocmd Filetype rmd map <F5> :!echo<space>"require('rmarkdown');<space>render('<c-r>%')"<space>\|<space>R<space>--vanilla<enter>
colorscheme darcula

hi Normal guibg=NONE  ctermbg=NONE

highlight LineNr ctermfg=gray ctermbg=NONE
set tags=tags

Ta copy file .vimrc và paste vào init.vim.

cp ~/.vimrc ~/.config/nvim/init.vim

Cài đặt vim plug.

curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
    https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim

cp -r ~/.vim/autoload ~/.local/share/nvim/site/autoload/

Trong file init.vim đổi dòng

call plug#begin('~/.vim/plugged')

Thành.

call plug#begin('~/.local/share/nvim/site/autoload')

Save và gõ

:PlugInstall

Cài thêm coc.

:CocInstall coc-css coc-html coc-phpls coc-tsserver coc-pyright

Như vậy là ta đã setup xong neovim rồi đó. Enjoy ^_^