Vim

Use correct browser when using fugitive Gbrowser command

https://github.com/tpope/vim-fugitive/issues/75

  git config --global web.browser google-chrome

Reformat long lines with line breakes

First set your vim so that it understands that you want 80 characters:

:set tw=80 then, hilight the line:

V and make vim reformat it:

gq

http://stackoverflow.com/questions/1272173/in-vim-how-do-i-break-one-really-long-line-into-multiple-lines

Error in Ubuntu about application menu

http://askubuntu.com/questions/132977/how-to-get-global-application-menu-for-gvim

** (gvim:20320): WARNING **: Unable to create Ubuntu Menu Proxy: Timeout was reached

Disable global menu for gvim in making an alias in .bashrc:

alias gvim='UBUNTU_MENUPROXY= gvim'

Show line numbers

set number

To remove:

set nonumber

Format json

http://blog.realnitro.be/2010/12/20/format-json-in-vim-using-pythons-jsontool-module/

:%!python -m json.tool

Set gui font size

http://vim.wikia.com/wiki/Setting_the_font_in_the_GUI

  :set guifont=*

and choose font.

Code completion for Django

http://blog.roseman.org.uk/2010/04/21/vim-autocomplete-django-and-virtualenv/

I am using vim-virtualenv so most of the advice in the link above is not really relevant. But specificly for Django:

From command line

  export DJANGO_SETTINGS_MODULE=giffeed.settings

Things to try to check:

  :python import sys; print sys.executable
:python from django import db

Find location of a file in NERDTree

http://superuser.com/questions/195022/vim-how-to-synchronize-nerdtree-with-current-opened-tab-file-path

  map <leader>r :NERDTreeFind<cr>

Modify macro

To modify the macro, move to a blank line and type "Rp replacing R with the register name of your macro. After making the changes you need, save the macro by typing 0"Ry$ replacing R with the register name you want to use for the macro.

http://byron.theclarkfamily.name/blog/archive/2007/03/1/

Turn spelling on/off

:set spell
:set nospell

Map Gdiff to show diff with a revision

:nmap <silent> \d :Gdiff 148ab<CR>  

Ctrl-i is opposite to Ctrl-o

Jumping to the new location is Ctrl-i (opposite to Ctrl-o).

Close all splits except active one

http://stackoverflow.com/questions/4809729/cancel-split-window-in-vim

:on or Ctrl-w Ctrl-o

Mnemonic rule - :only

Add words to spell words list

:zg

Open all folds

zR

Replacing ^M

:%s/\r//g

Count words

g Ctrl-g

Change encoding in 50 files

Task: change encoding in 50 files from windows to utf. Solution: map

map q :set fileencoding=utf-8:wn

Open all files in one window and press q, until encoding is changed in all the files. In the last file the command n will not work – just quit.

End of file

The first line always has number one. How about the last line? The $ character is used for this. For example, to substitute in the lines from the cursor to the end:

:.,$s/yes/no/

Editing more than one file

Highlight several files and with right click select "Edit with single Vim". To go to the next file type

:next

or simply

:n

If quit and there are some files left, vim will generate an error: "More files to edit". Simply quit one more time.

Wrapping after 76 characters

Removed the following line from vimrc file.

" Wrap after 76 Chars (could probably be 77, too)
set textwidth=75

It is probably relevant for Phython, but annoying for LaTex.

Russian characters

Tried to open a file containing Russian characters. It could not read it. Solution was as simple as to put

set encoding=utf-8

Text disappering

Re-drawing glitch in Ubuntu:

http://stackoverflow.com/questions/8597247/text-in-gvim-disappearing

:se guioptions=agim

Count number of words in a selection

To count the number of words in a block, select the block (for example, type V5j to select 6 lines) and again press g then Ctrl-g.

http://vim.wikia.com/wiki/Word_count

Search word under cursor in backward direction

http://tnerual.eriogerg.free.fr/vimqrc.html

# * - search backward, forward for word under cursor

Show error messages

:mess

New modules

Some bindings I've also added and keywords I should remember to use initially.

\t - RopeGotoDefinition, \r - RopeRename.

Tab for completion with supertab.

\pw - show pydocs for the module.

:VirtualEnvList :VirtualEnvActivate

F5 - to open gundo window

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

sudo apt-get install exuberant-ctags
ctags -R .

or only Python files

ctags -R *.py */*.py

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

Compile gvim under ubuntu

Compiling with Python support

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 s

Last edited by Artem Dudarev, 2013-10-13 02:01:37. Edit