@@ -66,18 +66,27 @@ function E.insert_eol(ctype, cfg)
66
66
local line = A .nvim_get_current_line ()
67
67
local padding = U .get_padding (cfg .padding )
68
68
69
- -- NOTE:
70
- -- 1. Python is the only language that recommends 2 spaces between the statement and the comment
71
- -- 2. Other than that, I am assuming that the users wants a space b/w the end of line and start of the comment
72
- local space = vim .bo .filetype == ' python' and ' ' or ' '
73
- local ll = line .. space .. lcs .. padding
74
-
75
69
-- We need RHS of cstr, if we are doing block comments or if RHS exists
76
70
-- because even in line comment RHS do exists for some filetypes like jsx_element, ocaml
77
71
local if_rcs = (ctype == U .ctype .block or rcs ) and padding .. rcs or ' '
78
72
79
- local erow , ecol = srow - 1 , # ll - 1
80
- A .nvim_buf_set_lines (0 , erow , srow , false , { ll .. if_rcs })
73
+ local ecol
74
+ if line :match (' ^$' ) then
75
+ -- If line is empty, start comment at the correct indentation level
76
+ A .nvim_buf_set_lines (0 , srow - 1 , srow , false , { lcs .. padding .. if_rcs })
77
+ vim .cmd (' normal! ==' )
78
+ ecol = A .nvim_get_current_line ():len () - if_rcs :len () - 1
79
+ else
80
+ -- NOTE:
81
+ -- 1. Python is the only language that recommends 2 spaces between the statement and the comment
82
+ -- 2. Other than that, I am assuming that the users wants a space b/w the end of line and start of the comment
83
+ local space = vim .bo .filetype == ' python' and ' ' or ' '
84
+ local ll = line .. space .. lcs .. padding
85
+
86
+ local erow = srow - 1
87
+ ecol = # ll - 1
88
+ A .nvim_buf_set_lines (0 , erow , srow , false , { ll .. if_rcs })
89
+ end
81
90
U .move_n_insert (srow , ecol )
82
91
U .is_fn (cfg .post_hook , ctx )
83
92
end
0 commit comments