Workspace efficiency - Vim tip 1 of 3

This is my first tip for advance usage of the Vim editor. It's meant for people that are already comfortable with Vim.

Requirements:

  • You are using Vim 7
  • You know how to install plugins
  • You know how to configure Vim (via .vimrc)
  • You know and have chosen a mapleader

Check out Vim documentation if you need help.

The idea

The general idea is to have a workspace! This is crucial if you use one Vim window. You can use multiple Vim windows, but this has a number of drawbacks:

  • Every Vim window has its own session. Vim yanking and pasting isn't possible.
  • Buffer completion gets useless since you only have one buffer open.
  • Every Vim window has its own undo session.
  • Most O/S window managers suck...
  • etc.

Here is how my Vim looks like and what we are aiming at:

General idea

Getting mini buffer explorer

This is a little script that lets you explore your buffers. I use it to have an overview over what files are currently open.

Download from Vim's site minibufexpl.vim. There is a guide on how to install it. My configuration of this script (place this inside your .vimrc file):

let g:miniBufExplModSelTarget = 1
let g:miniBufExplorerMoreThanOne = 0
let g:miniBufExplModSelTarget = 0
let g:miniBufExplUseSingleClick = 1
let g:miniBufExplMapWindowNavVim = 1
let g:miniBufExplVSplit = 25
let g:miniBufExplSplitBelow=1

map <c-w><c-t> :WMToggle<cr>

It's crucial that you know how to delete (close) buffers - without closing the window. If you don't: Deleting a buffer without closing the window...

Using tabs

I use Vim tabs when I am working on different parts of the same problem domain. For C you would have one tab for a header and another for the actual code. In MVC architecure you could have 3 tabs: view, controller and model. Etc.

To make it convinient here are my tab hotkeys:

map <leader>tn :tabnew %<cr>
map <leader>tc :tabclose<cr>
map <leader>tm :tabmove 

Now to open a new tab you just type ,tn in normal mode. My mapleader is ,.

Command line surfing

Vim command line is very powerful. I only use the command line to locate files, and I am pretty happy with the efficiency.

An animation (and introduction) of how I locate files and directories:

Intro to cmd surfing

Command line completion

Vim has excellent documentation, read about command line compeltion here. Ok, you read it? Well, notice Ctrl-D hotkey... This one is really nice :)

Before I come with an example, put this in your .vimrc:

set wildmenu

This will display command-line results in a wild menu :) After this is done go to command line mode and do this:

:e ~/Desktop/<CTRL-D>

CTRL-D is of course Control and D pressed togheter. Watch the result and I think you will have a pretty good understanding why CTRL-D is useful.

Notice: CTRL-D isn't the same as tab completion. Tab completions completes, CTRL-D shows you the available completions.

Lovely mappings

To speed things up I use some mappings, here are some really simple and useful command line mappings:

cno $h e ~/
cno $d e ~/Desktop/
cno $$ e ./

I.e. pressing $d prints out e ~/Desktop/! Notice: I have remapped the key below ESC to $, so pressing $ is lighting fast!

VIM Editor 9. Aug 2006
17 comments so far

I've been doing the same but I've been using > instead of $

cmap >v ~/.vim/
cmap >ftp ~/.vim/ftplugin/
cmap >fn <c-r>=expand('%:p')<cr>
cmap >fd <c-r>=expand('%:p:h').'/'<cr>



>fn inserts filename
>fd inserts directory of current file. quite useful

I also think typing: is nice but it needs some time. So I'v also but these mappings in my .vimrc:

noremap <m-s-e> :e<space>**/*
noremap <m-e> :e<space>
noremap <m-s-n> :n<space>**/*



The mapping **/* is used to find a file using glob pattern thus in any subdir. :n is opening all matches. you can cycle through the matches using tab.

If you want to edit files opened recently:
CTRL-O opens the last file. There is a plugin most recent files (link). Using a mapping for :MRU/ opens the most recent file dialog and starts search so you sould be able to find the file you were looking for very fast (either by remembering the directory or filename or extension.. or ... ;)

can you post your current .vimrc?

thanks!

hi jigg4joe

They will be up in a couple of days. Thanks for you interest.

With the new spellchecking in Vim7, its nice to be able to toggle it on/off easily. I use this mapping for that:

if v:version &gt;= 700
    function! <SID>ToggleSpell()
       if &spell != 1
           setlocal spell spelllang=en_us
       else
           setlocal spell!
       endif
    endfunction
    nnoremap &lt;silent&gt; &lt;F7&gt; &lt;ESC&gt;:call <SID>ToggleSpell()&lt;CR&gt;
    setlocal spell spelllang=en_us
endif

Marc:
The tip with using ":e **/*" is really great.

Amir, you are a total hero. Superb efforts to communicate the nuances of command-line surfing. Ctrl-D rocks!

Jim:
I appreciate that you like my tips - but really, I am no SuperMan ;)

Amir, I'm using gVim with vim version 7. When creating the initial new tab I find that the buffer explorer window vanishes completely. Upon selecting the previous tab via the mouse, the buffer explorer is visible again. Have you even seen this?

Also, I'm running E17 with the icon shelf configured to be above everything. When vim is running full screen and a new tab is created, the bottom of vim vanishes and I loose the command window :-( It's almost like it wants to go 100% full screen but some widget won't allow the redraw to be correct.

I'm not sure if this is a problem with gVim/vim itself, and/or an issue with the mini buffer explorer plugin.

Have you seen either of these issues before?

I think I'd prefer the mini buffer explorer plugin over the buffer explorer plugin but the tabs problem is preventing me from using it.

