Skip to content

Commit a713c07

Browse files
feat: add vim command to toggle enabled state (#54)
Adds the command `:NvimContextVtToggle` to toggle the enabled state for showing virtual text. closes #53
1 parent 07da9b4 commit a713c07

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ require('nvim_context_vt').setup({
8181
})
8282
```
8383

84+
## Commands
85+
86+
* `:NvimContextVtToggle` - Enable/disable context virtual text
87+
8488
## Debug
8589

8690
If you don't see the expected context vitual text, run `:NvimContextVtDebug` to print out the

doc/nvim_context_vt.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ CONTENTS *nvim_context_vt-content
88
1. nvim_context_vt...............................................|nvim_context_vt|
99
1.1. How to install..................................|nvim_context_vt-install|
1010
1.2. Advanced usage.................................|nvim_context_vt-advanced|
11-
1.3. Debug.............................................|nvim_context_vt-debug|
12-
1.4. License.........................................|nvim_context_vt-license|
11+
1.3. Commands.......................................|nvim_context_vt-commands|
12+
1.4. Debug.............................................|nvim_context_vt-debug|
13+
1.5. License.........................................|nvim_context_vt-license|
1314

1415
--------------------------------------------------------------------------------
1516
HOW TO INSTALL *nvim_context_vt-install*
@@ -87,6 +88,11 @@ To customize the behavior use the setup function:
8788
})
8889
<
8990

91+
--------------------------------------------------------------------------------
92+
COMMANDS *nvim_context_vt-commands*
93+
94+
* `:NvimContextVtToggle` - Enable/disable context virtual text
95+
9096
--------------------------------------------------------------------------------
9197
DEBUG *nvim_context_vt-debug*
9298

lua/nvim_context_vt/init.lua

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ local utils = require('nvim_context_vt.utils')
55
local M = {}
66
local ns = vim.api.nvim_create_namespace('context_vt')
77
local opts = config.default_opts
8+
local enabled = true
89

910
function M.setup(user_opts)
1011
opts = vim.tbl_extend('force', config.default_opts, user_opts or {})
@@ -29,9 +30,19 @@ function M.show_debug()
2930
end
3031
end
3132

33+
function M.toggle_context()
34+
if enabled then
35+
enabled = false
36+
vim.api.nvim_buf_clear_namespace(0, ns, 0, -1)
37+
else
38+
enabled = true
39+
M.show_context()
40+
end
41+
end
42+
3243
function M.show_context()
3344
local ft = parsers.get_buf_lang()
34-
if vim.tbl_contains(opts.disable_ft, ft) then
45+
if not enabled or vim.tbl_contains(opts.disable_ft, ft) then
3546
return
3647
end
3748

plugin/nvim_context_vt.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
highlight default link ContextVt Comment
22

33
command NvimContextVtDebug lua require'nvim_context_vt'.show_debug()
4+
command NvimContextVtToggle lua require'nvim_context_vt'.toggle_context()
45

56
autocmd CursorMoved * lua require 'nvim_context_vt'.show_context()
67
autocmd CursorMovedI * lua require 'nvim_context_vt'.show_context()

0 commit comments

Comments
 (0)