Skip to content
Damir Franusic edited this page Mar 5, 2017 · 2 revisions

1. install pathogen

2. install vim addons

$ cd ~/.vim/bundle
$ git clone https://github.com/jiangmiao/auto-pairs.git
$ git clone https://github.com/moll/vim-bbye.git
$ git clone https://github.com/ctrlpvim/ctrlp.vim.git
$ git clone https://github.com/scrooloose/nerdcommenter.git
$ git clone https://github.com/scrooloose/syntastic.git
$ git clone https://github.com/majutsushi/tagbar.git
$ git clone https://github.com/tomtom/tlib_vim.git
$ git clone https://github.com/SirVer/ultisnips.git
$ git clone https://github.com/mbbill/undotree.git
$ git clone https://github.com/MarcWeber/vim-addon-mw-utils.git
$ git clone https://github.com/vim-airline/vim-airline.git
$ git clone https://github.com/octol/vim-cpp-enhanced-highlight.git
$ git clone https://github.com/ludovicchabant/vim-gutentags.git
$ git clone https://github.com/honza/vim-snippets.git
$ git clone https://github.com/Valloric/YouCompleteMe.git
$ git clone https://github.com/morhetz/gruvbox.git

3. YouCompleteMe installation

4. .vimrc setup

"+-----------+
"| " general |
"+-----------+
set exrc
set secure
set t_Co:256
set tabstop=8
set softtabstop=4
set shiftwidth=4
set nocursorline
"set noexpandtab
set expandtab
set number
set nofoldenable
set nowrap
set viminfo^=%
set previewheight=20
syntax on
"set paste
highlight clear SignColumn
"set hidden (enable switching from changed buffer)
set hidden
runtime! ftplugin/man.vim
let g:netrw_liststyle=0
"pathogen
execute pathogen#infect()

"+---------+
"| windows |
"+---------+
function! WinMove(key)
  let t:curwin = winnr()
  exec "wincmd ".a:key
  if (t:curwin == winnr()) "we havent moved
    if (match(a:key,'[jk]')) "were we going up/down
      wincmd v
    else
      wincmd s
    endif
    exec "wincmd ".a:key
  endif
endfunction
map <leader>h :call WinMove('h')<cr>
map <leader>k :call WinMove('k')<cr>
map <leader>l :call WinMove('l')<cr>
map <leader>j :call WinMove('j')<cr>
map <leader>wc :wincmd q<cr>
map <leader>wr <C-W>r
nmap <leader><left>  :3wincmd <<cr>
nmap <leader><right> :3wincmd ><cr>
nmap <leader><up>    :3wincmd +<cr>
nmap <leader><down>  :3wincmd -<cr>


"+-----------+
"| shortcuts |
"+-----------+
" plugins
map <F9> :UndotreeToggle<CR>
map <F8> :TagbarToggle<CR>
" buffers
nnoremap <silent> <F12> :bnext<CR>
nnoremap <silent> <F11> :bprevious<CR>
nnoremap <F5> :CtrlPBuffer<CR>
nnoremap <Leader>q :Bdelete<CR>
" man
nnoremap K :Man <cword><CR>

"+---------+
"| airline |
"+---------+
set laststatus:2
set ttimeoutlen:50
set encoding:utf-8
"let g:airline#extensions#tabline#enabled = 1
"let g:airline#extensions#tabline#fnamemod = ':t'

"+-----------+
"| syntastic |
"+-----------+
let g:syntastic_cpp_remove_include_errors = 1
let g:syntastic_cpp_check_header = 0
let g:syntastic_cpp_auto_refresh_includes = 1
let g:syntastic_mode_map={"mode":"active", "active_filetypes": [], "passive_filetypes": ["c","cpp"]}
"+-------+
"| ctags |
"+-------+
set tags+=~/.vim/tags/stl_tags
set tags+=~/.vim/tags/boost_tags

"+-----------+
"| ultisnips |
"+-----------+
let g:UltiSnipsExpandTrigger="<c-j>"
let g:UltiSnipsJumpForwardTrigger="<c-j>"
let g:UltiSnipsJumpBackwardTrigger="<c-k>"

