        (progn
          (message "File path copied: %s" -fpath) -fpath)))))
 (define-key global-map (kbd "C-c 1") 'vvv/copy-file-path)
+
+(defun vvv/grep (command-args)
+  "When in git repository, run git-grep from its top-level directory;
+otherwise run ordinary grep."
+  (interactive
+   (progn
+     (grep-compute-defaults)
+     (let* ((git-toplevel (string-trim-right
+			   (shell-command-to-string
+			    "git rev-parse --show-toplevel 2>/dev/null")))
+	    (git-p (not (string-empty-p git-toplevel))))
+       (when git-p
+	 (setq default-directory git-toplevel))
+       (list (read-shell-command "Run: "
+				 (if git-p
+				     "git --no-pager grep -nHE "
+				   grep-command)
+				 'grep-history)))))
+  (compilation-start command-args 'grep-mode)
+  (switch-to-buffer-other-window grep-last-buffer))
+(global-set-key (kbd "C-c g") 'vvv/grep)
 
 (defun xah-open-file-at-cursor ()
   "Open the file path under cursor.

  (global-set-key (kbd "M-x") 'counsel-M-x)
  (global-set-key (kbd "C-x C-f") 'counsel-find-file)
  (global-set-key (kbd "C-c j") 'counsel-git)
  (global-set-key (kbd "C-c g") 'counsel-git-grep)
  (global-set-key (kbd "C-c i") 'counsel-imenu)
  (global-set-key (kbd "C-c p") 'ivy-push-view)
  (global-set-key (kbd "C-c P") 'ivy-pop-view))


(dolist
    (m '(c-mode python-mode sh-mode rust-mode html-mode js-mode haskell-mode
		markdown-mode yaml-mode ruby-mode org-mode emacs-lisp-mode
		sql-mode))
  (font-lock-add-keywords m
   ; Fontify "XXX", even in comments.
   '(("\\<\\(XXX\\)" 1 'font-lock-warning-face prepend))))
