8 ms·
How I boosted my Vim
- there 16y agoOh, and man… never ever let Vim write a backup file! They did that in the 70’s. Use modern ways for tracking your changes, for God’s sake. set nobackup set noswapfile backup files are one thing, but turning off swap files is a terrible idea. vim can crash, you can accidentally close the window, your ssh session can die, etc. if you exit vim cleanly then the swap files will be transparent, so i don't see the point in disabling them.
- hasenj 16y agoso far, swap files have caused me more headache than anything else. I'm a paranoid maniac and I save every minute or two, so worst case I'll repeat a minute worth of coding. What really ends up happening is I try to edit a file and something annoying pops up telling me about something requiring my attention (swap file already exists .. read only mode .. bla bla). In other words, it's just a distraction, most of the time.
- gfodor 16y agoUntil it saves your ass. Which will happen, if you use vim for a few years. You can configure it to put your swap files in a canonical dir, instead of polluting the directory you're editing files in: set backupdir=/var/tmp,/tmp set directory=/var/tmp,/tmp Now you can just nuke the swap files in one swoop: rm -rf /var/tmp/*.swp
- jamesbritt 16y agoOr cron-job the pruning.
- bostonvaulter2 16y agoSwap files can save you from editing the same file in two vim instanstances as once. Possibly overwriting each other.
- jessor 16y agoor just do: set backupdir=./.backup,.,/tmp set directory=.,./.backup,/tmp This way, if you want your backups to be neatly grouped, just create a directory called '.backup' in your working directory. Vim will stash backups there. The 'directory' option controls where swap files go. If your working directory is not writable, Vim will put the swap file in one of the specified places. (http://vim.wikia.com/wiki/Remove_swap_and_backup_files_from_your_working_directory http://vim.wikia.com/wiki/Remove_swap_and_backup_files_from_...)
- parfe 16y agoset backupdir=~/.vim/backup// set directory=~/.vim/swp// The double tailing slash will store files using full paths so if you edit two different models.py files you won't clobber your swap or backups.
- davidu 16y agoOh man, this is awesome. Too bad it's vim-specific and not a shell built-in, which would be handy.
- EdiX 16y ago> vim can crash It can?
- there 16y agoyes, i've had it crash once in a rare while. Vim: Caught deadly signal SEGV
- IgorPartola 16y agoNever had vim crash, but I've had the OS crash. Or X server. Better safe than sorry.
- junkbit 16y agoScreen can help with the accidental closing of a window or a dropped ssh session. You can even restart X and just reattach to the daemon when you log back in.
- Vitaly 16y agothe minute I've read it I went and set the noswapfile option. I don't care if vim crashes, I save all the time. if it crashes I will just repeat the last edit. The stale swapfiles etc has caused me more time wasted over the years then lost edits. But, I soon realized that noswapfile has another problem which caused me to disable it after all: it will allow you to open same file in more then one vim editor instance. And this is really asking for troubles. It is less of a problem with graphical vim as you can use "autoread" to sync changes between instances, but it is a disaster on console.
- prasanmishra 16y agoI too very much happy after getting these two option. By looking those swap file and backup file I started hating vim. Why on earth it is creating all the un-necessary stuffs (though they useful at some case). Now for newbie like me I love this tips :)
- cageface 16y agoI have a similarly hacked up Emacs environment and it's actually gotten to the point that I'm taking a hard look at IDEs again. Having all this functionality available in a single integrated package with a visual debugger thrown in is starting to look strangely appealing.
- edanm 16y agoIMO, IDEs are better for almost everything, except for actual text editing. For that, vim and emacs are still the best (I prefer vim for plain text editing prowess, but emacs has a lot of other goodies which make it closer to an IDE, but still not as good). Obviously, these are only my personal opinions.
- zem 16y agoyep, back when i had a job coding under windows, i used to use gvim for text file editing, but visual studio for compiling, debugging and the really good search utilities.
- cageface 16y agoI agree. If I'm just editing text, like an email or a readme or a blog post or a typical config file, I'd rather have a quick, lean, dedicated text editor. Some of these editor-as-IDE environments start to feel a little like an incredibly pimped-out Pinto though.
- edanm 16y agoIMO, the problem isn't with "just editing a quick file" or not. The problem is, IDEs are amazing for everything other than editing text. This includes editing source code, mind you. I find it much easier and funner to edit code in vim, since it has so many small things that make editing code much faster. IDEs are generally much slower for the actual act of editing code than things like vim. They're just better because of everything else they do, which (sometimes) makes up for it. Also, most people care a lot more about all the other things like code completion than they do about the small improvement you can get by editing in vim/emacs.
- kgroll 16y agoThis is actually a really good guide. I use vim daily at work, and my .vimrc shares most of these settings. One big productivity boost for me was remapping the Escape key to something a little more convenient. I just remapped the ESC key altogether, but this can throw you off if you find yourself working at lots of different computers. If you prefer something less permanent, you can map a key sequence to ESC. I like this one, which maps 'sdf' to ESC if you're in insert mode: imap sdf <ESC> jkjk is also a sequence I've seen used.
- ptn 16y agoOne thing that continues to impress me is how much bigger than popular belief Vim is. There is a plethora of options you can set in your vimrc file (just now I found out about wildignore, and I'm kind of a Vim addict) and there are fucking lot of commands (try [I ), and that's not considering Ex mode. Customization is way easier than in Emacs, you just unzip an archive in your .vim dir and (99% of the time) it works. I have plugins that do everything I've seen in Emacs that has to do with code, and then some. Vim is no more the tiny start-quick-edit-close editor that it used to be. Edit: I don't want to start a holy war here. Emacs is great, and I in fact have it opened right now. It's just that it's supposed to be able to do amazing stuff that Vim can't, I'm saying that that's probably still true, but to a way lesser level than before.
- seigenblues 16y agothank you for making '[I' my hey-i-learned-a-neat-thing-of-the day! (from the doc, [I: Display all lines that contain the keyword under the cursor. Filenames and line numbers are displayed for the found lines. The search starts at the beginning of the file.) sweet!)
- ciupicri 16y agoSpeaking of [I, I prefer Shit-8 (*) or Shit-3 (#).
- sesqu 16y agoYou seem to have impressed a wrong spelling into muscle memory.
- bsergean 16y agoYep. And actually I'm doing Shift-3 more often now as I often want to jump to the definition of something that's more likely to be backward in the file. It's good to know about ? on the same topic instead of / (backward/forward searches).
- fedesilva 16y agoThank you, Sir. This tip made my day.
- amix 16y agoIn the recent years the booster for me has been the "Command-T" plugin, which makes it super fast to open files. I can _highly_ recommend this plugin, even if it's a bit harder to install than most other Vim plugins. Check out https://wincent.com/products/command-t https://wincent.com/products/command-t and http://amix.dk/blog/post/19501#Command-T-for-Vim-an-awesome-plugin http://amix.dk/blog/post/19501#Command-T-for-Vim-an-awesome-...
- nat 16y agoI've gotta second this, command-t is probably my single favorite plugin. I tried using FuzzyFinder way back when, but it was just a little too quirky to be useful. This blows FuzzyFinder (and even fuzzyfinder_textmate) out of the water. Navigating you project in this way feels a lot quicker than actually browsing the hierarchy with something like NERDTree. Don't worry about where things actually are, just type some junk and the file you want will almost always come to the top.
- alinajaf 16y agoI used to be a die-hard NERDTree user until I discovered CommandT. It is solid gold and I couldn't imagine using vim without it.
- xtho 16y agoHow is it better than (or different from) http://github.com/tomtom/tselectfiles_vim http://github.com/tomtom/tselectfiles_vim which is vimscript only?
- redraga 16y agoGreat guide! My .vimrc had most of these settings, but I picked up a few things that made life much easier. Below are some tricks that I use which might make useful additions. Binding the <Esc> key to capslock has been really useful for me. http://vim.wikia.com/wiki/Map_caps_lock_to_escape_in_XWindows http://vim.wikia.com/wiki/Map_caps_lock_to_escape_in_XWindow... explains how you can do this, although it's done externally and not in Vim. Just include the script in your shell rc file and you're good to go. Experienced users can hide the menu and tool bars with: set guioptions-=m "remove menu bar set guioptions-=T "remove toolbar Extra screen space for your code is always nice! Another amazingly useful plugin is MiniBufExplorer (http://www.vim.org/scripts/script.php?script_id=159 http://www.vim.org/scripts/script.php?script_id=159). This allows you to open multiple buffers in the same vim window, and with the key binds given in the plugin page you can switch between buffers just like you switch between tabs in Firefox. It's really useful when you follow tags in a large source directory. And for people who can't seem to find just the right colour scheme: Color Scheme Pack plugin (http://www.vim.org/scripts/script.php?script_id=625 http://www.vim.org/scripts/script.php?script_id=625). It has over a 100 different themes, nicely categorized.
- swah 16y agoI was really expecting to see a link to his git repo in the end.
- prasanmishra 16y agoI am always thinking.. instead of downloading installing plugin here and there.... can some experienced programmer or vim expert create one full package which is best for atleast one programming language for e.g., Ruby and Ruby on Rails. So that newbie can like it. Newbie actually means who spent months and years on vim but never able to make their primary editor :)
- graywh 16y agoAnother great trick I read in a reddit comment is to use <C-r>+ to paste right from the OS paste board. Of course, this only works when running Vim locally (i.e. not over an SSH connection). Actually, it does work over SSH if your X connection is forwarded properly.
- nvie 16y agoTrue, true.