vim is an extremely powerful editor and it is becoming high time for me to start learning vim well enough to hack on a lean and mean system.
##Distributions
There are likely many distributions of vim available. I plan to use the following distribution as the vim of my choice!
spf13-vim - The Ultimate Vim Distribution
I will use this on windows since I have a lot of flexibilty on other system that I hack on!
##Additional Useful Plugins
Put these into ~/.vimrc.local
" HTML {
Bundle 'Valloric/MatchTagAlways'
Plugin 'Chiel92/vim-autoformat'
Plugin 'The-NERD-Commenter'
Bundle 'keepcase.vim'
Plugin 'dkprice/vim-easygrep'
" }
##Keyboard tips
-
Shift between tabs using (source: linux - In vim, how can I quickly switch between tabs? - Super User):
- Next tab:
gt
- Prior tab:
gT
- Numbered tab:
nnngt
- Next tab:
-
Moving around in vim
- Use ^ or 0, in normal mode, to move to the beginning of a line.
- Use $, to go to end of line
-
Cut and Copying out of vim
set mouse = r
disables going into visual mode. you can then copy and cut out of vim- Often the line numbers interfere. Use this to enable or disable line numbers
- Disable
set nonumber
- Enable
set number
- Disable
- Often the line numbers interfere. Use this to enable or disable line numbers
-
Copy Multiple Lines
Position the cursor at the beginning of the text you want to cut/copy. Press v to begin character-based visual selection, or V to select whole lines, or Ctrl-v or Ctrl-q to select a block. Move the cursor to the end of the text to be cut/copied. While selecting text, you can perform searches and other advanced movement. Press d (delete) to cut, or y (yank) to copy. Move the cursor to the desired paste location. Press p to paste after the cursor, or P to paste before.
-
Match HTML tags
Add the following entry to ~/.vimrc.bundles.local
Bundle "Valloric/MatchTagAlways"
-
Comment code using NERD Commenter
,+c+space
seems to work!
- Jump to matching bracket
Press %
.. source: Moving to matching braces - Vim Tips Wiki
-
Deleting a file using NERDTREE
- Browse to the file using NERDTREE and then
m
followed byd
- Browse to the file using NERDTREE and then
-
Jump to matching HTML Tag
Press %
.. source: http://stackoverflow.com/a/501001
- Fold and Unfold HTML tags (Collapse or Expand HTML tags)
I have found zfat (or, equally, zfit) works well for folding with HTML documents. za will toggle (open or close) an existing fold. zR opens all the folds in the current document, zM effectively re-enables all existing folds marked in the document.
Source: How to fold/unfold HTML tags with Vim - Stack Overflow
- Indenting of visual blocks
In normal mode, type >> to indent the current line, or << to unindent. Each command can be used with a count. The operators > and < do the same for motions, text objects and visual selections. For all commands, pressing . repeats the operation.
For example, typing 5>>.. shifts five lines to the right, and then repeats the operation twice so that the five lines are shifted three times.
In insert mode, Ctrl-T indents the current line, and Ctrl-D unindents.
When indenting or unindenting, lines are shifted one 'shiftwidth' to the right or left.
Source: Shifting blocks visually - Vim Tips Wiki
- Setting the colorscheme for spf13
Do : colorscheme seoul256
... this seemed most colorful with enough distinction
-
Getting neocomplete to work
- On ubunut, had to install
sudo apt-get install vim-nox
as mentioned here- Execute the :NeoCompleteEnable command or set let g:neocomplete#enable_at_startup = 1 in your .vimrc (not in .gvimrc or _gvimrc!)
- On ubunut, had to install
-
Search for string in folder
- Install
ag
like here mileszs/ack.vim: Vim plugin for the Perl module / CLI script 'ack' - Then simply .. use
ag
commands like here :Ack analyze -l -G .html
Note the capital Ack
- Install
-
Moving between panes in vim
CTRL+w
-
Working with panes in vim: vim tips and tricks: multiple windows
##Git tips from vim using Fugitive
Source: Fugitive.vim - working with the git index
- Use
gdiff
. More importantly usediffget
anddiffput
. Make sure to check where you are working in theworking copy
or theindex copy
!
##Git tips
- Get list of all logs in commit history
git log --name-status
git log --name-only
git log --stat
git rev-list --all --header
- many more options here
##s3cmd
- Upload files so that they are publicly accessible
s3cmd put --acl-public --guess-mime-type storage.jpg s3://logix.cz-test/storage.jpg
- List of files in a s3 bucket
s3cmd ls s3://s3orionss/orionjs/
##Resources