Useful tips for vim

3 minute read

In vim, you can use more powerful functions than vi. It’s easy to specify a region for copying and divide windows. It is convenient to use comparative utilities such as vimdiff. You can also use powerful features while adjusting various options in vimrc.

vim

view manual page : K(Shift+k)
show editing file list
    :args
block
    v+j for blocking (y for yank)
Edit column(Add/delete columns) : Ctrl+v 
    I, A : Insert
    y : Yank
    p : Paste
* (Shift+8) : Start a new search
Divide windows
    :sp . (:split)
    :vsp . (:vsplit)
    Ctrl+W+W : move window
Move file
    :bn : next file
    :bp : previous file
    :bd : close file

vimdiff

Ctrl+W+W : Move window
z + r : expand
diffthis : show difference

ctags

Ctrl + ] : Move to the definition
Ctrl + t : Move to the previous point

:tselect <function-name> : When there are multiple functions of the same name, it shows a list (:ts)

:tnext      : select next function
:tprevious  : select previous function
:tfirst     : select first function
:tlast      : select last function

:%!xxd      : show by HEX
:%!xxd -r   : hide HEX

:%s/^A/^M/g
---> Ctrl + v + a for ^A

$HOME/.vimrc

set tags+=$HOME/src/tags

"map <A-]> :vsp<CR>:exec("tag ".expand("<cword>"))<CR>
" <F2> folding <F3> unfolding <F4> all unfolding

map <F2> v]}zf
map <F3> zo
map <F4> zR

" <F5> paste mode, <F6> autoindenting mode
map <F5> <ESC>:set paste<CR>
map <F6> <ESC>:set nopaste<CR>

" <F7> hex mode, <F8> ascii mode
map <F7> <ESC>:%!xxd<CR>
map <F8> <ESC>:%!xxd -r<CR>

" <F9> insert, <F10> delete
map <F9> :norm i//<CR>
map <F10> :norm xx<CR>
"map <F9> :s/^/\/\//<CR>
"map <F10> :s/^\/\///<CR>

map <F11> :set tenc=korea<CR>:set enc=utf-8<CR>
map <F12> :set enc=euc-kr<CR>

nnoremap <F2> :set invpaste paste?<CR>
set pastetoggle=<F2>
nnoremap <F3> :noh<CR><CR>
nnoremap <F5> :set spell!<CR>

"map <C-J> <C-w>j<C-w>_
"map <C-K> <C-w>k<C-w>_
"map <C-H> <C-w>h<C-w>\|
"map <C-L> <C-w>l<C-w>\|
map <A-J> <C-w>j
map <A-K> <C-w>k
map <A-H> <C-w>h
map <A-L> <C-w>l

if v:version >= 703     " higher vim 7.3
    set colorcolumn=80
endif

if has("syntax")
    syntax on           " syntax highlighing
endif

filetype plugin indent on

"set t_Co=256
"colorscheme busybee2
colorscheme codedark

set expandtab           " tab to space
set tabstop=4           " numbers of spaces of tab character (alias ts)
set shiftwidth=4        " numbers of spaces to (auto)indent

set ai                  " set autoindent(ai) always set autoindenting on
"set paste              " off autoindenting when paste
"
set cindent             " cindent
set smartindent         " smart indent

"set fencs=ucs-bom,utf-8,euc-kr.latin1

set showmode            " display mode
set showcmd             " display incomplete commands
set sm                  " show matching braces, somewhat annoying...

set nowrap
set nocompatible        " use vim defaults (alias nocp)
set backspace=2         " make backspace like most other apps
set scrolloff=4         " keep 3 lines when scrolling

set hlsearch            " highlight searches
set incsearch           " do incremental searching
"set ignorecase         " ignore case when searching (alias ic)
set smartcase           " case when searching

"set ruler              " show the cursor position all the time
set noruler             " disable show the cursor position all the time
set number              " show line numbers
set numberwidth=5       " line numbers width
"set title              " show title in console title bar
set ttyfast             " Improves smoothness of redrawing
set modeline            " last lines in document sets vim mode
set modelines=3         " number lines checked for modelines
set shortmess=atI       " Abbreviate messages
set nostartofline       " don't jump to first character when paging
set whichwrap=b,s,h,l,<,>,[,] " move freely between files


" Status Line Setting
hi User1 guifg=#eeeeee guibg=#585858 ctermfg=255 ctermbg=240
hi User2 guifg=#262626 guibg=#ffff87 ctermfg=235 ctermbg=228
hi User3 guifg=#eeeeee guibg=#875fd7 ctermfg=255 ctermbg=98
hi User4 guifg=#121212 guibg=#afff87 ctermfg=233 ctermbg=156
hi User5 guifg=#005f00 guibg=#87d787 ctermfg=22  ctermbg=114
hi User6 guifg=#000000 guibg=#ff875f ctermfg=0   ctermbg=209
hi User7 guifg=#eeeeee guibg=#5fd700 ctermfg=255 ctermbg=67
hi User8 guifg=#eeeeee guibg=#585858 ctermfg=255 ctermbg=240
hi User9 guifg=#ffd7d7 guibg=#870000 ctermfg=224 ctermbg=88

set ls=2                                                "set laststatus(ls) allways show status line
set statusline=
set statusline+=%1*\[%n]                                "buffernr
set statusline+=%1*\ %<%F\                              "File+path
set statusline+=%1*\ %m\                                "modified flag
set statusline+=%=\                                     "align
set statusline+=%2*\ %y\                                "FileType
set statusline+=%2*\ %{''.(&fenc!=''?&fenc:&enc).''}    "Encoding
set statusline+=%2*\ %{(&bomb?\",BOM\":\"\")}\          "Encoding2
set statusline+=%2*\ %{&ff}\                            "FileFormat (dos/unix..)
set statusline+=%3*\ row:%l/%L\                         "Rownumber/total (%)
set statusline+=%3*\ col:%c\                            "Colnr
set statusline+=%4*\ %03b(0x%02B)                       "Oct, Hex


let g:indent_guides_enable_on_vim_startup=1
let g:indent_guides_guide_size=4
let g:indent_guides_auto_colors=0
autocmd VimEnter,Colorscheme * :hi IndentGuidesOdd  guibg=#3a3a3a ctermbg=237
autocmd VimEnter,Colorscheme * :hi IndentGuidesEven guibg=#444444 ctermbg=238

Tags:

Categories:

Updated:

Leave a comment