How to Make Your Vim Cool
Requirements:¶
- Vim Version: Ensure you have Vim version 8.0 or higher installed.
- Plugin Manager: Install a plugin manager like
vim-plugorPathogenfor easier management of plugins.
Installation¶
vim-plug¶
Online Installation¶
curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
Offline Installation¶
You should download plug.vim via url.
mkdir -p ~/.vim/autoload/
cp plug.vim ~/.vim/autoload/plug.vim
Pathogen¶
You should download pathogen.vim via url.
mkdir -p ~/.vim/autoload/
cp pathogen.vim ~/.vim/autoload/pathogen.vim
Configuration¶
You can customize your configuration based on your needs. Here, we provide an example.
vim ~/.vimrc
Paste the following configuration into ~/.vimrc:
set nocompatible " required for improved vim
set noic
syntax on
filetype off " required
set encoding=utf-8
set termencoding=utf-8
set fileencodings=utf-8,gbk,latin1
set nu " show line numbers
set cursorcolumn
set cursorline
set hlsearch
set tabstop=4
set shiftwidth=4
set expandtab
set autoindent
set cul
set cuc
call pathogen#infect()
set t_Co=256
set background=dark
execute pathogen#infect()
set statusline+=%#warningmsg#
set statusline+=%*
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0
filetype plugin indent on
let g:livepreview_previewer = 'open -a Preview'
let g:pymode_options_max_line_length = 120
let g:pymode_lint_options_pep8 = {'max_line_length': g:pymode_options_max_line_length}
let g:pymode_options_colorcolumn = 1
call plug#begin('~/.vim/plugged')
Plug 'xuhdev/vim-latex-live-preview', { 'for': 'tex' }
Plug 'scrooloose/nerdtree'
Plug 'Xuyuanp/nerdtree-git-plugin'
Plug 'sheerun/vim-polyglot'
Plug 'Vimjas/vim-python-pep8-indent'
Plug 'Chiel92/vim-autoformat'
Plug 'scrooloose/nerdcommenter'
call plug#end()
let g:header_field_author = 'deep_thoughts'
map <F4> :AddHeader<CR>
highlight Cursor guifg=white guibg=black
highlight iCursor guifg=white guibg=steelblue
set guicursor=n-v-c:block-Cursor
set guicursor+=i:ver100-iCursor
set guicursor+=n-v-c:blinkon0
set guicursor+=i:blinkwait10
let g:NERDSpaceDelims = 1
let g:NERDCompactSexyComs = 1
let g:NERDDefaultAlign = 'left'
let g:NERDAltDelims_java = 1
let g:NERDCustomDelimiters = { 'c': { 'left': '/**','right': '*/' } }
let g:NERDCommentEmptyLines = 1
let g:NERDTrimTrailingWhitespace = 1
let mapleader=","
set timeout timeoutlen=3000
imap <F5> <Esc>:w<CR>:!clear;python %<CR>
function! GitBranch()
return system("git rev-parse --abbrev-ref HEAD 2>/dev/null | tr -d '\n'")
endfunction
function! StatuslineGit()
let l:branchname = GitBranch()
return strlen(l:branchname) > 0 ? ' '.l:branchname.' ' : ''
endfunction
set statusline=
set statusline+=%#PmenuSel#
set statusline+=%{StatuslineGit()}
set statusline+=%#LineNr#
set statusline+=\ %f
set statusline+=%m\
set statusline+=%=
set statusline+=%#CursorColumn#
set statusline+=\ %y
set statusline+=\ %{&fileencoding?&fileencoding:&encoding}
set statusline+=\[%{&fileformat}\]
set statusline+=\ %p%%
set statusline+=\ %l:%c
After adding your plugins with vim-plug, you need to run :PlugInstall to install them. Once installed, use :source ~/.vimrc to apply your changes.
With these configurations and plugins, you can enhance your Vim experience significantly.