Showing posts with label vim. Show all posts
Showing posts with label vim. Show all posts

Thursday, October 11, 2007

VIM - omnicppcomplete

I had to put these in my ~/.vimrc to get omnicppcomplete to work
autocmd BufNewFile,BufRead,BufEnter *.cpp,*.hpp set omnifunc=omni#cpp#complete#Main

"ctags
map <C-F12> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR>

"omnicppcomplete
imap <C-Space> <C-x><C-o>
let OmniCpp_MayCompleteDot = 0
let OmniCpp_MayCompleteArrow = 0

VIM - NERDTree plugin

Good file explorer.

plugin: link

Add this to ~/.vimrc
"NERDTree Toggle
noremap <Leader>][ :NERDTreeToggle

Thursday, August 23, 2007

VIM - Search to end of word

This will leave your cursor at the end of the searched phrase:
/search phrase/e

Monday, August 13, 2007

VIM - format lines to certain width

First,
:set textwidth=80 (or :set tw=80)
Then,
gqqFormat a single line
{Visual}gqFormat visual selection. (ctrl+v to get to visual mode then use hjkl to navigate)

For more help,
:help gq

Wednesday, June 20, 2007

VIM - minibufexpl

Script: minibufexpl.vim
"MINIBUFEXPLORER Stuff (Enter "\mbe" minus quotes quickly to bring it up)
""Commands:
" Ctrl-PgDown - goto next buffer
" Ctrl-PgUp - goto prev buffer
" \-Backspace-= - toggle minibufexplorer
"let g:miniBufExplMaxSize = 3 "allow up to 3 lines of buffers
let g:miniBufExplModSelTarget=1
"map mbo :MiniBufExplorer
noremap :bn
inoremap :bn
cnoremap :bn
noremap :bp
inoremap :bp
cnoremap :bp
noremap = :TMiniBufExplorer
noremap u :UMiniBufExplorer

set hid "Hide abandoned buffers in order to not loose undo history

Thursday, June 7, 2007

VIM - Multiple highlighted searches

Script link
:Search <pattern1>
:Search <pattern2>
:SearchReset

Wednesday, May 9, 2007

VIM - Recursively set project path

Put this in your .vimrc
set path=$PWD/**

Wednesday, May 2, 2007

VIM - Using cscope

Install cscope.

At your project directory, to recursively build the database
cscope -Rb

Place cscope_maps.vim into ~/.vim/plugin.

CTRL+] to search for the word under the cursor.

See the cscope vim tutorial for more details.

VIM - Recursively set the path of the project

Put this in your .vimrc to
" Recursively set the path of the project
set path=$PWD/**

Wednesday, April 18, 2007

VIM - Shifting and code formatting

You can shift (indent) code right or left by typing >> or <<, respectively, with your cursor on the line you want to shift.

You can use VIM automatic formating by typing == on the line you want to format.

You can also set the amount of spaces to shift.

You can also shift and format in visual mode (To get into visual mode: SHIFT+V, then j and k to select rows) by selecting the lines you want, then typing >, <, or =.

VIM - Inserting spaces instead of tabs

Insert spaces instead of tabs

set expandtab or set et

Set the width of shifts to 4 for autoindenting and shifting: >> and <<

set shiftwidth=4 or set sw=4

Set where to stop tabs to 4

set tabstop=4 or set ts=4


This is what I have in my ~/.vimrc:

Set expanded tabs with shiftwidth=4 and tabstop=4 for Java, Perl, C, and C++ files

autocmd BufNewFile,BufRead *.java,*.pl,*.c,*.h,*.cc,*.cpp,*.hpp set sw=4 ts=4 et

Thursday, March 8, 2007

VIM - Doxygen Syntax Highlighting

To have vim highlight Doxygen comments, add this to your vimrc:
let g:load_doxygen_syntax=1

For more help, try
:help doxygen

Friday, February 23, 2007

VIM - Advanced Tips

Here are some advanced tips I've learned from coworkers and working with VIM:

CommandDescription
:%s *$==Delete end of line spaces
:'a,'bs/str1/str2/gReplace "str1" with "str2" from marker a to marker b
:%s/\(.*\):\(.*\)/\2:\1/gReplace the first field (\1) with the second field (\2) separated by the :
zfFold a selected block of code
zdUnfold a block of folded code
:makeRun Makefile
:w|makeWrite (save) current file and then run Makefile
:grep regexp filesFind regexp in files
:copenOpen quickfix list. Helpful after doing :make or :grep. Press Enter on entry in quickfix list to jump to that location
:ccloseClose quickfix list
:colderDisplay contents of previous quickfix list
:cnewerDisplay contents of next quickfix list
:!cmdRun cmd as if on command line. Example: :!ls
:bwClose current buffer
ctrl+oGo back once through visited lines
ctrl+iGo forward once through visited lines
:h topicGet help for topic