Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

How to show cursorline only in active window of Vim

📅 2013-Feb-07 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ cursorline, vim, vimrc ⬩ 📚 Archive

I find it very useful to have the cursorline enabled in Vim. However, if you are using split windows, the cursorlines of multiple windows can get distracting. Also, this makes it difficult to know which is the active window.

One solution to these problems is to display the cursorline only in the active window. To do that add this to your vimrc:

augroup CursorLineOnlyInActiveWindow
  autocmd VimEnter,WinEnter,BufWinEnter * setlocal cursorline
  autocmd WinLeave * setlocal nocursorline
augroup END

Tried with: Vim 7.3 and Ubuntu 12.04 LTS

© 2022 Ashwin Nanjappa • All writing under CC BY-SA license • 🐘📧