Установите Neovim
- Использование заварки
brew install neovim
- Использование curl
curl -LO https://github.com/neovim/neovim/releases/download/nightly/nvim-macos.tar.gz tar xzf nvim-macos.tar.gz ./nvim-osx64/bin/nvim
Конфигурация
- Создайте файлы конфигурации
~/.config/neovim/init.lua
- init.lua
require('options');
require('config');
require('plugins');
- options.lua
-------------------- HELPERS ------------------------------
local scopes = {o = vim.o, b = vim.bo, w = vim.wo}
local function opt(scope, key, value)
scopes[scope][key] = value
if scope ~= 'o' then scopes['o'][key] = value end
end
-------------------- OPTIONS -------------------------------
local indent = 4
opt('b', 'expandtab', true) -- Use spaces instead of tabs
opt('b', 'shiftwidth', indent) -- Size of an indent
opt('b', 'smartindent', true) -- Insert indents automatically
opt('b', 'tabstop', indent) -- Number of spaces tabs count for
opt('o', 'completeopt', 'menuone,noinsert,noselect') -- Completion options (for deoplete)
opt('o', 'hidden', true) -- Enable modified buffers in background
opt('o', 'ignorecase', true) -- Ignore case
opt('o', 'joinspaces', false) -- No double spaces with join after a dot
opt('o', 'scrolloff', 4 ) -- Lines of context
opt('o', 'shiftround', true) -- Round indent
opt('o', 'sidescrolloff', 8 ) -- Columns of context
opt('o', 'smartcase', true) -- Don't ignore case with capitals
opt('o', 'splitbelow', true) -- Put new windows below current
opt('o', 'splitright', true) -- Put new windows right of current
opt('o', 'termguicolors', true) -- True color support
opt('o', 'wildmode', 'list:longest') -- Command-line completion mode
opt('w', 'list', true) -- Show some invisible characters (tabs...)
opt('w', 'number', true) -- Print line number
opt('w', 'relativenumber', false) -- Relative line numbers
opt('w', 'wrap', false) -- Disable line wrap
opt('o', 'swapfile', false) -- Disable swapfile
opt('o', 'history', 1000)
opt('o', 'autoread', true)
opt('o', 'backup', false)
opt('o', 'writebackup', false)
opt('w', 'cursorline', true)
opt('o', 'pumheight', 10)
opt('o', 'fileencoding', 'utf-8')
opt('o', 'cmdheight', 2)
opt('o', 'mouse', 'a')
opt('o', 'updatetime', 50)
--opt('o', 'timeoutlen', 100)
opt('o', 'clipboard', 'unnamedplus')
opt('o', 'wildmenu', true)
opt('o', 'wildmode', 'full')
opt('o', 'lazyredraw', true)
opt('o', 'signcolumn', 'yes:1')
opt('o', 'background', 'dark')
opt('o', 'synmaxcol', 200) -- syntax file is slow,
----------------------- DISABLE BUILT-IN PLUGINS -------------------------
local disabled_built_ins = {
"netrw",
"netrwPlugin",
"netrwSettings",
"netrwFileHandlers",
"gzip",
"zip",
"zipPlugin",
"tar",
"tarPlugin",
"getscript",
"getscriptPlugin",
"vimball",
"vimballPlugin",
"2html_plugin",
"logipat",
"rrhelper",
"spellfile_plugin",
"matchit"
}
for _, plugin in pairs(disabled_built_ins) do
vim.g["loaded_" .. plugin] = 1
end
- config.lua
-------------------- HELPERS ------------------------------
local cmd = vim.cmd -- to execute Vim commands e.g. cmd('pwd')
local g = vim.g -- a table to access global variables
local function map(mode, lhs, rhs, opts)
local options = {noremap = true}
if opts then options = vim.tbl_extend('force', options, opts) end
vim.api.nvim_set_keymap(mode, lhs, rhs, options)
end
-------------------- CONFIG -------------------------------
g['mapleader'] = ' ' -- leader key
-- let g:node_host_prog = '/usr/local/bin/neovim-node-host'
g['node_host_prog'] = vim.call('system', 'volta which neovim-node-host | tr -d "n"')
g.coq_settings = {
auto_start = 'shut-up',
}
g['gitblame_date_format'] = '%r' -- relative date
g['gitblame_enabled'] = 0 -- default disabled
-- g['startify_disable_at_vimenter'] = 1
g['startify_lists'] = {{type = 'bookmarks', header = {'Bookmarks'}}}
g['startify_bookmarks'] = {
{ i = '~/.config/nvim/init.lua' },
{ p = '~/.config/nvim/lua/plugins.lua' },
{ c = '~/.config/nvim/lua/config.lua' },
{ o = '~/.config/nvim/lua/options.lua' },
{ z = '~/.zshrc' },
{ g = '~/.gitconfig' },
{ t = '~/.tmux.conf'},
}
-- register
g['peekup_paste_before'] = '<leader>P'
g['peekup_paste_after'] = '<leader>p'
cmd [[au TextYankPost * silent! lua vim.highlight.on_yank {on_visual=false, timeout=200}]]
-- Remove trailing space
cmd [[autocmd InsertLeavePre * :%s/s+$//e]]
-------------------- MAPPINGS -------------------------------
map('n', '<Space>sv', ':source $MYVIMRC<CR>')
map('n', '<Space>', '<Nop>', { noremap = true, silent = true })
-- <Tab> to navigate the completion menu
map('i', '<S-Tab>', 'pumvisible() ? "\<C-p>" : "\<Tab>"', {expr = true})
map('i', '<Tab>', 'pumvisible() ? "\<C-n>" : "\<Tab>"', {expr = true})
map('n', '\', '<cmd>noh<CR>') -- Clear highlights
map('n', '<Leader>j', ':j<CR>')
map('n', '<Leader>J', ':j!<CR>')
map('n', '<Leader>w', ':w<CR>')
-- keep visual selection after indenting
map('v', '>', '>gv');
map('v', '<', '<gv');
-- copy file path
map('n', '<Leader>cp', ':let @*=expand("%")<CR>')
-- Telescope
map('n', '<Leader>fl', '<cmd>Telescope current_buffer_fuzzy_find theme=get_ivy layout_config={height=0.5}<CR>')
map('n', '<Leader>ff', '<cmd>Telescope find_files theme=get_ivy layout_config={height=0.5}<CR>')
map('n', '<Leader>fg', '<cmd>Telescope live_grep theme=get_ivy layout_config={height=0.5}<CR>')
map('n', '<Leader>fb', '<cmd>Telescope buffers theme=get_ivy layout_config={height=0.5}<CR>')
map('n', '<Leader>fh', '<cmd>Telescope help_tags theme=get_ivy layout_config={height=0.5}<CR>')
map('n', '<Leader>fv', '<cmd>Telescope git_files theme=get_ivy layout_config={height=0.5}<CR>')
map('n', '<Leader>fp', '<cmd>Telescope planets theme=get_ivy layout_config={height=0.5}<CR>')
map('n', '<Leader>fk', '<cmd>Telescope keymaps theme=get_ivy layout_config={height=0.5}<CR>')
map('n', '<S-u>', '<C-u>')
map('n', '<S-d>', '<C-d>')
map('n', 'qo', ':only<CR>')
map('', '<C-S-Left>', ':vertical resize -5<CR>')
map('', '<C-S-Right>', ':vertical resize +5<CR>')
map('', '<C-S-Up>', ':resize +5<CR>')
map('', '<C-S-Down>', ':resize -5<CR>')
map('n', '<Leader>e', ':NvimTreeFindFileToggle<CR>')
-- switch window using hjkl
map('n', '<S-h>', '<C-w>h')
map('n', '<S-j>', '<C-w>j')
map('n', '<S-k>', '<C-w>k')
map('n', '<S-l>', '<C-w>l')
-- move selection using jk
map('v', '<S-j>', ':m'>+<CR>gv=gv')
map('v', '<S-k>', ':m-2<CR>gv=gv')
-- disable recording macros
map('n', 'q', '<Nop>')
map('n', 'Q', '<Nop>')
map('n', 'qq', ':q<CR>')
map('n', 'QQ', ':q!<CR>')
-- hop
map('n', '<Leader>hc', ':HopChar1<cr>')
map('n', '<Leader>hw', ':HopWord<cr>')
map('n', '<Leader>hl', ':HopLine<cr>')
map('n', '<Leader>hp', ':HopPattern<cr>')
-- lsp config
map('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>')
map('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>')
map('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>')
map('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>')
map('n', 'ca', '<cmd>lua vim.lsp.buf.code_action()<CR>')
map('n', 'rn', '<cmd>lua vim.lsp.buf.rename()<CR>')
map('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>')
map('n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>')
-- startify
map('n', '<Leader>S', ':Startify<CR>')
-- search and replace
map('n', '<Leader>sr', '<cmd>lua require("spectre").open()<CR>')
map('n', '<Leader>sw', '<cmd>lua require("spectre").open_visual({select_word=true})<CR>')
map('n', '<Leader>sp', '<cmd>lua require("spectre").open_file_search()<CR>')
map('n', '<Leader>gb', ':GitBlameToggle<CR>')
- plugins.lua
-------------------- HELPERS ------------------------------
local cmd = vim.cmd -- to execute Vim commands e.g. cmd('pwd')
local execute = vim.api.nvim_command
local fn = vim.fn
-------------------- PLUGINS ------------------------------
local install_path = fn.stdpath('data')..'/site/pack/packer/opt/packer.nvim'
if fn.empty(fn.glob(install_path)) > 0 then
execute('!git clone https://github.com/wbthomason/packer.nvim '..install_path)
execute 'packadd packer.nvim'
end
-- Only required if you have packer in your `opt` pack
cmd [[packadd packer.nvim]]
require('packer').startup(function()
-- Packer can manage itself as an optional plugin
use {'wbthomason/packer.nvim', opt = true}
use {
'nvim-treesitter/nvim-treesitter',
run = ':TSUpdate',
config = function()
require'nvim-treesitter.configs'.setup {
ensure_installed = 'all',
auto_install = true,
highlight = {
enable = true,
}
}
end
}
use {
'williamboman/nvim-lsp-installer',
'neovim/nvim-lspconfig',
config = function()
require('nvim-lsp-installer').setup {
automatic_installation = true
}
end,
}
local lsp_installer = require('nvim-lsp-installer')
local lspconfig = require('lspconfig')
lsp_installer.on_server_ready(function (server)
if server.name == 'tsserver' then
server:setup {root_dir = lspconfig.util.root_pattern('package.json')}
elseif server.name == 'denols' then
server:setup {root_dir = lspconfig.util.root_pattern('deno.json'), single_file_support = false}
else
server:setup {}
end
end)
-- improve default vim ui. e.g. code actions
use { 'stevearc/dressing.nvim' }
-- Auto completion
use {
'ms-jpq/coq_nvim',
branch = 'coq',
}
use { 'ms-jpq/coq.artifacts', branch = 'artifacts' }
use { 'ms-jpq/coq.thirdparty', branch = '3p' }
-- vim registers
use 'gennaro-tedesco/nvim-peekup'
-- search and replace
use {
'windwp/nvim-spectre',
requires = {
'nvim-lua/plenary.nvim'
},
config = function()
require('spectre').setup()
end
}
-- fuzzy finder
use {
'nvim-telescope/telescope.nvim',
tag = '0.1.0',
requires = {
'nvim-lua/popup.nvim',
'nvim-lua/plenary.nvim',
}
}
use {
'kyazdani42/nvim-tree.lua',
requires = {
'kyazdani42/nvim-web-devicons', -- optional, for file icons
},
config = function()
require('nvim-tree').setup()
end
}
use {
'lewis6991/gitsigns.nvim',
requires = {
'nvim-lua/plenary.nvim'
},
config = function()
require('gitsigns').setup()
end
}
use {
'f-person/git-blame.nvim',
}
-- terminal
use {
'numToStr/FTerm.nvim',
config = function()
local fterm = require('FTerm')
local lazygit = fterm:new({
cmd = 'lazygit',
})
local tig = fterm:new({
cmd = 'tig %',
})
vim.keymap.set('n', '<Leader>lg', function()
lazygit:toggle()
end)
vim.keymap.set('n', '<Leader>tg', function()
tig:toggle()
end)
end
}
-- Commenting
use {
'b3nj5m1n/kommentary',
config = function()
require('kommentary.config').use_extended_mappings()
end
}
-- easy motion
use {
'phaazon/hop.nvim',
branch='v1',
config = function()
require('hop').setup{keys = 'etovxqpdygfblzhckisuran'}
end
}
use 'kevinhwang91/nvim-hlslens'
use {
'kylechui/nvim-surround',
config = function()
require('nvim-surround').setup{}
end
}
-- quick fix fzf
use {
'kevinhwang91/nvim-bqf',
config = function()
require('bqf').setup({
auto_enable = true,
preview = {
win_height = 12,
win_vheight = 12,
delay_syntax = 80,
border_chars = {'┃', '┃', '━', '━', '┏', '┓', '┗', '┛', '█'}
},
func_map = {
vsplit = '',
ptogglemode = 'z,',
stoggleup = ''
},
filter = {
fzf = {
extra_opts = {'--bind', 'ctrl-o:toggle-all', '--prompt', '> '}
}
}
})
end
}
use {
'windwp/nvim-autopairs',
config = function()
require('nvim-autopairs').setup()
end
}
use {
'ellisonleao/gruvbox.nvim',
config = function()
require('gruvbox').setup({
contrast = 'hard',
})
vim.cmd[[colorscheme gruvbox]]
end
}
use {
'mhinz/vim-startify',
}
use 'dstein64/vim-startuptime' -- startup time
use 'markonm/traces.vim' -- search and replace
use {
'nvim-lualine/lualine.nvim',
requires = {'kyazdani42/nvim-web-devicons', opt = true},
config = function()
require('lualine').setup({
options = { theme = 'gruvbox' }
})
end
}
-- jk to escape
use {
'max397574/better-escape.nvim',
config = function()
require('better_escape').setup()
end
}
-- create missing directory on save
use {
'jghauser/mkdir.nvim',
}
end)
Установка / синхронизация
- Откройте neovim
- Установите пакеты
:PackerSync
. - Для установки языкового сервера просто откройте любой файл и запустите
:LspInstall
для установки соответствующего сервера