Supress some warning in vim

Maybe you know that vim parses the output from the compiler so it can jump to the right line which cause the error(:h quickfix for more info). Well it seems that the default compiler options parse even warning which are sometimes pretty annoying. There were some warning for depracated conversion from the compiler because of xmp files. Well i am sure that i don’t want to see those. So here is what i have in my ~/.vim/ftplugin/cpp.vim for some time:

let &errorformat = "%-G%f\:%l\:\ warning\:\ deprecated\ conversion\ from\ string%.%#\,".&errorformat

I know that maybe this only works for gcc, but it is a start. You can get more info about the erroformat with :h errorformat in vim. Happy vimming :)

Problem with file endings

Today I had the same problem with mixed file endings. It seems that many editors are still dealing bad with that on different platforms, so you get different line endings. This times instead of manually dealing with the problem I googled and it seems that there is a nice workaround, you just need to type

:%s/\r//

and you are done. This will take care of you, I also have ff=unix in most of my files and in my vimrc.

NERDTree

Hmm today i finally found a nice TreeExplorer for vim. I was looking for something like this for so long.

    • It had to be plugable to the UI and not clutter it

 

  • It had to list the files in a directories of my project

 

 

  • I wanted to be able to open the files from there to the right side of the window as antoher buffer/tab

 

 

There are many plugins out there that solve some of the problems/requirements in the list, but they were not complete. I have tried project(this one was good), the built in explorer, some other explorers, which names i cannot remember :D .

Enter NERDTree. That is one of the plugins that saves your day. I just put

map <F6> :NERDTreeToggle

in my vimrc and now when i hit F6 i have a list of the files in my home directory. I go to that window with either the mouse or <C-W> w and now i can use the neat features of the plugin.

? - get helpC - make the directory your ROOTo - open/close the directory(this shows the files also in the     directory as a list

When you finish don’t forget to hit F6 again :D

Nice way to keep the lines indented in vim

Here is one more vim tipp. I just put a new keybinding to my .vimrc file, thanks to \amethyst from #vim@freenode.net :) . Here it is

inoremap <expr> <CR> (col("$")==col(".") ? "\<ESC>=a{\<C-O>o" : "\<CR>")

This will indent the whole block before the line if you hit <CR> on the end of the code you are writing in insert mode. If you are not at the end of the line you will get the default behaviour of <CR>. I was not sure how to implement that, but \amethyst really helped me on IRC. Once more this shows the power of chatting with experienced people who know the project very well. Viva open source :) .

Highlight for Qt classes in vim

Maybe some of you like me like to use a sophisticated library for C++ development. My choice is Qt. I really like to have highlighting for most of the classes so here is my ~/.vim/syntax/cpp.vim. This will highlight all of the Qt classes as built in structures of the language, which is really nice. I just copied all of the classes from the Qt’s web site ;) .

UPDATE:
Today Vidas Katinas send me the modified version so i have updated the link. I have also added a checking for a variable. I am also using stl lately so here is the installation guide if you use them both:

mkdir -p ~/.vim/after/syntax/cpp
wget -c http://nikolavp.googlepages.com/cpp.vim -O ~/.vim/after/syntax/cpp/qt.vim
wget -c http://www.vim.org/scripts/download_script.php?src_id=8628 -O ~/.vim/after/syntax/cpp/stl.vim

Now if you want to disable the Qt highlighting just put that somewhere in your vimrc file

let g:qt_syntax=0

If for example you want to disable the syntax for the current file(it is too slow ot whatever) type this

:let g:qt_syntax=0:e

and

:e!

if you have made changes.

Making abbreviations persistent in vim

If you are like me, most of the time you make more mistakes in vim, because your mind is little slower than you fingers. Enter abbreviations which is a really neat feature in vim :) . You just have to type

:iabbrev wrongstring wantedstring

in command mode and the next time you type the word wrong vim will fix it. So where is the problem? The problem is that when you type that in command mode it is not persistent between sessions. I really wanted to save those save somehow in a file. So here is the solution :)

function! Abbreviate(input, output) python << EOFdef appendAbb():    import os    import vim    home = os.getenv("USERPROFILE") or os.getenv("HOME")    home += "/myvimfiles/abbs.vim"    Abbs = open(home, "a")    inputstr = vim.eval("a:input")    outputstr = vim.eval("a:output")    abbreviation = "iabbrev " + str(inputstr) + " " + str(outputstr)+ "\n"    Abbs.write(abbreviation)EOF:py appendAbb()let abbrevation = "iabbrev ". expand(a:input). " ". expand(a:output)execute abbrevationendfunctioncommand! -nargs=+ Abb :call Abbreviate(<f-args>)

Put that in your ~/.vimrc file and you are done :) . You should change /myvimfiles/abbs.vim to the file with abbreviations you would like to use. If it is in a special directory not in your runtimepath you should also put source “path/to/the/file” in vimrc :) . Now next time you want to correct a type just type

:Abb wrongstring correctstring

and that’s all ;)
Happy vimming

Renaming a variable in gvim

Some of you may be missing the nice IDE’s and their neat features when you are editing in gvim. I was myself a long time Eclipse user, but I found that it doesn’t make me more productive, but just eat the resources of my machine. I missed the renaming variable feature in gvim for some time now. Today this is over I was reading the manual of vim and found what I was looking for. We all know the substitute command, but I was not sure how to replace the variable with one command for all files in the project. So here is what I have now in my .vimrc:

fun! BuffersRenameVar(cword, newvar)        let word = a:cword        let newvar = a:newvar        let replace = ":bufdo %s/\\\

You just hit \brn for buffer rename and have to change the “nvname”
with the new name of the variable and that’s all :) . This will ask you
to rename every appearance of the variable in all open buffers. Don’t
forget to open all all your files in vim. This will also put a global
mark named “R” so you can continue your work. Happy vimming