Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ test.sh
nvim

spell/
lazy-lock.json
27 changes: 27 additions & 0 deletions .tmux.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
bind-key -r f run-shell "tmux neww ~/repo/config/tmux-s"

set-option -g prefix C-Space
unbind C-b
bind C-Space send-prefix

setw -g mode-keys vi
bind -T copy-mode-vi v send -X begin-selection
bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "pbcopy"
bind P paste-buffer
bind -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel "pbcopy"

set -g mouse on
set -g base-index 1

set -g status-style 'fg=red'
set -g status-left ' #S '
set -g status-left-length 20
set -g status-right ''
set -g status-bg black

setw -g window-status-current-style 'fg=black bg=red'
setw -g window-status-current-format ' #I #W #F '
setw -g window-status-style 'fg=red bg=black'
setw -g window-status-format ' #I #[fg=white]#W #[fg=yellow]#F '
setw -g window-status-bell-style 'fg=yellow bg=red bold'

58 changes: 58 additions & 0 deletions comment-toggle.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
-- Function to detect if a line contains JSX/TSX content
local function is_jsx_line(line)
-- Check for JSX patterns: <tag, </tag, self-closing <tag />, or JSX expressions
return line:match('<[/%a]') ~= nil
or line:match('/>%s*$') ~= nil
or line:match('^%s*{') ~= nil -- Lines starting with { (JSX expressions)
end

-- Function to comment out line(s)
local function comment_line()
local count = vim.v.count + 1
local start_line = vim.fn.line '.' -- Get current line number
local filetype = vim.bo.filetype

-- Check only the first line to determine comment style for all lines
local first_line = vim.fn.getline(start_line)

-- Detect if it's a JSX comment or regular comment on first line
local is_jsx_commented = first_line:match '^%s*{/%*' ~= nil
local is_regular_commented = first_line:match '^%s*//' ~= nil

-- Determine comment style to use based on first line
local use_jsx_comment = false
if not is_jsx_commented and not is_regular_commented then
-- When commenting: check if first line is JSX content
use_jsx_comment = (filetype == 'typescriptreact' or filetype == 'javascriptreact') and is_jsx_line(first_line)
end

for i = 0, count - 1 do
local line_num = start_line + i
local line = vim.fn.getline(line_num)
local new_line

if is_jsx_commented then
-- Uncomment JSX: remove {/* and */}
new_line = line:gsub('^(%s*){/%*%s*(.-)%s*%*/}', '%1%2')
elseif is_regular_commented then
-- Uncomment: remove leading whitespace, //, and optional space after //
new_line = line:gsub('^%s*//%s?', '')
else
-- Comment: use style determined from first line
if use_jsx_comment then
-- JSX comment: {/* ... */}
new_line = line:gsub('^(%s*)(.*)', '%1{/* %2 */}')
else
-- Regular comment: //
new_line = '// ' .. line
end
end

vim.fn.setline(line_num, new_line)
end

-- Move cursor down by count lines
vim.cmd('normal! ' .. count .. 'j')
end

vim.keymap.set('n', '<leader>c', comment_line, { desc = 'Toggle line comment(s)' })
Loading
Loading