"+-----+
"| ycm |
"+-----+
let g:ycm_add_preview_to_completeopt = 1
let g:ycm_autoclose_preview_window_after_completion = 0
let g:ycm_autoclose_preview_window_after_insertion = 1
"let g:loaded_youcompleteme = 1
let g:ycm_register_as_syntastic_checker = 1
let g:ycm_collect_identifiers_from_tags_files = 0
let g:ycm_auto_trigger = 1
let g:ycm_warning_symbol = 'WW'
let g:ycm_error_symbol = 'EE'

"+---------+
"| "colors |
"+---------+
"let g:solarized_termtrans=1
"let g:solarized_termcolors=256
set background=dark
colorscheme gruvbox
highlight Normal ctermbg=None

5. vim keyboard shortcuts

+------------+
| Extensions |
+------------+
UndoTree                                                        - F9
TagBar                                                          - F8

+---------+
| Buffers |
+---------+
Buffer list                                                     - F5
Buffer next                                                     - F12
Buffer prev                                                     - F11
Close buffer                                                    - \q
New empty buffer                                                - :enew
New empty buffer (horiz split window)                           - :new
New empty buffer (vert split window)                            - :vnew

+---------+
| Windows |
+---------+
Window to the right (move to or create)                         - \l 
Window to the left (move to or create)                          - \h 
Window above (move to or create)                                - \k 
Window below (move to or create)                                - \j 
Window close                                                    - \wc
Window rotate                                                   - \wr
Window resize left                                              - \<left arrow>
Window resize right                                             - \<right arrow>
Window resize up                                                - \<up arrow>
Window resize down                                              - \<down arrow>


+-------+
| Ctags |
+-------+
Jump to definition                                              - <CTRL ]>
Jump back from definition                                       - <CTRL t>
See all definitions                                             - <g ]>
Preview definition                                              - <CTRL w ]>
Generate tags                                                   - <F4>


+-------------+
| Indentation |
+-------------+
Indent right                                                    - >>
Indent left                                                     - <<
Indent block right(cursor on one of curly braces)               - >%
Indent block left(cursor on one of curly braces)                - <%
Indent inner block right(cursor anywhere inside curly braces)   - >i{
Indent inner block left(cursor anywhere inside curly braces)    - <i{
Re-indent the 'inner block', i.e. the contents of the block     - =i{
Re-indent 'a block', i.e. block and containing braces           - =a{

+-------+
| Other |
+-------+
Clear highlighted                                               - :noh
Open man page                                                   - SHIFT k
Open file under cursor                                          - gf

+-----------+
| Ultisnips |
+-----------+
Complete trigger                                                - <CTRL j>
Complete jump forward                                           - <CTRL j>
Complete jump backward                                          - <CTRL k>


+--------+
| CTRL-P |
+--------+
Cycle between modes                                             - CTRL f


+----------+
| Comments |
+----------+
Comment line                                                    - \cc
Comment toggle                                                  - \c space
Uncomment                                                       - \cu

+---------------+
| Moving around |
+---------------+
Move to the end of a word                                       - e
Move forward to the beginning of a word                         - w
Move backward to the beginning of a word                        - b
Move to the beginning of the line                               - 0
Move to the end of the line                                     - $

Go to the first line of current screen                          - H
Go to the middle line of current screen                         - M
Go to the last line of current screen                           - L
Jump forward one full screen                                    - <CTRL f>
Jump backwards one full screen                                  - <CTRL b>
Jump forward (down) a half screen                               - <CTRL d>
Jump back (up) one half screen                                  - <CTRL u>

+---------------------------------------------+
| standard Vim shortcuts to take into account |
+---------------------------------------------+
    <c-]> : Jumps to the tag definition of the word under cursor updating tag stack.
    <c-w>} : Opens a preview window with the location of the tag definition. The cursor does not change its position, so tag stack is not updated.
    <c-w>z : Close preview window.
    <c-w>v : Split current window in two, keeping the cursor position.

So, you can use <c-w>}if you want to quickly check the tag declaration, followed by <c-w>z to close it. But if you want to navigate, then you can simply
use <c-w>v to create a split followed by the standard <c-] to navigate in the tags. When you're done with it, you can simply close the window with <c-w>c.

Clone this wiki locally