Configure neovim from Scratch
Table of contents
- How to install
- How to configure
- Creating some shortcuts
- Add pulgin-manger(packer)
- Transparent Background
- Add tree sitter
- Add harrpon
- Add undotree
- Conclusion
How to install
To install simply just type
sudo pacman -S neovim
Now make a directory in .config
mkdir ~/.config/nvim
then go to that directory and open nvim
cd ~/.config/nvim
nvim .
here this type of interface popup
How to configure
Now press :
and type
:h rtp
here you can see default $XDG_CONFIG_HOME/nvim
is our main directory where we put all our config files.
Now exit from that your interface should look like this
Now press % and give file name init.lua
To type something press i
(insert) or a
(append) type this
now exit from insert mode by pressing Esc
or ctrl + c
After to save this file press :
and type w
(write) or wq
(write and quiet)
Again go to nvim
nvim .
here you can notice that our file is created and bottom left you can see hello.
Now press d
to create directory and give name lua
Go to lua directory and create a whatever named directory
And go to that directory and create file init.lua
for testing type this in your file:
Again press :
to go explore mode Ex
and go to previous directory ../
where our first file created
open that file ~/.config/nvim/init.lua
and type this
now exit from nvim by pressing :wq
Again open nvim
pwd :- ~/.config/nvim
nvim .
A message like this will show when you open nvim
congrats if this type of message will shows so you go further and lets make nvim usable.
Creating some shortcuts
Now lets make some shortcuts first you have to create a remap.lua file in ~/.config/nvim/lua/soul/remap.lua
here vim.g.leader
is name where you can assign a keybutton
in second line you can see vim.keymap.set
is used for set keyboard shortcuts of vim command
here we can directly execute this command Ex
by spacebar pv
save this file :w
after press :so
hit Enter (it will complie the source) now you can press spacebar pv
here when you exit from nvim you have to complie again so to solve this problem we have to type this in our init.lua
pwd:- ~/.config/nvim/lua/soul/init.lua
Now you everytime you open your nvim it will compile automatically
Add pulgin-manger(packer)
Go to this repo packer.nvim
clone this repo in your ~/.config
git clone --depth 1 https://github.com/wbthomason/packer.nvim\
~/.local/share/nvim/site/pack/packer/start/packer.nvim
Now copy this from that repo
vim.cmd [[packadd packer.nvim]]
return require('packer').startup(function(use)
-- Packer can manage itself
use 'wbthomason/packer.nvim'
end)
paste it in ~/.config/nvim/lua/soul/packer.lua
now complie it :so
now can able to type this :PackerSync
it will look like this
if the option is not available you can restart your nvim and recomplie it .
congrats you come this far you have succesfully installed pulgin-manger.
Add Pulgin(fuzzy finder)
Now lets add some pulgin
go to repo telescope.nvim
copy this from that repo
use {
'nvim-telescope/telescope.nvim', tag = '0.1.8',
-- or , branch = '0.1.x',
requires = { {'nvim-lua/plenary.nvim'} }
}
paste in your packer.lua it should be look like this
Now press :w
, :so
and after that :PackerSync
it will start to install that pulgin
Now copy this line paste it in ~/.config/nvim/after/pulgin/telescope.lua here create respective directory
local builtin = require('telescope.builtin')
vim.keymap.set('n', '<leader>pf', builtin.find_files, {})
vim.keymap.set('n', 'C-p', builtin.git_files, {})
vim.keymap.set('n', '<leader>ps', function()
builtin.grep_string({ search = vim.fn.input("Grep > ")});
end)
Now press :w
:so
now you can use fuzzy finder press spacebar pf or ps
Add pulgin (Rosé Pine)
Now go to this repo Rosé Pine
copy this line paste it in ~/.config/nvim/lua/soul/packer.lua
use({ 'rose-pine/neovim', as = 'rose-pine' })
vim.cmd('colorscheme rose-pine')
Now you can change it colorschema :coloschema rose-pine-main
Transparent Background
here i want traspraent background
create a file colors.lua at ~/.config/nvim/after/pulgin/colors.lua
function ColorMyPencils(color)
color = color or "rose-pine"
vim.cmd.colorscheme(color)
vim.api.nvim_set_hl(0,"Normal",{bg = "none"})
vim.api.nvim_set_hl(0,"NormalFloat",{bg = "none"})
end
ColorMyPencils()
After transparenting background . it will look beautiful ><
.
Add tree sitter
Add this line in your packer.lua
use( 'nvim-treesitter/nvim-treesitter', { run = ':TSUpdate'})
Save the file :w
and comple it :so
and run Packer :PackerSync
copy this line and paste it in ~/.config/nvim/after/pulgin/tree-sitter.lua
require'nvim-treesitter.configs'.setup {
-- A list of parser names, or "all" (the listed parsers MUST always be installed)
ensure_installed = { "c", "lua", "vim", "vimdoc", "query", "markdown", "markdown_inline", "javascript", "rust", "typescript" },
-- Install parsers synchronously (only applied to `ensure_installed`)
sync_install = false,
-- Automatically install missing parsers when entering buffer
-- Recommendation: set to false if you don't have `tree-sitter` CLI installed locally
auto_install = true,
highlight = {
enable = true,
-- Setting this to true will run `:h syntax` and tree-sitter at the same time.
-- Set this to `true` if you depend on 'syntax' being enabled (like for indentation).
-- Using this option may slow down your editor, and you may see some duplicate highlights.
-- Instead of true it can also be a list of languages
additional_vim_regex_highlighting = false,
},
}
Save the file :w
and comple it :so
Add this line in your packer.lua
use( 'nvim-treesitter/playground')
Save the file :w
and comple it :so
and run packer PackerSync
you can able to run :TSPlaygroundToggle
Add harrpon
Add this line in you Packer
use( 'ThePrimeagen/harpoon')
same as above
Now create a file harpoon.lua at ~/.config/nvim/after/harpoon.lua paste this
local mark = require("harpoon.mark")
local ui = require("harpoon.ui")
vim.keymap.set("n", "<leader>a", mark.add_file)
vim.keymap.set("n", "<leader>as", ui.toggle_quick_menu)
vim.keymap.set("n", "<C-a>", function () ui.nav_file(1) end)
vim.keymap.set("n", "<C-s>", function () ui.nav_file(2) end)
vim.keymap.set("n", "<C-u>", function () ui.nav_file(3) end)
vim.keymap.set("n", "<C-i>", function () ui.nav_file(4) end)
and save it and complie it Now can switch one file to another very fast
Here How ?
when i press spacebar a
means to add file in nav now press spacebar pf
serach file you want to access and go to that file and
press spacebar a
now press spacebar as
now and see two file that you selected
now you can switch using Ctrl + a
and Ctrl + s
and thats very quick
or you can use spacebar as
to switch
Add undotree
add this line in your packer
use ('mbbill/undotree')
then save it and complie it
now create a file undotree.lua ~/.config/nvim/after/plugin/undotree.lua
vim.keymap.set('n', '<leader>u', vim.cmd.UndotreeToggle)
save this file and complie it
Conclusion
Hope this helps you to understand who things works I also want to add lsp but i still confuse how to configure so if i fully understand then i will update it.
I try my best to make things simple see you in another blog :)