Home

Awesome

Date Time Inserter

Date Time Inserter is a simple/basic Neovim plugin that allows you to easily insert the current date and time into your Neovim buffer.

preview

Why?

This plugin does basically the same as the code block below, but this requires the date command to be installed on the system. Therefore it's not always possible to use it on every system, this is exactly what Date Time Inserter tries to solve by using the lua built-in os.date() function. The plugin allows you to insert the date and time into your Neovim buffer on every system regardless of the operating system.

vim.keymap.set("n", "<leader>dt", ':r! date "+\\%d-\\%m-\\%Y" <CR>', {noremap = true, vim.keymap.set})
vim.keymap.set("n", "<leader>tt", ':r! date "+\\%H:\\%M:\\%S" <CR>', {noremap = true, vim.keymap.set})

Warning

Please note that this is my first plugin for Neovim, so it may not be as efficient or polished as other plugins. This is probably due to my REALLY basic knowledge of lua or my shitty programming brain 😅. Jokes a side feedback and suggestions are ALWAYS welcome 😉!

Installation

Using Packer

  1. Add this to your Neovim config:
use { 'AntonVanAssche/date-time-inserter.nvim' }
  1. Run :PackerSync to install the plugin on your machine.

Using Vim-Plug

  1. Add the following to your Neovim config:
Plug 'AntonVanAssche/date-time-inserter.nvim'
  1. Run :PlugInstall to install the plugin on your machine.

Manually

  1. Clone this repository into your Neovim ~/.config/nvim/pack/plugins/start/directory.

Configuration

You can configure the plugin by adding the following to your init.lua:

Configuring Date Time Inserter in init.vim

All the examples below are in lua. You can use the same examples in .vim files by wrapping them in lua heredoc like this:

lua << END
    require('date-time-inserter').setup()
END

Configuring Date Time Inserter in init.lua

Here is an example of how you can configure the plugin in your init.lua file. The example below shows the default configuration, which you can customize by modifying the values of the different settings.

local date_time_inserter_status_ok, date_time_inserter = pcall(require, "date-time-inserter")
if not date_time_inserter_status_ok then
    return
end

date_time_inserter.setup {
    date_format = 'MMDDYYYY',
    date_separator = '/',
    time_format = 12,
    show_seconds = false,
    insert_date_map = '<leader>dt',
    insert_time_map = '<leader>tt',
    insert_date_time_map = '<leader>dtt',
}

You can customize the following settings:

If you do not configure Date Time Inserter or leave certain settings unconfigured, it will use its default settings for those settings.

Usage

Using keybindings

To use Date Time Inserter, you simply need to press the key combination you specified in the configuration file. For example, if you set insert_date_map to '<leader>dt', pressing <leader>dt in normal mode will insert the current date into the buffer. Similarly, pressing the key combination you specified for insert_time_map or insert_date_time_map will insert the current time or both the date and time, respectively.

Using commands

You can also use the commands like ':InsertDate', ':InsertTime', and ':InsertDateTime' to call the plugin (in normal mode).

For example:

:InsertDate
:InsertTime
:InsertDateTime

License

Date Time Inserter is licensed under the MIT License. See the LICENSE.md file for more information.

Contributing

Contributions are welcome! Please feel free to submit a pull request or open an issue for any bugs or feature requests.