VIM with GIT

 VIM  Comments Off on VIM with GIT
Jun 032012
 

As the source control system I use daily at work and in most of my home projects is GIT, and my favorite editor is VIM it was not far fetched that I wanted a easy way to use GIT from within VIM. After doing some searching and reading, I found this http://www.osnews.com/story/21556/Using_Git_with_Vim, which in turn points to https://github.com/amjith/git-vim.

Here is the information from the readme.rdoc file,

Commands

:GitAdd <file>
git-add <file> or current file if not specified.
:GitCommit <args>
git-commit.
:GitStatus
Show git-status of current file or repository.
:GitLog
Show git-log of current file or repository.
:GitCheckout <args>
git-checkout. Completes git commits.
:GitDiff <args>
git-diff. Completes git commits.
:GitPull <args>
git-pull.
:GitPullRebase
git-pull –rebase.
:GitPush <args>
git-push. Defaults to +git push origin <current-branch>+.
:GitCatFile <args>
git-cat-file.
:Git <args>
Does any git command.
:GitVimDiffMerge
Experimental. Call this command on unmerged file to enter vimdiff mode.
:GitVimDiffMergeDone
Call this command after merging.

 

Keymaps

<Leader>gd
:GitDiff
<Leader>gD
:GitDiff –cached
<Leader>gs
:GitStatus
<Leader>gl
:GitLog
<Leader>ga
:GitAdd
<Leader>gA
:GitAdd <cfile>
<Leader>gc
:GitCommit

 

In git-status buffer

<Enter>
:GitAdd <cfile>

VIM – revisited

 VIM  Comments Off on VIM – revisited
Mar 112012
 

Made some refactoring of my VIM settings the other day.

The current plugins used are:

  • colorsamplepack
  • cscope_maps
  • highlight_current_line
  • matchit
  • NERD_tree
  • SearchComplete
  • taglist

This is the current settings file, or .vimrc as it's called.

" Joakim Wesslen
"
" The inspiration for the below setup was found at these places
" http://www.derekwyatt.org/vim/
" http://www.swaroopch.com/notes/Vim_en:Programmers_Editor
" http://spf13.com/post/perfect-vimrc-vim-config-file
" http://www.catonmat.net/blog/vim-plugins-surround-vim/
" among others...
"
set nocompatible " not compatible with original vi
let mapleader="," " set mapleader to , instead of \
nmap <silent> <leader>ev :e $MYVIMRC<CR> " edit .vimrc
nmap <silent> <leader>sv :so $MYVIMRC<CR> " source .vimrc
" Status bar --------------------------------------------------------------
set ch=2 " Make command line two lines high
set showmode " show current mode in status bar
set stl=%f\ %m\ %r\ Line:\ %l/%L[%p%%]\ Col:\ %c\ Buf:\ #%n\ [%b][0x%B] " Set the status line the way I like it
set laststatus=2 " Show statusline in single window
" Color, layout etc  ------------------------------------------------------
set background=dark " background color
colorscheme darkgreen " color scheme
syntax on " Enable syntax highlightning
set tw=120 " text width
set cc=+1 " highlight column after textwidth
set nowrap " wrap text
"set smarttab " tab/backspace are smart
"set expandtab " insert spaces as tabs
set tabstop=8 " Tab length, nbr spaces
set cindent " indent according to tabstop
set smartindent " help me with indenting
set autoindent " autoindent
set sw=2 " scrollbar width
set number " show line numbers
set autoread " watch for file changes
set undolevels=1000 " nbr undo levels
set history=1000 " command history levels
set list " Show trailing spaces and tabs
set listchars=trail:+,tab:>- " Show trailing spaces and tabs
set foldminlines=5 " Folding lines shown
set foldnestmax=3 " Folding level
" Search ------------------------------------------------------------------
set ignorecase " ignore case in pattern
set smartcase " override ignorecase
set incsearch " show pattern in text as it is written
set hlsearch " highlight all matches
set wrapscan " Set the search scan to wrap around the file
set path+=** " search directories
" Copy --------------------------------------------------------------------
set cpoptions+=$ " add a $ at end of 'copy/change'
" Buffer ------------------------------------------------------------------
set hidden " change buffer without saving
noremap <C-Left> :bfirst<cr> " Switch to first buffer
noremap <C-Down> :bnext<cr> " Switch to next buffer
noremap <C-Up> :bprevious<cr> " Switch to previous buffer
noremap <C-Right> :blast<cr> " Switch to last buffer
" Windows -----------------------------------------------------------------
noremap <silent> <C-h> :wincmd h<cr> " Move the cursor to the window left of the current one
noremap <silent> <C-j> :wincmd j<cr> " Move the cursor to the window below the current one
noremap <silent> <C-k> :wincmd k<cr> " Move the cursor to the window above the current one
noremap <silent> <C-l> :wincmd l<cr> " Move the cursor to the window right of the current one
" Specials ----------------------------------------------------------------
map <C-s> :w<CR> " 'Ctrl s' to save file in command mode.
imap <C-s> <Esc>:w<CR>i " 'Ctrl s' to save file in insert mode.
" Plugins -----------------------------------------------------------------
:filetype plugin on "
" Function keys -----------------------------------------------------------------
map <F2> :TlistToggle<cr> " Taglist, need ctags
map <F3> :NERDTreeToggle<cr> " NERDtree
"map <F4> <cr> " Buflist (buflist.vim defines F4 as toggle window
map <F5> :b#<cr> " switch buffer
" file type detection
:filetype on "
autocmd FileType make set noexpandtab set sw=4
autocmd FileType c set tw=80
autocmd FileType h set tw=80
autocmd FileType patch set tw=80

 

The Beginning

 VIM  Comments Off on The Beginning
Jan 122012
 

The very first blog entry!
What should it be about?
Linux, device drivers, Lego Mindstorms NXT, Arduino, Raspberry Pi, or ...?
No!
Let's start with the tool I use daily, both at work and at home.

That would be VIM (VI iMproved).

My first encounter with Vim was when a collegue showed it, and then sent me this link.
http://www.derekwyatt.org/vim/vim-tutorial-videos/
It has been a real kick-starter for me in the introduction to Vim.

To be honest it was not easy in the beginning, but after using it constantly for several months, I would not like to switch it for any other editor.

Anyhow, here is my .vimrc, which I use both at work and at home.

"
" not compatible with original vi
set nocompatible
" Status bar --------------------------------------------------------------
" Make command line two lines high
set ch=2
" show current mode in status bar
set showmode
" Set the status line the way I like it
set stl=%f\ %m\ %r\ Line:\ %l/%L[%p%%]\ Col:\ %c\ Buf:\ #%n\ [%b][0x%B]
"set stl=%f\ %m\ %r\ Line:\ %l/%L[%p%%]\ Col:\ %c\ Buf:\ #%n\
" Show statusline in single window
set laststatus=2
" Color, layout etc  ------------------------------------------------------
" background color
set background=dark
" color scheme
colorscheme darkgreen
" Enable syntax highlightning
syntax on
" text width
set tw=120
" highlight column after textwidth
set cc=+1
" wrap text
set nowrap
" tab/backspace are smart
" set smarttab
" Tab length, nbr spaces
set tabstop=8
" indent according to tabstop
set cindent
" help me with indenting
set smartindent
" autoindent
set autoindent
" scrollbar width
set sw=2
" show line numbers
set number
" watch for file changes
set autoread
" nbr undo levels
set undolevels=1000
" Show trailing spaces and tabs
set list
set listchars=trail:+,tab:>-
" Folding
"set foldmethod=syntax
" Folding lines shown
set foldminlines=5
" Folding level
set foldnestmax=3
" Search ------------------------------------------------------------------
" ignore case in pattern
set ignorecase
" override ignorecase
set smartcase
" show pattern in text as it is written
set incsearch
" highlight all matches
set hlsearch
" Set the search scan to wrap around the file
set wrapscan
" search directories
set path+=**
" Copy --------------------------------------------------------------------
" add a $ at end of 'copy/change'
set cpoptions+=$
" Buffer ------------------------------------------------------------------
" change buffer without saving
set hidden
" Switch to first buffer
noremap  :bfirst
" Switch to next buffer
noremap  :bnext
" Switch to previous buffer
noremap  :bprevious
" Switch to last buffer
noremap  :blast
" Windows -----------------------------------------------------------------
" Move the cursor to the window left of the current one
noremap   :wincmd h
" Move the cursor to the window below the current one
noremap   :wincmd j
" Move the cursor to the window above the current one
noremap   :wincmd k
" Move the cursor to the window right of the current one
noremap   :wincmd l
" Cscope----------------------------------------------------------------
if has("cscope")
	set csprg=/usr/bin/cscope
	set csto=0
	set cst
	set nocsverb
	" add any database in current directory
	if filereadable("cscope.out")
	    cs add cscope.out
	" else add database pointed to by environment
	elseif $CSCOPE_DB != ""
	    cs add $CSCOPE_DB
	endif
	set csverb

	map g :cs find c =expand("")
	map g :cs find s =expand("")
endif
" Specials ----------------------------------------------------------------
" 'Ctrl s' to save file in both command and insert mode.
map  :w
imap  :wi
" Plugins -----------------------------------------------------------------
:filetype plugin on
" Taglist, need ctags
map  :TlistToggle
" NERDtree
map  :NERDTreeToggle
" Buflist (buflist.vim defines F4 as toggle window
"map  
" CScope. Find this definition - :cs f g
map  :cs f g =expand("")
" CScope. Find functions called by this function - :cs f d
map  :cs f d =expand("")
" CScope.  Find functions calling this function - :cs f c
map  :cs f c =expand("")
" CScope.  Find symbol - :cs f s
map  :cs f s =expand("")
" Search for this word in this file
map  :/=expand("")
" Remove MS-DOS carriage returns
"map  :1,$s/
//
" Cscope
" Matchit
" ColorSamplePack
" SearchComplete
" VcsCommand
" Folding
" Filetype specifics ------------------------------------------------------
" file type detection
:filetype on
"
autocmd FileType make set noexpandtab sw=4
autocmd FileType c set tw=80
autocmd FileType h set tw=80
" Text width --------------------------------------------------------------
"autocmd BufEnter *.c,*.h let w:m1=matchadd('Search', '/\%<81v.\%77v', -1)
"autocmd BufEnter *.c,*.h let w:m2=matchadd('ErrorMsg', '/\%>80v.\+', -1)