Advertisement
FocusedWolf

VIM: Window and Tab binds

May 13th, 2024 (edited)
1,470
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VIM 5.53 KB | None | 0 0
  1. if has('gui_running') " gVim
  2.     " Remove the toolbar.
  3.     set guioptions-=T
  4.  
  5.     " Remove the menu toolbar.
  6.     set guioptions-=m
  7.  
  8.     " Remove left-hand scrollbar.
  9.     set guioptions-=l
  10.     set guioptions-=L
  11.  
  12.     " Remove right-hand scrollbar.
  13.     set guioptions-=r
  14.     set guioptions-=R
  15.  
  16.     " Disable autoselect which forces MiddleMouse clicks in other programs to paste the contents of Vim's "+ unnamedplus register instead of the "* unnamed selection register. See :h go-a
  17.     set guioptions-=a
  18.     set guioptions-=A
  19.  
  20.     " Tab navigation
  21.     " SOURCE: http://genotrance.wordpress.com/2008/02/04/my-vim-customization/
  22.     " SOURCE: https://github.com/bashwork/settings/blob/master/linux/.vimrc
  23.  
  24.     " New Tab.
  25.     noremap <C-t> :tabnew<CR>
  26.     inoremap <C-t> <Esc>:tabnew<CR>i
  27.     cnoremap <C-t> <Esc><Esc>:tabnew<CR>
  28.  
  29.     " Close Tab.
  30.     "noremap <C-w> :tabclose<CR> " Firefox uses this but had to disable it because it interferes with ctrl + ww to switch between windows
  31.     noremap <C-q> :tabclose<CR>
  32.     inoremap <C-q> <Esc>:tabclose<CR>
  33.     cnoremap <C-q> <Esc><Esc>:tabclose<CR>
  34.  
  35.     " Next Tab.
  36.     noremap <C-Tab> :tabnext<CR>
  37.     inoremap <C-Tab> <Esc>:tabnext<CR>i
  38.     cnoremap <C-Tab> <Esc><Esc>:tabnext<CR>
  39.  
  40.     " Previous Tab.
  41.     noremap <C-S-Tab> :tabprevious<CR>
  42.     inoremap <C-S-Tab> <Esc>:tabprevious<CR>i
  43.     cnoremap <C-S-Tab> <Esc><Esc>:tabprevious<CR>
  44.  
  45.     " Hold shift for horizontal mouse-wheel scrolling.
  46.     " NOTE: This works for Linux and macOS but [:h scroll-mouse-wheel] says this does not work with Windows).
  47.     " SOURCE: https://github.com/graywh/dotfiles/blob/master/.gvimrc
  48.     noremap <S-ScrollWheelUp> <ScrollWheelLeft>
  49.     inoremap <S-ScrollWheelUp> <ScrollWheelLeft>
  50.     cnoremap <S-ScrollWheelUp> <ScrollWheelLeft>
  51.  
  52.     noremap <S-ScrollWheelDown> <ScrollWheelRight>
  53.     inoremap <S-ScrollWheelDown> <ScrollWheelRight>
  54.     cnoremap <S-ScrollWheelDown> <ScrollWheelRight>
  55.  
  56.     " Different cursors for different modes.
  57.     "
  58.     "     Default value of guicursor:
  59.     "     set guicursor=
  60.     "     set guicursor+=n-v-c:block-Cursor/lCursor,
  61.     "     set guicursor+=ve:ver35-Cursor,
  62.     "     set guicursor+=o:hor50-Cursor,
  63.     "     set guicursor+=i-ci:ver25-Cursor/lCursor,
  64.     "     set guicursor+=r-cr:hor20-Cursor/lCursor,
  65.     "     set guicursor+=sm:block-Cursor-blinkwait175-blinkoff150-blinkon175
  66.     "
  67.     " Moved v (Visual) to ve (Visual mode with 'selection') and applied a non-blinking block cursor.
  68.     " Made r (Replace) and cr (Command-line Replace) a blinking block cursor.
  69.     set guicursor=
  70.     set guicursor+=n-c:block-Cursor/lCursor,
  71.     set guicursor+=v-ve:block-Cursor-blinkon0,
  72.     set guicursor+=o:hor50-Cursor,
  73.     set guicursor+=i-ci:ver25-Cursor/lCursor,
  74.     " set guicursor+=r-cr:block-Cursor/lCursor,
  75.     set guicursor+=r-cr:hor20-Cursor/lCursor,
  76.     set guicursor+=sm:block-Cursor-blinkwait175-blinkoff150-blinkon175
  77. endif
  78.  
  79. " Bind Leader + Up/Down/Left/Right for window moving {{{
  80.  
  81. nnoremap <silent> <Leader><left> <C-w>H
  82. nnoremap <silent> <Leader><right> <C-w>L
  83. nnoremap <silent> <Leader><up> <C-w>K
  84. nnoremap <silent> <Leader><down> <C-w>J
  85.  
  86. " }}} Bind Leader + Up/Down/Left/Right for window moving
  87. " Bind Ctrl + Up/Down/Left/Right for window creation {{{
  88.  
  89. " Window creation.
  90. " SOURCE: https://stackoverflow.com/questions/22614280/vim-open-file-in-right-split
  91. " SOURCE: https://technotales.wordpress.com/2010/04/29/vim-splits-a-guide-to-doing-exactly-what-you-want/
  92. "nnoremap <silent> <C-left>   :leftabove  vnew<CR>:startinsert<CR>
  93. "nnoremap <silent> <C-right>  :rightbelow vnew<CR>:startinsert<CR>
  94. "nnoremap <silent> <C-up>     :leftabove  new<CR>:startinsert<CR>
  95. "nnoremap <silent> <C-down>   :rightbelow new<CR>:startinsert<CR>
  96.  
  97. " Open Startify in the created window.
  98. nnoremap <silent> <C-left>    :leftabove  vnew<CR>:Startify<CR>
  99. nnoremap <silent> <C-right>   :rightbelow vnew<CR>:Startify<CR>
  100. nnoremap <silent> <C-up>      :leftabove  new<CR>:Startify<CR>
  101. nnoremap <silent> <C-down>    :rightbelow new<CR>:Startify<CR>
  102.  
  103. " }}} Bind Ctrl + Up/Down/Left/Right for window creation
  104. " Bind Alt + Up/Down/Left/Right for window viewing {{{
  105.  
  106. " Built in ways to navigate windows:
  107. "   Cycle all windows: <Ctrl + W><Ctrl + W>
  108. "   Window navigating: <Ctrl + W><arrow key>
  109.  
  110. "nnoremap <A-left> <C-w>h
  111. "nnoremap <A-right> <C-w>l
  112. "nnoremap <A-up> <C-w>k
  113. "nnoremap <A-down> <C-w>j
  114.  
  115. " SOURCE[modded]: http://janneinosaka.blogspot.com/2014/10/automatically-resize-vim-splits.html
  116. function! SplitResize()
  117.     let ratio = 0.9 "2.0/3.0
  118.  
  119.     if &ft ==? 'help'
  120.         let hmax = 83
  121.     elseif &ft ==? 'nerdtree'
  122.         let hmax = 40
  123.     else
  124.         let hmax = max([winwidth(0), float2nr(&columns * ratio)])
  125.     endif
  126.  
  127.     let vmax = max([winheight(0), float2nr(&lines * ratio)])
  128.     exe "vertical resize" . hmax
  129.     exe "resize" . vmax
  130. endfunction
  131.  
  132. " NOTE: Use <Control-W>= to equalize windows size. See :h CTRL-W_=
  133. " CTRL-W =    Make all windows (almost) equally high and wide, but use
  134. "             'winheight' and 'winwidth' for the current window.
  135. "             Windows with 'winfixheight' set keep their height and windows
  136. "             with 'winfixwidth' set keep their width.
  137. "
  138. " Alt + = makes more sense.
  139. nnoremap <silent> <A-=> <C-w>=
  140.  
  141. " Window navigation.
  142. nnoremap <silent> <A-left>  <C-w>h:call SplitResize()<CR>
  143. nnoremap <silent> <A-right> <C-w>l:call SplitResize()<CR>
  144. nnoremap <silent> <A-up>    <C-w>k:call SplitResize()<CR>
  145. nnoremap <silent> <A-down>  <C-w>j:call SplitResize()<CR>
  146.  
  147. " }}} Bind Alt + Up/Down/Left/Right for window viewing
  148.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement