Add OpenInOtherWindow to .vimrc
David Blume

David Blume commited on 2016-04-07 02:06:32
Showing 1 changed files, with 24 additions and 1 deletions.

... ...
@@ -1,4 +1,4 @@
1
-" Version 2015-08-12.1 - Leader-n = number! Leader-e = nerdtree (:Explore)
1
+" Version 2016-04-07.1 - OpenInOtherWindow()
2 2
 set nocompatible    " Use Vim defaults, forget compatibility with vi.
3 3
 set bs=2            " allow backspacing over everything in insert mode
4 4
 set wildmenu        " Allows command-line completion with tab
... ...
@@ -158,6 +158,29 @@ function! DeleteTrailingWS()
158 158
   exe "normal `z"
159 159
 endfunc
160 160
 
161
+function! OpenInOtherWindow()
162
+  if winnr('$') == 1
163
+    exe "wincmd F"
164
+  else
165
+    let curNum = winnr()
166
+    let oldBuf = bufnr( "%" )
167
+    if curNum == 1
168
+      let othNum = 2
169
+    else
170
+      let othNum = 1
171
+    endif
172
+    exe "normal! gF"
173
+    let newBuf = bufnr( "%" )
174
+    let newLine = line(".")
175
+    exe 'hide buf' oldBuf
176
+    exe othNum . "wincmd w"
177
+    exe 'hide buf' newBuf
178
+    exe "normal! " . newLine . "G"
179
+  endif
180
+endfunc
181
+
182
+nmap <silent> <leader>F :call OpenInOtherWindow()<cr>
183
+
161 184
 if has("autocmd")
162 185
   autocmd! BufWritePost .vimrc source %           " re-source this file when saved.
163 186
   autocmd BufWrite *.py :call DeleteTrailingWS()  " Delete trailing whitespace
164 187