Back to Blog

Learn Lua in Neovim: Hello World with print() & :!lua % | Episode 1

Sandy LaneSandy Lane

Video: Learn Lua in Neovim: Hello World with print() & :!lua % | Episode 1 by Taught by Celeste AI - AI Coding Coach

Watch full page →

Learn Lua in Neovim: Hello World with print() & :!lua % | Episode 1

This tutorial introduces you to writing and running Lua code directly inside Neovim. You'll create a Lua file, use the print() function to display text, and run your script using the Neovim command :!lua %, which executes the current file.

Code

-- hello.lua
-- Print a greeting message to the console
print("Hello, world!")

-- Add another line to print a friendly message
print("Welcome to Lua programming in Neovim!")

Key Points

  • Create a Lua file with a .lua extension inside Neovim using commands like :e hello.lua.
  • Use print() with double-quoted strings to output text to the terminal.
  • Run the current Lua file in Neovim by typing :!lua %, which executes the script externally.
  • Use o in normal mode to open a new line below the current line and start inserting text.
  • Save your file anytime with :w before running it to ensure changes are executed.