Thursday, June 13, 2013

VIM Tips


Tips:
-plugins
matchit.vim
zenburn color scheme

-filetype detection for verilog and systemverilog
download systemverilog.vim plugin


-profile vim load time, for debugging slowness opening file
    Profiling Vim
- map CapsLock key to Contrl, and use "ctrl+[" for escaping
-vimdiff:
    vim -d file1 file2
    :diffthis
    :diffoff
    do #diff obtain from the other file
    dp #diff put current code to the other file
Plugin:

- File Finder: MRU.vim, and ctrlp.vim

- Colorschem: Zenburn.vim (by the way, zenburn your gnome terminal: http://ubuntuforums.org/showthread.php?t=1091337 however, you need to change the pallete to this value: #3F3F3F3F3F3F:#CCCC93939393:#7F7F9F9F7F7F:#E3E3CECEABAB:#DFDFAFAF8F8F:#CCCC93939393:#8C8CD0D0D3D3:#DCDCDCDCCCCC:#3F3F3F3F3F3F:#CCCC93939393:#7F7F9F9F7F7F:#E3E3CECEABAB:#DFDFAFAF8F8F:#CCCC93939393:#8C8CD0D0D3D3:#DCDCDCDCCCCC)

- Matchit.vim: need to set for non standard filetypes like systemverilog, see My VIM Settings.
UPDATE: this is a great plug-in for finding a file if you know part of its names. however, since then, i have replaced it with ctags which removs the need to find a file. You should try catags too.

show invisible characters:
http://vimcasts.org/episodes/show-invisibles/

-Backspace does not delete to the left, delete forward. vim key mapping issues. fix in .vimrc with mapping.
backspace deletes characters forward like the delete key in vim when using term=xterm #641

-increment/decrement numbers
  • Ctrl+a will increment the number under the cursor or the first occurrence of a number to the right of the cursor
  • Ctrl+x will decrement the number under the cursor or the first occurrence of a number to the right of the cursor

You can also provide a count prefix:

  • 3 followed by Ctrl+a will add 3
  • 1000 followed by Ctrl+x will subtract 1000

-substitute within visual selection
    do visual selection, then substitute with command :%s/\%VPATTERN/REPLACEPATTERN/g
    NOTE: this works for block selection too!

-some filetype plugins can overwrite some vim settings, as these are loaded last, so setting it in vimrc wont work. and as these may be system level plugin and you may not have permission to modify. to workaround this, you can have an appropriate autocommand in your vimrc. 
    au   FileType systemverilog  set textwidth=0

My VIM Settings


" no need to be compatible with vi!
set nocompatible

" tab settings
set tabstop=4
set shiftwidth=4
set softtabstop=4
set expandtab

" more convenient settings
set encoding=utf-8

set scrolloff=3
set autoindent
set smartindent
set cindent
set showmode
set showcmd
set hidden
set wildmenu
set wildmode=list:longest
set visualbell
set cursorline
set ttyfast
set ruler
set backspace=indent,eol,start
set laststatus=2

" set searching and moving
" if search all-lower or all-upper case word, it will be case-sensitive
" else it will be case insensitive
set ignorecase
set smartcase

set gdefault

" highlight search results
set incsearch
set showmatch
set hlsearch
set incsearch

"set split open position
set splitright
set splitbelow

" to show invisible characters
set list
set listchars=tab:▸\ ,eol:¬

"Invisible character colors
highlight NonText guifg=#4a4a59
highlight SpecialKey guifg=#4a4a59

" save on losing focus
" au FocusLost * :wa

" set font
if has('gui_running')
set guifont=DejaVu\ Sans\ Mono\ 16
endif

" set working directory the same as the file you are editing.
set autochdir

" map K to split lines, the opposite of J
nmap K i<cr><esc>k$

" let ; equal to :
nnoremap ; :

" remap <ESC> to jj
inoremap jj <ESC>
"set terminal mode change to normal mode
tnoremap jj <C-W>N


" use tab key to match brackets pairs instead of %
nmap <tab> %
vmap <tab> %

" Press space to clear search highlighting and any message
" already displayed.
nnoremap <silent> <Space> :silent noh<Bar>echo<CR>


" set the default encoding to utf-8
set encoding=utf-8

set showmode
set autowrite

set ls=2

"syntax highlight
syntax on
"show matching bracket with blinking
set showmatch
set matchtime=3

"set now autowrap
set textwidth=0
set wrapmargin=0

"visualize command
set showcmd

"change leader key
let mapleader = " "

"map terminal
nnoremap <Leader>t  :term<CR>
nnoremap <Leader>t  :vert term<CR>




"turn off backup
set nobackup
set noswapfile

colorscheme zenburn
let g:zenburn_high_Contrast=1
set background=dark

"for matchit.vim settings, import for SV and verilog files

"enable filetype detect
filetype plugin on
"source ~/.vim/plugin/matchit.vim
au Filetype systemverilog
\let b:match_words=
\ '\<begin\>:\<end\>,' .
\ '\<if\>:\<else\>,' .
\ '\<module\>:\<endmodule\>,' .
\ '\<class\>:\<endclass\>,' .
\ '\<program\>:\<endprogram\>,' .
\ '\<clocking\>:\<endclocking\>,' .
\ '\<property\>:\<endproperty\>,' .
\ '\<sequence\>:\<endsequence\>,' .
\ '\<package\>:\<endpackage\>,' .
\ '\<covergroup\>:\<endgroup\>,' .
\ '\<primitive\>:\<endprimitive\>,' .
\ '\<specify\>:\<endspecify\>,' .
\ '\<generate\>:\<endgenerate\>,' .
\ '\<interface\>:\<endinterface\>,' .
\ '\<function\>:\<endfunction\>,' .
\ '\<task\>:\<endtask\>,' .
\ '\<case\>\|\<casex\>\|\<casez\>:\<endcase\>,' .
\ '\<fork\>:\<join\>\|\<join_any\>\|\<join_none\>,' .
\ '`ifdef\>:`else\>:`endif\>,'

"set ctags files
"set tags=./tags
"set tags+=~/.vim/tags/UVM/tags
"set tags+=$WS_DV_HOME/tags

"for ctags
nnoremap    <M-[>    <C-T>
nnoremap    <M-]>    g<C-]>

"remap the window switching, and with window effect
map <C-j> <C-w>j
map <C-k> <C-w>k
map <C-h> <C-w>h
map <C-l> <C-w>l

"show line numbers and behaviors
set number
autocmd InsertEnter * :set norelativenumber
autocmd InsertLeave * :set relativenumber

"let vimdiff ignore white space
set diffopt+=iwhite

C Programming

Header Files and Includes https://cplusplus.com/forum/articles/10627/ https://stackoverflow.com/questions/2762568/c-c-include-header-file-or...