   ;; Set the highlight background of current line to black, this make selected region become more
   ;; distinct.
   (set-face-background 'hl-line "#000000")
+
+  ;; Below settings maybe failed in some platform, in order to avoid affecting the executing of
+  ;; other settings, so place them at the bottom of "dotspacemacs/user-config".
+
+  ;; Copy to or paste from system clipboard when spacemacs is running in terminal.
+  (xclip-mode 1)
   )
 
-
-;; User defined functions.
+;; User defined macros and functions.
+
+;; Split window below or right according to the value of parameter "direction" and focus on it, then
+;; switch to scratch buffer.
+(defmacro split-and-focus-scratch (direction)
+  `(lambda ()
+     (interactive)
+     (,(intern (concat "split-window-" (symbol-name direction) "-and-focus")))
+     (spacemacs/switch-to-scratch-buffer)))
+
+;; Enter "evil-emacs-state" firstly, and then move cursor to next or previous line according to the
+;; value of parameter "direction".
+(defmacro enter-emacs-state-and-move-line (direction)
+  `(lambda ()
+     (interactive)
+     (evil-emacs-state)
+     (,(intern (concat (symbol-name direction) "-line")))))
+
+(defun enter-emacs-state-and-set-mark (arg)
+  "Enter \"evil-emacs-state\" firstly, and then set mark at the current position of cursor."
+  (interactive "P")
+  (evil-emacs-state)
+  (set-mark-command arg))
 
 ;; Save user's current buffer if there are any changes.
 (defun save-user-current-buffer ()

  (interactive)
  (if (not (string-match-p "^\*" (buffer-name)))
      (save-buffer)))

(defun split-below-and-focus-scratch ()
  "Split window below and focus on it, then switch to scratch buffer."
  (interactive)
  (split-window-below-and-focus)
  (spacemacs/switch-to-scratch-buffer))

(defun split-right-and-focus-scratch ()
  "Split window right and focus on it, then switch to scratch buffer."
  (interactive)
  (split-window-right-and-focus)
  (spacemacs/switch-to-scratch-buffer))

;; Do not write anything past this comment. This is where Emacs will
;; auto-generate custom variable definitions.

explicitly specified that a variable should be set before a package is loaded,
you should place your code here."
  (define-key evil-normal-state-map (kbd "m") 'evil-emacs-state)
  (define-key evil-normal-state-map (kbd "C-n") (enter-emacs-state-and-move-line next))
  (define-key evil-normal-state-map (kbd "C-p") (enter-emacs-state-and-move-line previous))
  (define-key evil-normal-state-map (kbd "C-@") 'enter-emacs-state-and-set-mark)
  (define-key evil-normal-state-map (kbd "C-SPC") 'enter-emacs-state-and-set-mark)
  ;; Escape from "evil-emacs-state" to "evil-normal-state" when press "ESC" twice consecutive, this
  ;; key binding is useful for working in high latency network, because "evil-escape-key-sequence"
  ;; can't work very well in this situation.
  (define-key evil-emacs-state-map "" 'evil-normal-state)
  ;; Change some leader key bindings.
  (spacemacs/set-leader-keys
    "bk"  'kill-buffer-and-window
    "w-"  (split-and-focus-scratch below)
    "w/"  (split-and-focus-scratch right))
  ;; Mouse scrolling doesn't work when emacs is run in Mac OSX terminal. The root cause is that
  ;; mwheel.el set "mouse-wheel-up-event" and "mouse-wheel-down-event" to "wheel-down" and
  ;; "wheel-up" because of "ns-win" always in "features" of emacs no matter emacs is launched in GUI
  ;; or terminal environment. In addition, the mouse wheel keys received from terminal is "mouse-4"
  ;; and "mouse-5", received from GUI is "wheel-up" and "wheel-down". So change the values of
  ;; "mouse-wheel-up-event" and "mouse-wheel-down-event" can't make emacs GUI and terminal clients
  ;; work well at the same time when they connect to the same emacs daemon.
  (if (featurep 'ns)
      (progn
        (global-set-key (kbd "<mouse-4>") (kbd "<wheel-up>"))
        (global-set-key (kbd "<mouse-5>") (kbd "<wheel-down>"))))

  ;; Ignore hidden files in "counsel find file" default, these files will appear unless we input "."
  (setq counsel-find-file-ignore-regexp "\\`\\.")
  ;; Use the input to replace the selected region.
