Skip to content

Commit

Permalink
(bugfix) set cursor shape to vertical bar on leaving vim
Browse files Browse the repository at this point in the history
why:
to distinguish between command and normal modes of vi mode in
powershell

how:
using VimLeave event and guicursor option

misc:
see :help guicursor

links:
- neovim/neovim#4867
- microsoft/terminal#4335

tags:
cursor,cursor-shape

fixes #5
  • Loading branch information
PrashanthaTP committed Aug 29, 2021
1 parent d5217df commit 44a5dd5
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 24 deletions.
23 changes: 23 additions & 0 deletions nvim/general/augroups.vim
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,34 @@ augroup END
" --- }}}

" Cursor management --- {{{
"https://github.com/microsoft/terminal/issues/4335
"
" https//vim.fandom.com/wiki/Configuring_the_cursor
" 1 or 0 -> blinking block
" 2 solid block
" 3 -> blinking underscore
" 4 solid underscore
" Recent versions of xterm (282 or above) also support
" 5 -> blinking vertical bar
" 6 -> solid vertical bar
"
augroup CURSOR_MANAGEMENT
autocmd!

" powershell requires different format for escape codes
" see :
" (i) https://docs.microsoft.com/en-us/powershell/module/psreadline/set-psreadlineoption?view=powershell-5.1#example-6--use-vimodechangehandler-to-display-vi-mode-changes
" (ii) https://github.com/microsoft/terminal/issues/1604
if has('win32')
"https://github.com/neovim/neovim/issues/4867#issuecomment-291249173"
autocmd VimEnter * silent !echo -ne "\e[2 q"
autocmd VimLeave * set guicursor=a:ver25

else
autocmd VimEnter * silent !echo -ne "\e[2 q"
autocmd VimLeave * silent !echo -ne "\e[6 q"
" autocmd VimLeave * let &t_me="\<Esc>]50;CursorShape=1\x7"
" autocmd VimLeave * let &t_SI.="\<Esc>[6 q"
endif
augroup END
" }}
23 changes: 23 additions & 0 deletions nvim/general/cursor.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
" also see augroups.vim
" cursor ----- {{{
" Cursor in terminal
" https//vim.fandom.com/wiki/Configuring_the_cursor
" 1 or 0 -> blinking block
" 2 solid block
" 3 -> blinking underscore
" 4 solid underscore
" Recent versions of xterm (282 or above) also support
" 5 -> blinking vertical bar
" 6 -> solid vertical bar
if &term =~ '^xterm'
" normal mode ||
" .= means shorthand for appending : see help .=
let &t_EI .= "\<Esc>[1 q"
" replace mode _
let &t_SR .= "\e[4 q"
" insert mode |
let &t_SI .= "\<Esc>[6 q"
endif
"
" }}}

28 changes: 4 additions & 24 deletions nvim/init.vim
Original file line number Diff line number Diff line change
@@ -1,41 +1,21 @@
let mapleader = "\<Space>"

source $LOCALAPPDATA/nvim/general/augroups.vim

source $LOCALAPPDATA/nvim/plugs/plugins.vim
source $LOCALAPPDATA/nvim/plugs/coc.vim
source $LOCALAPPDATA/nvim/plugs/lightline_v1.vim
source $LOCALAPPDATA/nvim/plugs/telescope_plug.vim
source $LOCALAPPDATA/nvim/plugs/firenvim.vim
source $LOCALAPPDATA/nvim/plugs/markdown.vim

source $LOCALAPPDATA/nvim/general/cursor.vim
source $LOCALAPPDATA/nvim/general/general.vim
source $LOCALAPPDATA/nvim/general/leader.vim
source $LOCALAPPDATA/nvim/general/keybindings.vim

source $LOCALAPPDATA/nvim/languages/languages.vim
"set path+=**
hi Normal ctermbg=none guibg=none
"wrap backspace
set backspace=indent,eol,start
hi Comment gui=italic cterm=italic
hi htmlArg gui=italic cterm=italic
" cursor ----- {{{
" Cursor in terminal
" https//vim.fandom.com/wiki/Configuring_the_cursor
" 1 or 0 -> blinking block
" 2 solid block
" 3 -> blinking underscore
" 4 solid underscore
" Recent versions of xterm (282 or above) also support
" 5 -> blinking vertical bar
" 6 -> solid vertical bar
if &term =~ '^xterm'
" normal mode ||
let &t_EI .= "\<Esc>[1 q"
" replace mode _
let &t_SR.="\e[4 q"
" insert mode |
let &t_SI .= "\<Esc>[6 q"
endif
"
" }}}


0 comments on commit 44a5dd5

Please sign in to comment.