Created
August 4, 2010 13:44
-
-
Save robince/508149 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" BufPos: Activate a buffer by its position number in the buffers | |
" list | |
" Author: Michele Campeotto <[email protected]> | |
" Date: 2007-04-25 | |
" Version: 1.0 | |
" | |
" This script provides a function to activate a vim buffer by passing it the | |
" position in the buffers list and maps it to <M-number> to easily switch | |
" between open buffers. | |
" | |
" This is best used togheter with the buftabs plugin: | |
" http://www.vim.org/scripts/script.php?script_id=1664 | |
function! BufPos_ActivateBuffer(num) | |
let l:count = 1 | |
for i in range(1, bufnr("$")) | |
if buflisted(i) && getbufvar(i, "&modifiable") | |
if l:count == a:num | |
exe "buffer " . i | |
return | |
endif | |
let l:count = l:count + 1 | |
endif | |
endfor | |
echo "No buffer!" | |
endfunction | |
function! BufPos_Initialize() | |
if has('gui_running') | |
for i in range(1, 9) | |
exe "map <M-" . i . "> :call BufPos_ActivateBuffer(" . i . ")<CR>" | |
endfor | |
exe "map <M-0> :call BufPos_ActivateBuffer(10)<CR>" | |
else | |
for i in range(1, 9) | |
exe "map " . i . " :call BufPos_ActivateBuffer(" . i . ")<CR>" | |
endfor | |
exe "map 0 :call BufPos_ActivateBuffer(10)<CR>" | |
endif | |
endfunction | |
autocmd VimEnter * call BufPos_Initialize() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment