           ;; in evil-mode, if we use hot key V `M-x evil-visual-line` to select line
           ;; the (line-beginning-position) of the line which is after the last selected
           ;; line is always (region-end)! Don't know why.
-          (if (and (> e b) (= e (line-beginning-position)) (boundp 'evil-state) (string= evil-state 'visual))
-              (setq e (1- e))
-            )
+          (if (and (> e b)
+                     (save-excursion (goto-char e) (= e (line-beginning-position)))
+                     (boundp 'evil-state) (eq evil-state 'visual))
+              (setq e (1- e)))
+
           (goto-char b)
           (setq b (line-beginning-position))
           (goto-char e)

              (setq b (line-beginning-position)))
          (if (> (line-end-position) e)
              (setq e (line-end-position)))
          (kill-region b (+ 1 e)) ; +1 because we need remove the CR
          ))))

;;;###autoload
(defun evilnc-default-hotkeys ()

   whole lines. Then we comment/uncomment the expanded region. NUM is ignored."
  (interactive "p")
  ;; donot move the cursor
  ;; support negative number
  (cond
   ((and (= 1 NUM) (string-match "^[ \t]*$" (buffer-substring-no-properties (line-beginning-position) (line-end-position))))
    ;; comment on current empty line
    (comment-dwim nil))
   (t
    (save-excursion
      (when (< NUM 0)
        (forward-line (1+ NUM))
        (setq NUM (- 0 NUM)))
      (evilnc--operation-on-lines-or-region '(lambda (b e)
                                               (evilnc--fix-buggy-major-modes)
                                               (evilnc--comment-or-uncomment-region b e))
                                            NUM))
    )))

;;;###autoload
(defun evilnc-copy-and-comment-lines (&optional NUM)
