I\'ve started using Vim to develop Perl scripts and am starting to find it very powerful.
One thing I like is to be able to open multiple files at once with:
<I use the same .vimrc file for gVim and the command line Vim. I tend to use tabs in gVim and buffers in the command line Vim, so I have my .vimrc set up to make working with both of them easier:
" Movement between tabs OR buffers
nnoremap L :call MyNext()<CR>
nnoremap H :call MyPrev()<CR>
" MyNext() and MyPrev(): Movement between tabs OR buffers
function! MyNext()
if exists( '*tabpagenr' ) && tabpagenr('$') != 1
" Tab support && tabs open
normal gt
else
" No tab support, or no tabs open
execute ":bnext"
endif
endfunction
function! MyPrev()
if exists( '*tabpagenr' ) && tabpagenr('$') != '1'
" Tab support && tabs open
normal gT
else
" No tab support, or no tabs open
execute ":bprev"
endif
endfunction
This clobbers the existing mappings for H and L, but it makes switching between files extremely fast and easy. Just hit H for next and L for previous; whether you're using tabs or buffers, you'll get the intended results.
if you're on osx and want to be able to click on your tabs, use MouseTerm and SIMBL (taken from here). Also, check out this related discussion.
In my and other many vim users, the best option is to,
:e file_name.extension
And then just Ctrl + 6 to change to the last buffer. Or, you can always press
:ls to list the buffer and then change the buffer using b followed by the buffer number.
:vsp for vertical split
:sp for horizantal split
And then <C-W><C-H/K/L/j>
to change the working split.
You can ofcourse edit any file in any number of splits.
You may want to use Vim global marks.
This way you can quickly bounce between files, and even to the marked location in the file. Also, the key commands are short:
'C
takes me to the code I'm working with,
'T
takes me to the unit test I'm working with.
When you change places, resetting the marks is quick too:
mC
marks the new code spot,
mT
marks the new test spot.
To see a list of current buffers, I use:
:ls
To open a new file, I use
:e ../myFile.pl
with enhanced tab completion (put set wildmenu
in your .vimrc
).
Note: you can also use :find
which will search a set of paths for you, but you need to customize those paths first.
To switch between all open files, I use
:b myfile
with enhanced tab completion (still set wildmenu
).
Note: :b#
chooses the last visited file, so you can use it to switch quickly between two files.
Ctrl-W s
and Ctrl-W v
to split the current window horizontally and vertically. You can also use :split
and :vertical split
(:sp
and :vs
)
Ctrl-W w
to switch between open windows, and Ctrl-W h
(or j
or k
or l
) to navigate through open windows.
Ctrl-W c
to close the current window, and Ctrl-W o
to close all windows except the current one.
Starting vim with a -o
or -O
flag opens each file in its own split.
With all these I don't need tabs in Vim, and my fingers find my buffers, not my eyes.
Note: if you want all files to go to the same instance of Vim, start Vim with the --remote-silent
option.
Vim (but not the original Vi!) has tabs which I find (in many contexts) superior to buffers. You can say :tabe [filename]
to open a file in a new tab. Cycling between tabs is done by clicking on the tab or by the key combinations [n]gt
and gT
. Graphical Vim even has graphical tabs.