One of the primary distinction betweeen vi (vim) and emacs, is emacs is designed and supposed to be run at times without quitting, where as given the quick load time of vim, it is easier to quit and start for editing tasks. I read that it has become a cultural difference between these two editor users.
I tend to think that keeping the editor running at all times, kind of helps in productivity as you know that, something is in progress and you need not start again. What is best tricks and plugins that you have found to run a single vim session and do all your tasks from there?
For e.g, I edit Python programs, then quit to run the appengine appcfg and go back. Sometimes quit current file to open another file. I have not yet gotten used to concept of buffers and tabs, but rather run vim in my screen sessions, if I want to edit multiple files.
Everything the others said plus three:
With
set hidden
you can open a new buffer in place of the current one, even if it's not saved. You can open dozens of buffers like that, no need to close Vim! See:help windows
or the Vim wiki.Supposing Vim is compiled with the correct flag (
+clientserver
) you can have a single Vim running as a "server" (in a terminal window A) and open all your files in that single Vim (from terminal window B). It's done in two steps:$ vim --servername WHATEVER
to start Vim$ vim --remote file.js
to open a fileYour file is opened in Vim in terminal window A and you still have your prompt in terminal window B.
Don't touch tabs. They are terribly wrongly named and don't work like tabs at all.
Just use the
:!
command to run stuff in a shell. It mixes great with:cd
and%
expansionYou can also mix it with
:read
if you want to put the output of a command in the current buffer:Here's good video tutorial that helps with workflow of how and why to use a single Vim session to manage all your edits:
http://www.derekwyatt.org/vim/vim-tutorial-videos/vim-intermediate-tutorial-videos/#onevim
If I'm running vim from console (which I do on linux because I use ssh exclusively), then I often use CTRL-z to suspend vim. Then do my shell stuff and fg to return to vim.
Using
ctags
in vim is incredibly useful --help tags
for more info.I use a perforce plugin that is quite powerful: http://www.vim.org/scripts/script.php?script_id=240. The diff support is amazing because you can cycle through all opened files or look at file history and diff between 2 older versions. Try :PVDiff, :PFilelog and :POpened.
I define a lot of macros for things like search and buffer windows manipulation. I have some interesting macros/functions listed here that help me live in vim.
Clipboard:
Tags:
Scratch:
IDE:
So you're running one file Vim per screen session? That sounds pretty bad man. You don't really need any special plugins to use multiple files in Vim easily. Just do
I have set
autochdir
in my.vimrc
which automatically changes current working directory to whatever buffer is currently active. So once you have that file open you can just doetc. BTW opening any files in Vim can be completed with tab completion so make sure you are doing that. Once you have a bunch of buffers open to switch between I just do
which you can also use tab completion for you can just type
:b 1
and hit tab and it will figure out you wantmyfile1.py
open so it is super quick if you can remember the general file name and if there is more than one similar match it will give you a list that you can tab through. For that I would also advise taking a look at thewildmode
andwildmenu
settings to see what you prefer they will give you enhanced tab completion menus. If at any time you start getting lost with what buffers are open and what you want to look at you can just doand it will show you everything open.
Also remember you can run external commands by preceding a command with
!
for example. Hope some of this helps or at least gets you looking in the right direction.
You can even drop down to a shell using :sh, and then get back to Vim using exit in the shell. For editing multiple files in the same Vim, you can use :vsplit filename or :split filename (for vertical and horizontal splits), and then use Esc+Ctrl+w+arrow keys to navigate between the different splits. This way you don't need tabs. Works especially well if you're working with small pieces of code.