Hi Steve

I haven't had that issue :(

The tips are great and all, but what colorscheme are you using in the screenshot above? :)

If you're used to how bash handles completion and would rather type Tab than Ctrl-D, then just use these shortcuts:
set wildmode=longest,list,full
set wildmenu
set wildignore+=*.o,*.obj

Wildignore is obvious. Wildmenu is fairly useless in terms of speed, but if you like it, it's activated when wildmode reaches "full".

Wildmode is simple: the comma-separated list are actions that are taken when the TAB key is pressed. On any other keystroke, the position in the list gets reset.
Longest == longest expandable substring
List == display list of choices
Full == expand to first choice

So if you have three files in your directory, called
"The Goodies", "The Good Life", "The Avengers", and "Yes, Minister", and you type
:e T
it becomes
:e The\
A further tab:
:e The\
The\ Avengers The\ Good\ Life The\ Goodies
:e The\
Type G
:e The\ Good
Tab
:e The\ Good
The\ Good\ Life The\ Goodies
:e The\ Good
Tab
:e The\ Good\ Life
Tab
:e The\ Goodies

etc. Just like bash.

Sweet stuff,

there is a project plugin which does what the mini buffer explorer does and more.

try it out.
I activate the project tab with :
nmap § ToggleProject

§ this is the button below the ESC in swedish keymap..

Hi,

Really nice site with lots of usefull tips. I just started playing with the minibufferexplorer and it's good, but using your settings and having it in the right frame is really good.

I'm using tabs too but I was a bit disapointed by the default look (~/s/a/d/c/foo.cpp), so I'm using that now:

function GuiTabLabel()                                                                                                                
        let bufnrlist = tabpagebuflist(v:lnum)                                                                                           
        let bufId = bufnrlist[tabpagewinnr(v:lnum) - 1]                                                                              
        let fn = bufname(bufId)                                                                                                      
        let lastSlash = strridx(fn, '/')                                                                                             
        return strpart(fn, lastSlash+1, strlen(fn))                                                                                  
endfunction                                                                                                                          

set guitablabel=%{GuiTabLabel()}

I also learn the usage of the t command, which looks usefull. What I'm starting to like is the block commands, like diw (delete inner word), or =iB for indenting inner block, (use it with b for parenthesis). This works fine with C/C++ that uses { a lot, but does not work great with Python, but I'm sure there is a way to tell vim how to be nice with Python.

Thank you very much for this information. I like this site

nice article nice comments nice site.

Hi. I noticed that you use Mac Os. How did you manage to save a kind of video which shows your actions? I'd like to create some.

عقارات السعودية - عقارات الرياض - عقارات الخرج - عقارات مكة المكرمة - عقارات جدة - عقارات الطائف - عقارات المدينة المنورة - عقارات ينبع - عقارات الدمام - عقارات الخبر - عقارات الأحساء - عقارات القصيم - عقارات عسير - عقارات حائل - عقارات تبوك - عقارات الباحة - عقارات الحدود الشمالية - عقارات الجوف - عقارات جازان - عقارات نجران - عقارات مصر - عقارات القاهرة - عقارات الجيزة - عقارات حلوان - عقارات 6 اكتوبر - عقارات الاسكندرية - عقارات الساحل الشمالي - عقارات البحيرة - عقارات السويس - عقارات الاسماعلية - عقارات بورسعيد - عقارات البحر الاحمر - عقارات مطروح - عقارات جنوب سيناء - عقارات شمال سيناء - عقارات دمياط - عقارات الدقهلية - عقارات كفر الشيخ - عقارات الشرقية - عقارات الغربية - عقارات القليوبية - عقارات المنوفبة - عقارات الفيوم - عقارات قنا - عقارات المنيا - عقارات اسيوط - عقارات بني سويف - عقارات سوهاج - عقارات الوادي الجديد - عقارات الأقصر - عقارات اسوان - عقارات الامارات - عقارات ابوظبي - عقارات العين - عقارات دبي - عقارات جبل علي - عقارات الشارقة - عقارات رأس الخيمة - عقارات عجمان - عقارات أم القيوين - عقارات الفجيرة - الوطن العربي - عقارات الكويت - عقارات عمان - عقارات قطر - عقارات البحرين - عقارات الاردن - عقارات لبنان - عقارات المغرب - عقارات السودان - عقارات سوريا - وظائف - وظائف في السعودية - وظائف في الامارات - وظائف في مصر - وظائف في الكويت - وظائف في عمان - وظائف في قطر - وظائف في البحرين - وظائف في الاردن - وظائف في لبنان - وظائف في المغرب - وظائف في السودان - وظائف في سوريا - خدمات - العروض الجديدة - الرعاية و الإعلان - الدعم الفني - العقارات العام - شراء شقق - شراء شقة - شقق بالتقسيط - شقة بالتقسيط - شقق تمليك - شقة تمليك - شقق سكنية - شقة سكنية - شقق فندقية - شقة فندقية - شقق للايجار - شقة للايجار - شقق للبيع - شقة للبيع - شقق مفروشة - شقة مفروشة - غير مصنف - مطلوب شقق - مطلوب شقة
اهداف الدوري الأنجليزي
اهداف الدوري الأسباني
اهداف دوري ابطال اوروبا
مهارات ولقطات منوعة
اهداف الدوري السعودي
اهداف تصفيات كأس العالم
اهداف الدوري المصري
اهداف الدوري الالماني
أهداف كأس الخليج
هدف تيوب

Post a comment
Commenting on this post has expired.
© 2000-2009 amix. Powered by Skeletonz.