Wikia

Vim Tips Wiki

Changes: Using vertical splits

Edit

Back to page

(Move categories to tip template)
(Remove html character entities)
 
Line 59: Line 59:
 
exec dir . " " . orientation " " . currFname
 
exec dir . " " . orientation " " . currFname
 
endfunction
 
endfunction
noremap ^W^] ^W^]:silent call ToggleSplit ("d")<CR>
+
noremap ^W^] ^W^]:silent call ToggleSplit ("d")<CR>
 
</pre>
 
</pre>
   
Line 66: Line 66:
   
 
In which case the above mapping becomes:
 
In which case the above mapping becomes:
noremap ^W^] :set splitbelow&lt;CR&gt;^W^]:silent call ToggleSplit ("u")&lt;CR&gt;:set nosplitbelow&lt;CR&gt;
+
noremap ^W^] :set splitbelow<CR>^W^]:silent call ToggleSplit ("u")<CR>:set nosplitbelow<CR>
   
 
Or you could just
 
Or you could just
Line 72: Line 72:
   
 
Very elegant and almost perfect, but it screws up if you want to run a command with ranges
 
Very elegant and almost perfect, but it screws up if you want to run a command with ranges
noremap : :vertical&lt;Space&gt;
+
noremap : :vertical<Space>
   
 
==Comments==
 
==Comments==

Latest revision as of 05:26, September 29, 2008

Tip 237 Printable Monobook Previous Next

created April 23, 2002 · complexity intermediate · author Kartik Agaram · version 6.0


This is just in case there's somebody else who likes to work in a maximized Vim window on a high resolution desktop. If you follow good coding practice and make sure your programs use only 80 characters in each row, have you noticed how much space lies unused on the right?

I find that the following settings keep me from ever seeing another horizontal split, unless I specifically ask for it.

cabbrev split vsplit
cabbrev hsplit split
cabbrev sta vertical sta
cabbrev help vertical help
cabbrev new vnew
cabbrev right botright
" A more heavyweight solution for ^W^]
function! ToggleSplit (dir)
  let currFname = bufname ("%")
  let old = winnr ()
  " Window navigation to ensure the correct window is 'last'.
  if (a:dir == "u")
    wincmd k
    let back="j"
  elseif (a:dir == "d")
    wincmd j
    let back="k"
  elseif (a:dir == "l")
    wincmd h
    let back="l"
  elseif (a:dir == "r")
    wincmd l
    let back="h"
  endif
  if (winnr () == old)
    echo "Ouch"
    return
  endif
  exec "wincmd " . back
  quit
  if (back == "j" || back == "k")
    let orientation = "vsplit"
  else
    let orientation = "split"
  endif
  if (back == "j" || back == "l")
    let dir = "below"
  else
    let dir = "above"
  endif
  exec dir . " " . orientation " " . currFname
endfunction
noremap ^W^] ^W^]:silent call ToggleSplit ("d")<CR>

Optional.

set splitright

In which case the above mapping becomes:

noremap ^W^] :set splitbelow<CR>^W^]:silent call ToggleSplit ("u")<CR>:set nosplitbelow<CR>

Or you could just

set splitbelow

Very elegant and almost perfect, but it screws up if you want to run a command with ranges

noremap : :vertical<Space>

CommentsEdit

Around Wikia's network

Random Wiki