Millet Porridge

English version of https://corvo.myseu.cn

0%

My Vim Config

As a long-time fan of linux and vim, I feel like I’m being melted by the spirit of sharing. My .vim folder used to be a mess. When I first met vundle, I was resistant: I had worked so hard to get you-complete-me configured and didn’t want to lose my hard-won plugins to a package manager. But the appeal of linux is never chaos — it is clarity and order. I spent one morning wiring my .vim directory up with vundle package management. It really is a sexy tool: basically one command gets vim fully configured.

GITHUB

For the detailed configuration see corvofeng/MyVimConfig

The .vim directory structure

1
2
3
4
5
6
7
8
9
.
├── bundle/ # plugin folder
├── UltiSnips/ # my snippets folder
├── vrapperrc # .vrapperrc eclipse vrapperrc plugin config
├── vimrc # .vimrc
├── gvimrc # .gvimrc
├── ycm_extra_conf.py # YCM config file
└── vundlerc # Bundle plugin list
2 directories, 5 files

usage

I suggest symlinking specific files to your home directory, so editing one file stays in sync.

  1. First add .vimrc and friends:
1
2
3
ln -s ~/.vimrc ~/.vim/vimrc
ln -s ~/.gvimrc ~/.vim/gvimrc
ln -s ~/.vrapperrc ~/.vim/vrapperrc
  1. Open vim, enter command mode, and type BundleInstall to install everything automatically. I assume you already have basic vim skills.

vundlerc

See the vundlerc file. It is inevitably a bit messy — please bear with me. Many plugins I’ve only installed; I haven’t really used them deeply yet.

vimrc

Most lines in vimrc have comments; I’ll only paste the key DIY parts. I hope you get something out of it and can customize your own config — what suits you is the best.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
source ~/.vim/vundlerc          " first line of vim: read vundlerc

" normal files indent by 4 characters
set tabstop=4
set shiftwidth=4
set softtabstop=4
set expandtab

au Filetype c,cpp setl sw=8 sts=8 ts=8 et " C, C++: indent by 8 characters

set hlsearch " highlight searches
set incsearch " search as you type

" Turn off highlighting after a search — a problem that plagued me for a long time.
" Not being able to switch off the highlight is really painful.
map<F2> : noh <CR>

" Run with xterm so a window can pop up directly; press ESC or Enter to exit xterm.
" Many shortcuts call this function.
function! Xterm(cmd)
silent exec "!xterm -e '". a:cmd ." ; read" ."'"
endfunction

" Compile and run C, C++, sh, java with Shift+F10; calls Xterm
map <S-F10> :call CompileAndRun()<CR>
func! CompileAndRun()
exec "w"
if &filetype == 'c' "C and C++
call Xterm("gcc -g % -o %< && ./%<")
elseif &filetype == 'cpp'
call Xterm("g++ -g % -o %< && ./%<")
elseif &filetype == 'sh' "Shell Script
call Xterm("chmod u+x % && ./%")
elseif &filetype == 'java' "Java Source
call Xterm("javac % && java %<")
elseif &filetype == 'md' "For MarkDown
call Xterm("nemo .")
elseif &filetype == 'asm' "For asm
call Xterm("nasm % -o %<.bin")
elseif &filetype == 'python' "For Python(python3)
call Xterm("python %")
endif
endfunc

" Custom snippets can insert variables; change the user and project names as you like
let g:snips_author = "corvo"
let g:snips_projectname = "default"

" UltiSnips conflicts with YCM shortcuts; use Ctrl+j to expand snippets
let g:UltiSnipsExpandTrigger='<c-j>'
let g:UltiSnipsJumpForwardTrigger='<c-k>'
let g:UltiSnipsJumpBackwardTrigger='<c-s-k>'
let g:UltiSnipsSnippetsDir='~/.vim/UltiSnips'

" Tabular: a powerful alignment tool
let mapleader=','
if exists(":Tabularize")
nmap <Leader>a= :Tabularize /=<CR>
vmap <Leader>a= :Tabularize /=<CR>
nmap <Leader>a: :Tabularize /:\zs<CR>
vmap <Leader>a: :Tabularize /:\zs<CR>
endif

gvimrc

My gvim config defines some other options; many already have comments, so I won’t paste them all.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
set foldenable          " folding in gvim
set foldmethod=syntax

set lines=35 columns=90 " window size on startup

" Removing everything around the `gvim` window feels great. If it's unfamiliar at first,
" just add the scrollbars and toolbar back.
" disable scrollbars
set guioptions-=l
set guioptions-=L
set guioptions-=r
set guioptions-=R

" disable the menu and toolbar
set guioptions-=m
set guioptions-=T

Vim In Windows

Since I always work on Linux, Windows support may need improvement. For now I’ve kept a copy of the Windows software set:

VIM 8.0 download _vimrc

Install and copy the config file, and it’s ready to use.

Do Not Give Up

  • When I was a linux beginner, learning vim was hard. Never leaving the keyboard sounds cool, but it’s really hard to get used to at first. My learning method was: once you know hjkl, start playing a game. My game was 2048, found on chrome, combined with Vimium, forcing myself to operate with hjkl. After about an hour of practice, I had basically learned vim movement.

  • Low efficiency at the start is normal. But after using it more, the efficiency really is unmatched by other editors. This is not to say vim is a god — many modern IDEs provide vim plugins. The JetBrains and Eclipse plugins, for example, are excellent and almost seamless. Once you really master vim, you can be highly efficient in different development environments. I barely know the JetBrains and Eclipse shortcuts, yet I can move the cursor without a mouse.

The principle of much software is to be powerful rather than easy to use. If you want to work more efficiently, spending some time on editor configuration is never a bad thing.

LICENSE:

Copyright © 2016 corvo. Commercial use without permission is prohibited. Please credit the source when reposting.