1995parham / elievim

neovim configuration based on cosyvim 🙈🎈💌
MIT License
8 stars 0 forks source link
lua neovim nvim vim

The Way of Life

Your editor, your rules

Elahe
GitHub Workflow Status GitHub

Introduction

Neovim is a modern and powerful text editor that is fully compatible with Vim and supports Lua plugins, LSP client, and remote plugins. It is a project that seeks to aggressively refactor Vim in order to simplify maintenance, enable advanced UIs, and maximize extensibility. You can learn more about Neovim from its official website, its GitHub repository, or its releases page.

Structure

├── init.lua
├── 📂 lua
│   ├── 📂 core                    heart of elievim which provides api
│   │   ├── init.lua
│   │   ├── keymap.lua             keymap api
│   │   └── options.lua            vim options
│   │
│   ├── 📂 keymap
│   │   ├── config.lua
│   │   └── init.lua
│   │   └── plugins.lua
│   │
│   ├── 📂 commands
│   │   │
│   │   ├── init.lua
│   │   └── go.lua
│   │   └── ansible.lua
│   │
│   └── 📂 modules
│       │
│       ├── 📂 completion
│       │   ├── config.lua
│       │   └── plugins.lua
│       ├── 📂 lang
│       │   ├── config.lua
│       │   └── plugins.lua
│       ├── 📂 tools
│       │   ├── config.lua
│       │   └── plugins.lua
│       └── 📂 ui
│           ├── config.lua
│           └── plugins.lua
└── 📂 snippets                   snippets
    ├── lua.json
    └── package.json

Nomenclature

Ellie is a pet form of Elahe coming from Elahe Dastan.

How to Install?

You need to remove your old configuration and then install elievim using:

rm -Rf ~/.config/nvim
rm -Rf ~/.local/share/nvim
rm -Rf ~/.cache/nvim

git clone https://github.com/1995parham/elievim

How to register plugins?

When you have a new module in the modules folder, you can register plugins as follows in the plugins.lua:

local conf = require('modules.ui.config')

return {
    {'1995parham/naz.vim', config = conf.naz},
    {'plugin github repo name'},
}

What is config?

This is a keyword of lazy.nvim, and you need to check its document. If a plugin has many configs you can create other file in modules/your-folder-name/config.lua and avoid making the plugins.lua file too long.

return {
    -- modules/completion/plugins.lua
    {
      'neovim/nvim-lspconfig',
      -- used filetype to lazy load lsp
      -- config your language filetype in here
      ft = { 'lua','rust','c','cpp'},
      config = conf.nvim_lsp,
    },

    -- modules/tools/plugins.lua
    {
      'nvim-telescope/telescope.nvim',
      -- use command to lazy load.
      cmd = 'Telescope',
      config = conf.telescope,
      dependencies = {
        { 'nvim-lua/popup.nvim' },
        { 'nvim-lua/plenary.nvim' },
        { 'nvim-telescope/telescope-fzy-native.nvim' },
      }
    },
}

How to config key mapping?

In elievim there are some APIs that make it easy to set key mapping. All APIs are defined in core/keymap.lua.

-- functions to generate keymap by vim.keymap.set
keymap.nmap()
keymap.imap()
keymap.cmap()
keymap.vmap()
keymap.xmap()
keymap.tmap()
-- generate opts into vim.keymap.set
keymap.new_opts()
-- function type that work with keymap.new_opts
keymap.silent()
keymap.noremap()
keymap.expr()
keymap.nowait()
keymap.remap()
-- just return string with <Cmd> and <CR>
keymap.cmd()
-- work like cmd but for visual map
keymap.cu()

Use these APIs to config your key mapping in keymap folder. In this folder keymap/init.lua is necessary but if you have many VIM modes' remap you can config them in keymap/other-file.lua Then config plugins key mapping in keymap/init.lua. The example of API usage is as follows:

-- genreate keymap in normal mode
nmap {
  -- packer which is replaced by lazy.nvim
  {'<Leader>pu',cmd('PackerUpdate'),opts(noremap,silent,'Packer update')},
  {'<Leader>pi',cmd('PackerInstall'),opts(noremap,silent)},
  {'<Leader>pc',cmd('PackerCompile'),opts(noremap,silent)},
}

map for each table, generate a new table that can pass to vim.keymap.set as follows:

cmd('PackerUpdate') just return a string <cmd>PackerUpdate<CR> as RHS. LHS is <leader>pu and opts(noremap, silent, 'Packer update') generate options table as follows:

{noremap = true,silent = true, desc = 'Packer Update' }

For some vim mode remap and Do not need use cmd function because you want to have another key mapping not a command as RHS.

-- window jump
{"<C-h>",'<C-w>h',opts(noremap)}

Also, you can pass a table not include sub table to map like

nmap {'key','rhs',opts(noremap,silent)}

Use :h vim.keymap.set to know more about.

LSP Tools Requirements

To utilize Language Servers, you'll typically need the following commands:

- luarocks
- npm / node
- pip / python

Configuration

Language servers are configured in lua/modules/completion/config.lua based on nvim-lspconfig.

['taplo'] = function()
  require('lspconfig').taplo.setup({})
end,

If you use this approach, make sure you don't also manually set up servers directly via lspconfig as this will cause servers to be set up more than once.

Tips

Improve key repeat

# macOS (needs a restart)
defaults write NSGlobalDomain KeyRepeat -int 1
defaults write NSGlobalDomain InitialKeyRepeat -int 10

# Linux (X11)
xset r rate 210 40

Links

Languages

This document outlines useful features of my development configuration specifically designed for Python and Go projects.

General

Golang