Skip to content

plugins

register

You can list all previous copy-paste buffers quite easily :

copy-paste register
:reg

It will display the last 20 buffer contents you use plus a buffer name like "2 or "z. You use that name to paste that buffer again:

paste buffer
"2p

And there is your forgotten text again. You will be happy to see the register stays intact after closing the edited file.

todo list

This one seems to be simple enough :

visit

Install with :

vim todo lists
1
2
3
cd ~/.vim/bundle
git clone https://github.com/aserebryakov/vim-todo-lists.git
cp -r vim-todo-lists/plugin ~/.vim/

If you empty the .vimrc file you can use this command.

~/.vimrc
:VimTodoListsSetItemMode

This shows that the function works. Actually you could set this as default because we usually are always editing

Note that you will get in trouble when enabling these lines :

leave intact
filetype plugin indent on    " required
set paste

The creation of new items will fail when hitting if these are on. Now i can't remember why they were on in the first place but i DO know that set paste was there to counteract against a nasty indentation behaviour of the ident plugin.

I think this has to do with vundle, but we might get along fine without vundle ?

ctags for vim

The CTRL-5 (CTRL-]) option jumps to a tag under the cursor, and the dot '.' is not part of a keyword in the default setup. You steer this with the iskeyword setting , default is :

ctags
iskeyword=@,48-57,_,192-255

Which is ok for c, but add this to ~/.vimrc for java development

ctags
set iskeyword=@,48-57,_,192-255,.

Now you can push CTRL-] anywhere on 'XMap.getDistance' and you will go to the correct member.

bad indentation

Especially when using the yaml indentation it goes horribly wrong. After a section like this, you might want to start a new object in the first column :

indent
1
2
3
4
5
6
- name: Restart service mysql
  service:
    name: mysql
    state: restarted

[visit](cursor)

But yaml indentation decides it will be :

yaml
1
2
3
4
5
6
- name: Restart service mysql
  service:
    name: mysql
    state: restarted

    [visit](cursor)

This will start to annoy the hell out of you, and what will annoy you more is the amount of non-working advise you get for disabling it. Finally i got it working by disabling this setting in ~/.vimrc : For the vundle plugins section, you had to disable these and this line re-enabled them again afterwards :

restore indent
"filetype plugin indent on    " required

But this also seems to disable syntax coloring, because you should not read this as "set the plugin indent on" but as "set both plugin and indent on". This would be the equivalent :

same as
filetype plugin on
filetype indent on

So we only want to re-enable plugin :

only re-enable plugin
filetype plugin on

per directory .vimrc

Main use : to have the correct makeprg in for instance java/Scons and makefile projects. Use this in the $HOME/.vimrc file :

local .vimrc file
1
2
3
if filereadable(".vim.custom")
    so .vim.custom
endif

I put it in the end so it overwrites the other settings. Now if you include a file called .vim.custom in the directory of choice with for instance :

makeprg
set makeprg=make

That will be taken instead of the default scons.

tabs

I always use

tabstop
set tabstop=4

To get a 4 space indentation in my programs. However, since using python it is not well mannered to use tabs as indentation, so to make these tabs 'soft-tabs' you can also add this to .vimrc :

make space tabs
set expandtab

When you encounter older files still containing tabs you can search and replace them, or use :

do the whole file
:retab

I ended up not using expandtab because you can't backup a complete tab with the backspace. I just use :retab some more when doing python.

vundle

Bundle for vim, you can easily install plugins in vim once this plugin is installed.

install
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
sudo pip install https://github.com/Rykka/instant-rst.py/archive/master.zip

This will put everything in the right place, now add this to your .vimrc :

~/.vimrc
set nocompatible

filetype off                  " required

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
"
"Bundle 'Rykka/riv.vim'
Bundle 'Rykka/InstantRst'
" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'

call vundle#end()            " required

filetype plugin indent on    " required

It contains a plugin that is very handy for editing restructured text. And one commented out because i don't particularly found that very useful.

Riv knows RST format inside vim but the folding end general usage is not of much benefit. The second plugin however : instantrst is very useful and described in the next section.

If you open up vim with this .vimrc and type :

install plugins
1
2
3
:PluginInstall

It will install the Bundles you added, to remove one (like riv) you comment it out and run :
clean plugins
:PluginClean

Now you have a new plugin called InstantRst.

Instant rst

This plugin shows the result from you RST file inside your browser, usually at port :5676.

visit

It opens up automatically if you enter the vim command below and you can see all editing while you type.

run instantRst server
" in vim type
:InstantRst

Troubleshooting

When command above does not work, there is not much info you get about it. But you can run the command standalone to see what the output is :

instantRst
instantRst
error
1
2
3
4
File "/usr/local/bin/instantRst", line 84
   print 'nSome error/exception occurred.'
                                      ^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(int 'nSome error/exception occurred.')?

It shows you what is wrong (python 3 not supported) and where to fix it. Edit the script and change the shebang in python2. If you run it again it will start with an empty browser window.

spelling

Automatic spelling control is an option in vim that can be very useful. Also i used to run spelling checks in sphinx-doc on a regular base, but this is a very time consuming task, especially looking up the problems and rerunning.

So direct checks are very useful:

How spelling check in vim works is that you set these values in your .vimrc (or better .vim.custom file in the top directory of your sphinx-doc project. The directory where you start vim from normally.

spelling check
1
2
3
4
5
“ optional
“set makeprg="make spelling"
set spell spelllang=en_us
set bg=dark
set spellfile=kees.add

The bg=dark because of the highlighting that vim uses. Spellfile has to end in .add and will be created in the current directory alongside a binary version kees.add.spl . This file is probably a search index, so the main file can remain in the order created.

Now you can walk through all spelling errors with [s and ]s but beware you need to release the [ or ] key every time otherwise it just starts command 's' (change under cursor)

  • [s : find previous spelling error
  • ]s : find next spelling error
  • zg: adds the word under the cursor to the .add file and index
  • z=: prints a suggestion list to pick from

The errors are displayed with different colors :

Green background : spelling error, not found in dictionary or .add file Purple background : word is found bu should have a capital letter

The .add file will not be read by make spelling in sphinx-doc unless of course you add it to the source/spelling_wordlist.txt. Some experiments :

  • setting spellfile=source/spelling_wordlist.lst does not work since it has to end in add
  • setting spelling_word_list_filename='../kees.add' does work
  • using spelling_wordlist.add does not work because of the underscore. It will complain with 'does not have a region name'
  • Adding two lists together does work, and you will see that the index get's regenerated the first time you add a word (with zg) because all previously added errors will clear !
  • If you just add two files it will contain double entries
  • If you add a word again, it will just become multiple entries.

So based on that i would suggest this scheme for sphinx-doc projects :

  • Alter the entry in sources/conf into spelling.add
  • combine both files if needed by just concatenating
  • regularly remove doubles with sort -uo sources/spelling.add sources/spelling.add

This last command will do it 'in-place', trying sort x will truncate your file !!

Using this scheme does not take into account the per-file spelling list, try avoiding that or live with it.

ctrl-6 not working

This seems to be the default in newer installations. Ctrl-^ switches between files and not ctrl-6. But that means always pressing ctrl-shift-6 and that's horrible. Since ctrl-6 does nothing by default i just remap it in ~/.vimrc :

ctrl-6
noremap [visit](C-6) [visit](C-^)