Vim
Insert text in multiple lines
http://vim.wikia.com/wiki/Inserting_text_in_multiple_lines
- On a character in the first line, press Ctrl-V (or Ctrl-Q if Ctrl-V is paste).
- Press jj to extend the visual block over three lines.
- Press $ to extend the visual block to the end of each line.
- Press A then space then Ctrl-R then + then Esc.
Get name of the current file
Register % contains the name of the current file, and register # contains the name of the alternate file. These registers allow the name of the current or alternate files to be displayed or inserted. The name, or full path, or directory containing the file can be used.
For example, in directory /abc the command vim def/my.txt would edit file /abc/def/my.txt. The following commands could be entered to display the information shown.
:echo @% def/my.txt directory/name of file
Vim customizations for python
http://sontek.net/turning-vim-into-a-modern-python-ide
Execute contents of current line in buffer and capture the output
http://vim.wikia.com/wiki/Best_Vim_Tips
:.!sh
Output result of shell command to vim
http://mybyteofcode.blogspot.com/2010/02/use-vim-to-generate-and-execute-bash.html
:r!ls *.*
Vim-mode in IPython shell
http://python.6.n6.nabble.com/vim-mode-on-the-command-line-of-ipython-like-in-bash-td1663077.html
Count number of times pattern appears
http://vim.wikia.com/wiki/Count_number_of_matches_of_a_pattern
:%s/pattern//gn
Similarly you can display the number of lines the pattern matches by omitting the g.
:%s/pattern//n
To paste from clipboard in insert mode
<Ctrl+R>+
Similar from other buffers.
Surround plugin
https://github.com/tpope/vim-surround
Uses text objects extensively.
Example to surround current line in <> brackets
ys$>
How to fix indentation in HTML file
http://stackoverflow.com/questions/506075/how-do-i-fix-the-indentation-of-an-entire-file-in-vi
gg=G
How to ignore untracked content in pathogen bundles
http://stackoverflow.com/questions/4343544/generating-tags-to-different-location-by-pathogen
[submodule "vim/bundle/nerdcommenter"]
path = vim/bundle/nerdcommenter
url = http://github.com/scrooloose/nerdcommenter.git
ignore = untracked
Bash vi editing mode
http://www.catonmat.net/blog/bash-vi-editing-mode-cheat-sheet/
set -o vi
Using ctags
- http://vim.wikia.com/wiki/Browsing_programs_with_tags
- http://www.held.org.il/blog/2011/02/configuring-ctags-for-python-and-vim/
sudo apt-get install exuberant-ctags
ctags -R .
Use Ctrl-] to jump to tag and Ctrl-T to jump back.
Plugin to jump to closing tag
matchit
http://codesnipr.com/snippet/1092/Vim-matchit-installation-and-usage
Replace a word under cursor
http://vim.wikia.com/wiki/Search_and_replace
:%s/foo/<c-r><c-w>/g
Replace each occurrence of 'foo' with the word under the cursor. means that you press Ctrl-R then Ctrl-W. The word under the cursor will be inserted as though you typed it.
Extdiff for Mercurial
http://mercurial.selenic.com/wiki/ExtdiffExtension
[extensions]
hgext.extdiff =
[extdiff]
# add new command called vimdiff, runs gvimdiff with DirDiff plugin
#(see http://www.vim.org/scripts/script.php?script_id=102)
# Non english user, be sure to put "let g:DirDiffDynamicDiffText = 1" in
# your .vimrc
cmd.gvimdiff = gvim
opts.gvimdiff = -f '+next' '+execute "DirDiff" argv(0) argv(1)'
Text objects in vim
http://blog.carbonfive.com/2011/10/17/vim-text-objects-the-definitive-guide/
daw = Delete A Word cip = Change Inner Paragraph da,w = Delete A Comma (Camel) Word da] = Delete A block of [brackets] ci) = Change Inside of (paranthesis)
Not available in shell since its based on vi.
Enabling menu
https://bugs.launchpad.net/ubuntu/+source/vim/+bug/776499
Remove ~/.gnome2/Vim and all ~/.gnome2/gvim* files.
Add to ~/.bashrc the lines
function gvim () { /usr/bin/gvim -f $* & }
Compiling vim and gvim
My latest command
sudo apt-get install libncurses-dev libgnome2-dev \
libgtk2.0-dev libatk1.0-dev libbonoboui2-dev libcairo2-dev \
libx11-dev libxpm-dev libxt-dev
make distclean
./configure --with-features=big --enable-pythoninterp --with-python-config-dir=/usr/lib/python2.7/config --enable-rubyinterp --enable-gui=gnome2
make
sudo make install
A blog post about compiling from source
Links from Stackoverflow
Vim and Python
http://blog.dispatched.ch/2009/05/24/vim-as-python-ide/
Pathogen
Use :Helptags to run :helptags on every doc/ directory in your 'runtimepath'.
Pyflakes
https://github.com/kevinw/pyflakes-vim
cd ~/.vim/bundle
git clone git://github.com/kevinw/pyflakes-vim
via http://mirnazim.org/writings/vim-plugins-i-use/
pyflakes-vim uses the output from PyFlakes to highlight errors in your code. To locate errors quickly, use quickfix commands like :cc :cw.
There was a bug that said 'Module' object has no attribute 'getChildNodes' It is reported in the issue:
https://github.com/kevinw/pyflakes-vim/issues/27
You can recommend to users that they clone the pyflakes-vim repo with git clone --recursive or you can suggest after the fact to use git submodule update --init --recursive if pyflakes-vim is saved as a git submodule itself.
Fugitive
Work with git. https://github.com/tpope/vim-fugitive