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 following, this gives you lots of features that you'd expect to have in other editors such as Sublime Text / Textmate
.vimrc
: let g:airline#extensions#tabline#enabled = 1
. This automatically displays all the buffers as tab headers when you have no tab pages openedset wildmenu
in your .vimrc
then when you type :b <file part>
+ Tab for a buffer you will get a list of possible buffers that you can use left/right arrows to scroll through:Explore
but makes it much easier to work with. You just type -
to open the explorer, which is the same key as to go up a directory in the explorer. Makes navigating faster (however with fzf I rarely use this):cdo
on the results to do search and replaceTo add to the args
list:
:argadd
To delete from the args
list:
:argdelete
In your example, you could use :argedit
test.pl to add test.pl to the args
list and edit the file in one step.
:help args
gives much more detail and advanced usage
If using only vim built-in commands, the best one that I ever saw to switch among multiple buffers is this:
nnoremap <Leader>f :set nomore<Bar>:ls<Bar>:set more<CR>:b<Space>
It perfectly combines both :ls
and :b
commands -- listing all opened buffers and waiting for you to input the command to switch buffer.
Given above mapping in vimrc, once you type <Leader>f
,
23
to go to buffer 23,#
to go to the alternative/MRU buffer,<Tab>
, or <C-i>
to autocomplete,<CR>
or <Esc>
to stay on current bufferA snapshot of output for the above key mapping is:
:set nomore|:ls|:set more
1 h "script.py" line 1
2 #h + "file1.txt" line 6 -- '#' for alternative buffer
3 %a "README.md" line 17 -- '%' for current buffer
4 "file3.txt" line 0 -- line 0 for hasn't switched to
5 + "/etc/passwd" line 42 -- '+' for modified
:b '<Cursor> here'
In the above snapshot:
%a
for current, h
for hidden, #
for previous, empty for hasn't been switched to.+
for modified.Also, I strongly suggest set hidden
. See :help 'hidden'
.
My way to effectively work with multiple files is to use tmux.
It allows you to split windows vertically and horizontally, as in:
I have it working this way on both my mac and linux machines and I find it better than the native window pane switching mechanism that's provided (on Macs). I find the switching easier and only with tmux have I been able to get the 'new page at the same current directory' working on my mac (despite the fact that there seems to be options to open new panes in the same directory) which is a surprisingly critical piece. An instant new pane at the current location is amazingly useful. A method that does new panes with the same key combos for both OS's is critical for me and a bonus for all for future personal compatibility.
Aside from multiple tmux panes, I've also tried using multiple tabs, e.g. and multiple new windows, e.g.
and ultimately I've found that multiple tmux panes to be the most useful for me. I am very 'visual' and like to keep my various contexts right in front of me, connected together as panes.
tmux also support horizontal and vertical panes which the older screen
didn't (though mac's iterm2 seems to support it, but again, the current directory setting didn't work for me). tmux 1.8
Some answers in this thread suggest using tabs and others suggest using buffer to accomplish the same thing. Tabs and Buffers are different. I strongly suggest you read this article "Vim Tab madness - Buffers vs Tabs".
Here's a nice summary I pulled from the article:
Summary:
have a try following maps for convenience editing multiple files
" split windows
nmap <leader>sh :leftabove vnew<CR>
nmap <leader>sl :rightbelow vnew<CR>
nmap <leader>sk :leftabove new<CR>
nmap <leader>sj :rightbelow new<CR>
" moving around
nmap <C-j> <C-w>j
nmap <C-k> <C-w>k
nmap <C-l> <C-w>l
nmap <C-h> <C-w>h