Highlight cursor line when focus is lost.
[profile.git] / .vimrc
diff --git a/.vimrc b/.vimrc
index 24e05bc..71c5093 100644 (file)
--- a/.vimrc
+++ b/.vimrc
@@ -174,6 +174,7 @@ fun! Iain_Vars() "{{{2
   call Prep_Var("b:iainstatus", "'Fih'")
   call Prep_Var("g:iainextracolumnsnumber", "''")
   call Prep_Var("g:iainextracolumnslist", "''")
+  call Prep_Var("b:iaincul", 0)
   if has("signs")
     call Prep_Var("g:marksigns", 0)
     call Prep_Var("g:firstsign", 100)
@@ -1002,6 +1003,19 @@ fun! Show_GUITabLine() "{{{2
   return l:s
 endfun "}}}2
 
+" Toggle highlighting cursor line when focus changes.
+fun! <SID>ToggleCursorLine() "{{{2
+  call Iain_Vars()
+
+  if b:iainstatus =~# "f" && b:iainstatus =~# "H" && b:iainstatus =~# "I"
+    " Focus lost while held in insert mode.
+    let b:iaincul = getbufvar("", "&cursorline")
+    setlocal cursorline
+  elseif ! b:iaincul
+    setlocal nocursorline
+  endif
+endfun "}}}2
+
 se tabline=%!Show_TabLine()
 se guitablabel=%!Show_GUITabLine()
 
@@ -1012,6 +1026,8 @@ au StatusLine FocusLost * call Highlight_StatusLine("f")
 au StatusLine InsertEnter * call Highlight_StatusLine("I")
 au StatusLine InsertLeave * call Highlight_StatusLine("i")
 
+au Display FocusGained,FocusLost * call <SID>ToggleCursorLine()
+
 if has("signs")
   au Signs InsertEnter * call <SID>Highlight_Signs()
   au Signs InsertLeave * call <SID>Highlight_Signs()