Skip to main content

2 posts tagged with "neovim"

View All Tags

Typing Simulation in Neovim with typeit.nvim

· 4 min read

Photo by Andrew
Seaman
on
Unsplash

Neovim plugin useful for technical presentations from a terminal

Introduction

As a developer who frequently gives technical presentations and demos from the terminal, I’ve always been drawn to Neovim’s extensibility. It’s a powerful feature, especially for those of us creating tutorials, demos, or presentations. That’s why I created typeit.nvim.

Over the years, I’ve found that live coding during presentations can be risky — typos, mistakes, and the pressure of an audience can sometimes lead to less-than-smooth demonstrations. On the other hand, pre-recorded videos or static code snippets often lack the dynamism that keeps an audience engaged. I needed something in between, and that’s where the idea for typeit.nvim was born.

I leveraged Neovim’s extensibility to create a plugin that allows presenters to simulate typing in real-time, complete with customizable typing speed. Whether you’re creating tutorials, giving live demos, or just want to add some flair to your coding screencasts, typeit.nvim can help bring your code to life.

In this blog post, I’ll guide you through the features, installation, configuration, and usage of typeit.nvim. By the end, you'll have a new tool in your Neovim arsenal for creating more engaging and realistic coding demonstrations, enhancing your Neovim experience.

Prerequisites

Before diving into the installation and setup of typeit.nvim, ensure you have the following:

  • Neovim version 0.9.0 or higher
  • A plugin manager such as, packer.nvim, or lazy.nvim

Installation

You can install typeit.nvim using various plugin managers. Below are the instructions for the three popular options:

Using packer.nvim

use 'Piotr1215/typeit.nvim'

Using lazy.nvim

{
'Piotr1215/typeit.nvim',
config = function()
require('typeit').setup({
-- Your configuration here
})
end
}

Configuration

After installation, you can configure typeit.nvim globally using the setup function. Here’s a basic example:

require('typeit').setup({
default_speed = 30, -- Default typing speed (milliseconds)
default_pause = 'line' -- Default pause behavior ('line' or 'paragraph')
})

Usage

Vim Commands

typeit.nvim provides several commands for simulating typing in Neovim:

  • :SimulateTyping [file_path] [speed]: Simulate typing from a file
  • :SimulateTypingWithPauses [file_path] [speed] [pause_at]: Simulate typing with pauses (‘line’ or ‘paragraph’)
  • :StopTyping: Stop the current typing simulation

Simulating Typing from a File

To simulate typing the contents of a file:

  1. Open a new empty buffer: :enew
  2. Use the SimulateTyping command:
:SimulateTyping ~/example.txt 30

This command simulates typing the contents of example.txt at a speed of 30 milliseconds per character.

Simulating Typing with Pauses

To simulate typing with pauses between lines or paragraphs:

  1. Open a new empty buffer: :enew
  2. Use the SimulateTypingWithPauses command:
:SimulateTypingWithPauses ~/example.txt 50 line

This command pauses after each line at a typing speed of 50 milliseconds per character. For paragraph pauses, use:

:SimulateTypingWithPauses ~/example.txt 50 paragraph

Simulating Custom Text Typing

You can also simulate typing custom text directly in Neovim:

  1. Open a new empty buffer: :enew
  2. Enter command mode and type your text in quotes:
:call luaeval("require('typeit').simulate_typing(_A[1], _A[2])", ["This is a custom text being typed out.", 40])

This command simulates typing “This is a custom text being typed out.” at a speed of 40 milliseconds per character.

For custom text with pauses:

:call luaeval("require('typeit').simulate_typing_with_pauses(_A[1], _A[2], _A[3])", ["Line 1\nLine 2\nLine 3", "line", 30])

This simulates typing the given lines with pauses after each line at a speed of 30 milliseconds per character.

Stopping the Simulation

To stop the typing simulation at any point, use:

:StopTyping

Alternatively, you can use Ctrl+C to interrupt the typing simulation.

Custom Keybindings

Set up custom keybindings for typeit.nvim commands:

vim.api.nvim_set_keymap('n', '<leader>st', ':SimulateTyping<CR>', { noremap = true, silent = true })
vim.api.nvim_set_keymap('n', '<leader>sp', ':SimulateTypingWithPauses<CR>', { noremap = true, silent = true })

Conclusion

typeit.nvim is a versatile plugin that brings dynamic typing simulations to Neovim, making it perfect for live demos, tutorials, and presentations. By integrating this plugin into your workflow, you can create more engaging content and showcase your coding skills in real-time.

Thanks for taking the time to read this post. I hope you found it interesting and informative.

🔗 Connect with me on LinkedIn

📺 Subscribe to my YouTube Channel

Crossplane resources in Neovim

· 2 min read

In the realm of text editors, Neovim stands out for its extensibility, especially for developers working with Kubernetes. The telescope-crossplane.nvim extension bridges the gap between Neovim's editing capabilities and Kubernetes resource management. This tutorial outlines the prerequisites, installation, and setup processes for integrating telescope-crossplane.nvim into Neovim, providing an efficient way to manage Kubernetes resources.

Prerequisites

Obviously some familiarity with Crossplane plus the following installed.

  • Neovim version 0.9.0 or higher.
  • The telescope.nvim plugin
  • kubectl

Installation

Installation of telescope-crossplane.nvim can be achieved through various plugin managers. A popular choice is packer.nvim. To install, include the following in the Neovim configuration file (init.lua):

use { "Piotr1215/telescope-crossplane.nvim",
requires = { { 'nvim-telescope/telescope.nvim' } },
config = function()
require("telescope").load_extension("telescope-crossplane")
end
}

Setup and Usage

Once installed, telescope-crossplane.nvim offers two commands that enhance Kubernetes management:

:Telescope telescope-crossplane crossplane_managed for managing Crossplane resources. :Telescope telescope-crossplane crossplane_resources for a broader view of Kubernetes resources.

These commands can be executed directly in Neovim, bringing Kubernetes resource management into the editor.

This integration significantly reduces context switching, as developers can view, edit, and manage Kubernetes resources without leaving their coding environment.

Benefits of Integration

Integrating telescope-crossplane.nvim with Neovim offers several advantages:

Streamlines Kubernetes workflows by bringing kubectl functionalities into Neovim. Enhances productivity by reducing the need to switch between terminal and editor. Offers a unified interface for code and Kubernetes resource management.

Conclusion

Neovim is a very extensible editor, lua is easy to learn and plugins not that difficult. It might be some learning at the beginning, but it’s well worth it.

The workflow with editing Crossplane resources (or any kubernetes resources for the matter) is a very common one. Deleting finalizes, adding/removing annotations etc. It’s all about staying in the flow and not leaving your main development environment.