Why vim and neovim?
Vim is a highly configurable text editor built to make creating and changing any kind of text very efficient. It is included as "vi" with most UNIX systems and with Apple OS X.
vim is highly customizable and it is the default fallback editor in most Linux systems. If you are the server admin, then vim can be a great tool for you. If you are a programmer, it already supports 100s of programming languages.
Recently I have switched from vim to neovim and neovim is fully compatible with Vim's editing model and Vimscript.
How to install neovim?
If you want to use vim, it is already available in most Linux OS. you can follow vim.org to download and install it.
We are going to use Lunarvim for our neovim IDE. It has lots of great features which you can find on the official website.
You can follow the Installation section to install Lunarvim and also all the prerequisites.
Install latest neovim
# linux
sudo snap install neovim --classic
# Mac
brew install neovim
In this post, we are going to set up Lunar vim for Ruby on Rails development, but feel free to check Lunarvim Plugins section to install plugins as your need.
Theme
I really like dracula
theme and I use it in almost all of my tools: You can get dracula for your choice of editor, terminal or even HD wallpapers from here.
lvim.colorscheme = "dracula"
Configuration file
Open ~/.config/lvim/config.lua
file and keep the default configuration and replace the following sections in the file
change the treesitter list of your choice
-- if you don't want all the parsers change this to a table of the ones you want
lvim.builtin.treesitter.ensure_installed = {
"bash",
"c",
"javascript",
"json",
"lua",
"python",
"typescript",
"tsx",
"css",
"rust",
"ruby",
"java",
"yaml",
}
Additional plugins in lvim.plugins
section
lvim.plugins = {
{
"folke/trouble.nvim",
cmd = "TroubleToggle",
},
{ 'Mofiqul/dracula.nvim' }, -- theme
{ 'tpope/vim-rails' }, -- ruby on rails
{ 'kdheepak/lazygit.nvim' }, -- lazy git
{
"max397574/better-escape.nvim",
config = function()
require("better_escape").setup {
mapping = { "jj" }, -- a table with mappings to use
timeout = 200, -- the time in which the keys must be hit in ms. clear_empty_lines = false, keys = '<ESC>', -- keys used for escaping
}
end
},
{ "preservim/vimux" }, -- send test command in tmux pane
{ "vim-test/vim-test" }, -- run test
{ "tpope/vim-abolish" }, -- search and replace preserving state
}
Mofiqul/dracula.nvim
: for dracula themetpope/vim-rails
: Ruby on rails power tool (recommended)kdheepak/lazygit.nvim
: If you are lazygit user, you will love this integration within your neovimmax397574/better-escape.nvim
: it allows you to remap e.g:jj
as ESC keypreservim/vimux
: If you love tmux, vim + tmux is great. This allows you to send command in separate tmux pane from your vimvim-test/vim-test
: powerful when combined withvimux
or evenneovim
tpope/vim-abolish
: I recently found this tool, it helps you find and replace(or substitute) multiple occurances of the word preserving their case.
Add the below configurations at the end of the file
-- VIM configurations (my custom configurations)
-- relative line number
vim.o.relativenumber = true
-- using neovim strategy, so that pressing anykey will not close test result window
vim.g['test#neovim#start_normal'] = 1
-- autoclose tag
-- enable plugin for file extensions
vim.g['closetag_filenames'] = '*.html,*.erb'
-- vim-test strategy
vim.g['test#strategy'] = 'vimux'
-- vim-test keybindings
vim.cmd("let test#strategy = 'vimux'")
vim.keymap.set('n', '<space>tt', '<cmd>TestNearest<CR>', { desc = "Test nearest" })
vim.keymap.set('n', '<space>tl', '<cmd>TestLast<CR>', { desc = "Test last" })
vim.keymap.set('n', '<space>tf', '<cmd>TestFile<CR>', { desc = "Test file" })
vim.keymap.set('n', '<Leader>ts', '<cmd>TestSuite<CR>', {desc = "Test suite" })
Some of the plugins worth mentioning
vim-test: Quickly test your rails project within neovim
vim-rails: This is a feature-rich plugin for rails
Easily navigate between pages
:help rails-navigation
Easily generate the missing file by appending
!
Interface to the
rails
command, e.g::Rails console
,:Rails db:migrate
,:Rails g controller example
, etcPartial extraction
:help rails-:Extract
Integrate with other plugins
:help rails-integration
vim-closetag: auto close html and erb tags
lazygit: One of my favourite terminal UI for git commands. This is so powerful, just try it.
My config files
If you like my neovim config, you can use it from https://github.com/przbadu/lvim_config