wiki:linux/vim

Vim - ZeroMQ - iPython: Eine IDE


My most used mappings

Note: The leader key in my configuration is the , key.

my own

mapping vim command
Escape ,e inoremap <Leader>e <Esc>l
vnoremap <Leader>e <Esc>
nnoremap <Leader>e <Esc>
cnoremap <Leader>e <Esc>
Folding <Space> map <Space> za
gb Jump back from previous movements map gb <C-o>
gt Goto tag under word noremap gt g<C-]>
<C-y> Put comment char to start of line/selected lines map <C-y> :s/^/#<CR>
<C-x> Remove comment char from start of line/selected lines map <C-x> :s/#<CR>
,O Insert line above cursor map <Leader>o O<Esc>
,o Insert line below cursor map <Leader>O o<Esc>
<Tab> Indent line/selection map <Tab> >>
:vmap <Tab> >
<S-Tab> Outdent line/selection map <S-Tab> <<
vmap <S-Tab> <
,y Copy marked text into X clipboard map <silent> <Leader>y "xy:call system('xsel -i -b', @x)<CR>
,p
,P
Paste text from X clipboard map <silent> <Leader>p :let @x=system('xsel -b')<CR>p
map <silent> <Leader>P :let @x=system('xsel -b')<CR>P
by vim
<command>a<object> <command> a object ('a'!) with leading or trailing whitespace(s) :help text-object
<command>i<object> <command> only the object ('i'nner!) without any leading or trailing whitespace(s) <command>
d Delete
c Change
v Select

<object>
w Word
( Parenthesis
[ Squared bracket
{ Curly bracket
" Double quote
' Single quote

Search and replace

Wikia > vim search and replace

Note: As of Vim 7.3, substitutions applied to a range defined by marks or a visual selection (which uses a special type of marks '< and '>) are not bounded by the column position of the marks by default. Instead, Vim applies the substitution to the entire line on which each mark appears unless the \%V atom is used in the pattern like: :'<,'>s/\%Vfoo/bar/g.

Entering special characters

By decimal value ^V nnn 000 <= nnn <= 255
By octal value ^V O nnn or ^Vonnn 000 <= nnn <= 377
By hex value ^V X nn or ^V x nn 00 <= nn <= FF
By hex value for BMP Unicode codepoints ^V u nnnn 0000 <= nnnn <= FFFF
By hex value for any Unicode codepoint ^V U nnnnnnnn 00000000 <= nnnnnnnn <= 7FFFFFFF

By example to enter the unicode number for the leftward arrow (2190) within insert mode press CTRL-V then u (release CTRL!) and 2190. Voila: ←

X clipboard in a X-less vim

By using vim without the +xterm_clipboard option such it is in the Debian vim-package these mappings will doing the job:

Copy text from vim into the X clipboard via <Leader>y:

map <silent> <Leader>y "xy:call system('xsel -i -b', @x)<CR>

Paste text from X clipboard into vim via <Leader>p|P:

map <silent> <Leader>p :let @x=system('xsel -b')<CR>p
map <silent> <Leader>P :let @x=system('xsel -b')<CR>P

Be sure you have installed the xsel package!

The fakeclip plugin provides a pseudo-clipboard within X and even GNU screen with much more mappings as above such as d, dd, D, yy ....

Indentation

Indenting Python with VIM

python.vim for indentation

indent/python.vim : An alternative indentation script for python

~/.vim/indent/python.vim (needed for correct indentation of multiple lines inner [] and {}...)

Works only for max 50 lines per default, set maxoff higher, e.g. for 150 lines

let s:maxoff = 150

if indentation with the default value fails, e.g. long lists for test cases.

This solution was found here: VIM python filetype specific indent fails after 50 lines of one list

indentLine

see indentLine below

Configuration

Save & restore view of file

To save the current cursor position and/or state of folds (see the :mkview documentation for a full description) put this in your ~/.vimrc:

au BufWinLeave * silent! mkview
au BufWinEnter * silent! loadview

Without giving a specific name for the view it will be saved into ~/.vim/view directory by default.

Snippets

Check for version or specific feature

vim scripting, if vim version is < 7.3

"vim version 7.3 = 703!!
if v:version >= 703
   do things for versions equal or greater 7.3
endif

Equivalent to above...

if version >= 703
    ...
"is relativenumber feature available
if exists('+relativenumber')
    do things which needs the relativenumber feature
endif

Check for filename

function! GetFilename()
    let file_name = bufname("%")
    if !empty(file_name)
        echo file_name
    else
        echo "no filename"
    endif
endfunction

Plugins

Autocomplection

jedi

an auto-completion plugin, don't tested
jedi-vim

pythoncomplete

~/.vim/autoload/pythoncomplete.vim (don't use any more)
pythoncomplete : Python Omni Completion

Folding

jpythonfold

jpythonfold.vim : A better python fold script

simpylfold

No-BS Python code folding for Vim

My favourite cause it folds docstrings!

Syntax checkers

pyflakes

pyflakes.vim : PyFlakes on-the-fly Python code checking

Checks on the fly and highlights not only the line but the exact position of an error occurence too.

syntastic

syntastic

How to jump/display the column of an error
how to make syntastic show current line errors in insert mode in vim?

Highlighting

python.vim for syntax highlighting

~/.vim/syntax/python.vim
python.vim : Enhanced version of the python syntax highlighting script

Indentation

indentLine

indentLine

This plugin is used for displaying thin vertical lines at each indentation level for code indented with spaces.

Helpers

NERDtree

~/.vim/nerdtree_plugin
~/.vim/plugin/NERD_tree.vim
The NERD tree : A tree explorer plugin for navigating the filesystem

TagBar

tagsbrowser (really needed?)
Tagbar

pathogen

I resistet using this plugin a long time. But what should I do? It's quite easy!
pathogen

CSApprox

~/.vim/plugin/CSApprox.vim (don't use any more)
CSApprox : Make gvim-only colorschemes work transparently in terminal vim

vcscommand

Version Control System like mercurial integration for vim.
vcscommand

pydoc

~/.vim/ftplugin/python/pydoc.vim (don't use any more)
pydoc.vim : Python documentation view- and search-tool (uses pydoc)

vim & python

Python and vim: Make your own IDE
Python Doc

Debian packages

vim

This package contains a vim version compiled with a rather standard set of features. This package does not provide a GUI version and has no support for common languages like Lua, Perl or Python.

vim-nox

This package provides a vim version which is compiled with Lua, Perl, Python, Ruby and Tcl support but without a GUI

# apt-get install vim-nox

vim-gtk

Same as vim-nox but with GTK2 GUI (gvim)

Note: Using vim-gtk causes problems with redrawing while scrolling up. Don't know why... Use vim-gnome instead.

# apt-get install vim-gtk

vim-gnome

Same as vim-nox but with GNOME2 GUI (gvim)

# apt-get install vim-gnome
Last modified 4 months ago Last modified on Mar 15, 2019, 4:58:20 PM