Vim
Vim is a highly configurable, text-based editor that has been around for decades. It was designed to be extremely efficient and powerful, with a steep learning curve that can be intimidating for some users. However, once mastered, Vim can be incredibly productive, allowing users to edit text quickly and efficiently with a variety of advanced features and customization options. It is known for its modal editing system, which allows users to switch between different modes to perform different tasks, such as inserting text, navigating the document, or executing commands. NeoVim is a modern fork of Vim that aims to provide improved performance, better support for plugins and scripting languages, and a more modular architecture.
NeoVim
NeoVim is a text editor based on Vim, but with improved performance, a more modular architecture, and better support for plugins and scripting languages. It is available for Linux, as well as macOS and Windows.
you need to have this file in this structure:
neovimPLugin
└── lua
└── luaPlugin
└── init.lua
Here is an example of the file structure for a Neovim
plugin, where 'neovimPLugin'
is the name of your plugin, 'lua'
is the directory for Lua files, and 'luaPlugin'
is the directory for your plugin's Lua files. The 'init.lua'
file is the main file for your plugin, where you can write all of your desired plugin's codes.
mkdir neovimPLugin/lua/luaPlugin
cd $_
touch init.lua
# or use nvim
nvim init.lua
===========================================================
neovimPLugin ==> you can call this whatever name you like.
└── lua
└── luaPlugin
└── init.lua ==> the actual file.
2 directories, 1 file
===========================================================
-------- init.lua -----------
# This will have all your desire plugin's codes.
print('Hello World from lua plugin!')
-----------------------------
Add the file you create to your path. We are going to use a command for that.
# Run neovim with this option [rtp = Run top path]
nvim --cmd "set rtp+=./"
# Test the previous steps
# Open neovim an activate command mode using the :
:lua require"luaPlugin"
# this will result in printing you message to the secreen
Hello World from lua plugin!
Add a function to your plugin
To add a function to your Neovim
plugin, you can follow these steps:
- Open the
init.lua
file in your plugin's directory. - Write your desired function in the file.
- Return the function object as a value from the
init.lua
file. - Update the
rtp
path inNeovim
to include your plugin's directory. - Test your function by calling it in
Neovim
with therequire
function.
Here is an example of how to add a function to your Neovim
plugin:
-- This will have all your desired plugin's codes.
print('Hello World from lua plugin!')
-- Here is where the function starts
local function some_function()
print("Hello from a function")
end
-- This is what the plugin returns
return {
some_function = some_function
}
After saving the init.lua
file, you need to update the rtp
path in Neovim
to include your plugin's directory. You can do this by running the following command in your terminal:
nvim --cmd "set rtp+=./"
Then, you can test your function by calling it in Neovim
with the require
function:
:lua require"luaPlugin".some_function()
This should result in printing the message "Hello World from lua plugin!" followed by "Hello from a function" on the screen.