This is so simple, it doesn’t even deserve an explanation:
Re-map your Caps Lock key to Ctrl and navigating around your tabs just got a lot easier.
To re-map in Ubuntu, open up the Dash, find the Keyboard Layout app, launch it, go to Options… and expand Caps Lock key behaviour. Select Make Caps Lock an additional Control but keep the Caps_Lock keysym. Close windows. Changes should be available immediately.
I am fairly new to Vim. When I switched editors and moved to Vim completely (about an year ago), I looked around for plug-ins and scripts other Users were using. I knew I was going to improve my text editing speed just by using the core editor itself, however I was more keen on setting up my very own personal environment.
What helped me a great deal were all those '[Vim plug-ins you MUST have][must-have]'-style articles. After a while, however, they got pretty boring as most were covering the same plug-ins.
As I started using Vim for everything (after an initial period of pain and suffering), I kept expanding my .vimrc and soon found it had grown to contain a lot of useful and rare gems. My intentions are by sharing these here they would also help you be more productive in your day-to-day tasks in Vim.
I like my code well indented and aligned… but it is a pain to keep it organised by hand. Tabular does this instead of you. It is extremely helpful and can deal with any coding style preference you may have. Take, for example, this input:
For quick access to Tabular, set up key bindings like so to trigger indentation on =:
HTML is dead, long live HTML5! This plug-in provides syntax highlighting for the new HTML5 tags which are not available out-of-the-box in a default Vim installation.
It also plays nicely with other plug-ins, such as php.vim.
If you do a lot of JavaScript development, you have probably been driven to despair on each new line. Vim’s default JavaScript syntax file is not very smart when it comes to indentation and it can sometimes be utterly stupid. This plug-in puts a stop to it all.
Basically, this is the TextMate Tasks Bundle port for Vim.
I like keeping NOTEs and TODOs in my projects. This is a very simple plug-in which provides syntax highlighting for *.tasks files and a couple of handy key bindings to deal with resolving items.
Undone your changes, tried something different and then realised you want to get your old code back? Gundo comes to the rescue giving you a tree of all edits and points of interest in the history.
Restart Vim and avoid losing your editing session. This plug-in saves your Vim sessions and restores them so it is like you never even left Vim. The default options are somewhat intrusive, but it doesn’t take too much to customise the plug-in to behave:
Whenever you feel you need to close Vim, but want to be able to get back your opened buffers, use \ss (where \ is the leader key) before :quitting. Next time you start Vim, use \sr to restore.
Note you wouldn’t be able to save options like plug-ins state, e.g., opened directories in NERDTree.
When I first got to Vim, I tried Command-T. I loved it… but having Ruby support available in Vim was proving an issue on some Windows machines. You also need to compile a binary which further meant the plug-in cannot be used out-of-the-box in a new Vim installation.
CtrlP is a great alternative with a slew of new features to offer. You still get a fuzzy matching file finder, but you can also search for tags, recent buffers, etc.
I don’t like having plug-ins register their key bindings without my say, so I turn off the defaults for CtrlP and create personalised mappings:
Use \o (where \ is the leader key) to fuzzy match and open a file and \b to fuzzy match and move to a tag in the current buffer (quickly navigate to a method, etc.)
The star * is a very powerful key in Vim. You can quickly look for all occurrences of the word under the cursor, but it is not always a word you’d be looking for. This plug-in extends the star in visual mode so it looks for all occurrences of the entire selected text, taking care of escaping any special characters or whitespace that may have been selected.
IMHO this is how Vim’s * should work by default in visual mode.
Add CSS3 syntax support to vim’s built-in syntax/css.vim.
This plug-in provides syntax highlighting for the new CSS3 properties. It is a bit trickier to set it up so it works for HTML and Sass buffers, but you only have to do it once anyway.
A Vim script to provide text objects for items in lists like ( a, b, c ), { a; b; c; } etc.
Lastly, I came across this plug-in several weeks ago and have been using it on a daily basis ever since. It deals with text objects for lists, e.g.:
Given the cursor position is defined by <|> above, pressing ci, will result in:
This is a great and quick way to change function arguments, list values, etc.
Tips & Tricks
Keep Your Focus
One of the greatest strengths of Vim is having your hands rest comfortably on the home row whilst you are editing away. It bugged me I can’t do the same with my screen, i.e., focus my attention on a given area and have everything I am working on flow in that particular line of screen. You can achieve this in Vim by setting the scrolloff option to a relatively big value:
It takes some getting used to, but eventually (hopefully) you will find there is less strain on your eyes.
Relative Line Numbers
I have always found this particular ‘feature’ of Vim to be extremely annoying. That is until I decided to try and live with it for at least a week. Coupled with the technique above, the editor becomes static and all that ever changes is the buffer itself. You can also much more easily navigate to a particular line since you know how many lines away it happens to be.
Long Lines Slow Down Vim
It has happened to all of us. You accidentally open a minified JavaScript file, Vim crawls to a complete halt and <C-C> cannot get you control of the editor back. This usually happens because Vim is having trouble syntax highlighting long lines. By setting a limit on the characters Vim will highlight per line at most, you can avoid situations like the above.
Dreadful ‘Ex’ mode
Q must be one of the most useless default key bindings in Vim. I have yet to hear someone making extensive use of ‘Ex’ mode. It is much more efficient having Q save and quit the current buffer (and you would also never have to type visual again):
Quick Indentation Settings
Very often files open with the wrong indentation settings. 2, 4 and 8 are the most common setting for spaces per indent:
Final Words
Leave a comment with your favourite, not-so-popular Vim plug-in or script below. Share this article with friends and on Twitter. I hope it has helped you make your Vim a little bit nicer to work from.
The design team at Canonical has decided to refresh the default theme in Ubuntu for its LTS release to feature light menus from light sources and dark menus from dark sources.
If you are anything like me, the decision didn’t probably go well with you either. I’ve been hacking on a ‘proper’ port back to dark menus, those interested can find the source and instructions available on GitHub.
I’ve kept the changes to a minimum so you’d still get all other improvements, such as less prominent controls for windows out of focus.
every time you launch an app, you have left a Gnome Shell module, which is no longer present on your system, in your GTK_MODULES environment variable. In my case, I enabled the Global Menu extension in Gnome Tweak Tool and then uninstalled Gnome Shell. To fix, I rmed the /etc/profile.d/globalmenu.sh file and rebooted.