⏳
5 mins
read time
I use vim everyday. I think it is good for my fingers because it uses few short cuts. Instead of using combos with touches like Ctrl, Alt or MetaKey, it uses different function modes (normal, insert, visual and command). In this way, the fingers remain near the home row in rest position, being able to have a continuous typing rate. Some people speculate that this can prevent musculoskeletal diseases.
It also induce motion to be done without neither the arrow keys nor the mouse. Instead single movement is controlled by HJKL keys to avoid the movement of the hand for every manipulations of the text. In addition vim offers several other motions capabilities, by word, by line, by paragraph, by places of text, etc.
It is simple and it is ubiquitous in most Unix operating systems. Still it is very powerful and can be highly customized with plugings. I will present my vim workflow in the following sections.
I use vundle as a plugin manager. I can configure your plugins right in the .vimrc. I can install/update/search/remove/clean plugins.
one plugin to rule them all.
All that with a single keypress with an interactive mode. In addition it regenerates the tags automatically after installing and updating, as a difference from pathogen for example.
I use nerd tree to explore my file system and open files from inside vim. It performs simple filesystem operations, saving bookmarks, etc. I like to have F3
as a shortcut for this plugin and also to ignore python *.pyc
files.
" NerdTreeToogle
let NERDTreeIgnore=['\.pyc$', '\~$'] "ignore files in NERDTree
nmap <silent> <F3> :NERDTreeToggle<CR>
I use tagbar to browser tags of the current file and its structure.
It does this by creating a sidebar that displays the ctags-generated tags of
the current file, ordered by their scope. This means that for example methods
in python are displayed under the class they are defined in. I like to toggle this plugin using F6
shortcut.
" Tagbar
nmap <F6> :TagbarToggle<CR>
I use the combo airline, tmuxline and promptline to put the same theme on the vim status bar, my tmux bar and my promptline. They are highly configurable and can control some other themes. In the vim status bar, I have information about the git branch, the type of file, the number of words, the place of the file, etc. In my tmux bar I have included the number of new emails, the number of slack new notifications and I can also include some information like the weather. In my promptline I have information about the git branch, the python virtual environment and whether if the last command have a error code.
" Airline
let g:airline#extensions#whitespace#enabled = 0
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#branch#enabled=1
let g:airline#extensions#hunks#enabled=0
let g:airline_powerline_fonts = 1
" Tmuxline
let g:airline#extensions#tmuxline#enabled = 1
let g:airline_theme='solarized'
let g:tmuxline_preset = {
\'a' : '#S',
\'b' : '#(~/Documents/Script/new_mail.sh)',
\'win' : ['#W'],
\'cwin' : '#F #W',
\'y' : '#(~/Documents/Script/tmux-slack-notifier.sh)',
\'z' : '%R'}
" Promptline
"":PromptlineSnapshot! .shell_prompt.sh airline
let g:promptline_preset = {
\'a' : [ promptline#slices#host() ],
\'b' : [ promptline#slices#cwd() ],
\'c' : [ promptline#slices#vcs_branch() ],
\'warn' : [ promptline#slices#last_exit_code() ],
\'z' : [ promptline#slices#python_virtualenv() ]}
I use fugitive to use git inside vim, it is consider one of the best git wrapers of all time. It allows to see the changes of each file from different version, the file logs, the changes using git blame
and from my personal point of view, the merge conflict resolution are easy to solve using fugitive. I have the default options of the pluging. The only thing that I have change is that I prefer to have a vertical split when dealing with merge conflicts.
" Fugitive
set diffopt+=vertical "Vertical split by default
I also use vim-gitgutter to check the lines that has been modified, removed or added with a simple plus and minus sign at the left part of the file. It have disable this pluing by default, and configure a shortcut using ,d
" Git gutter (Git diff)
let g:gitgutter_enabled=0
nnoremap <silent> <leader>d :GitGutterToggle<cr>
I use Syntastic the syntax checker. It supports all the programming languages that I know. For python it has support of flake8, pyflakes and pep8 in general. I have this plugin in passive mode so that it doesn’t bother me when I am coding. I use the shortcut ,sc
to activate it. It is also possible to customize the visual appareance.
" Syntastic
nnoremap <leader>sc :SyntasticToggleMode<CR>
let g:syntastic_mode_map = { 'mode': 'passive', 'active_filetypes': [],'passive_filetypes': [] }
let g:syntastic_always_populate_loc_list = 0
let g:syntastic_enable_highlighting = 1 " Highlight
let g:syntastic_auto_loc_list = 1 " No erros list
let g:syntastic_enable_signs = 1 " No sign column
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0
I use easy aligns plugin to create text tables, align equations and assignments. I select the text that I want to align, then I use the shortcut <Enter>
to activate the pulgin and then I write the character where I want to align.
" Easy Align
"" Start interactive EasyAlign in visual mode (e.g. vip<Enter>)
vmap <Enter> <Plug>(EasyAlign)
"" Start interactive EasyAlign for a motion/text object (e.g. gaip)
nmap ga <Plug>(EasyAlign)
I use surround to modify any time of parentheses.
I use ultisnips to use predefined snippets. There are several snippets for each programming language. It is also possible to create very modular snippets. I have added a path where I put my own snippets inside ~/.vim/
.
" UltiSnips
let g:UltiSnipsEditSplit="vertical" " If you want :UltiSnipsEdit to split your window.
" Trigger configuration. Do not use <tab> if you use https://github.com/Valloric/YouCompleteMe.
let g:UltiSnipsExpandTrigger="<tab>"
"let g:UltiSnipsJumpForwardTrigger="<c-b>"
"let g:UltiSnipsJumpBackwardTrigger="<c-z>"
set runtimepath+=~/.vim/my-snippets/
Markdown writting has many plugins. One of them are emojis. These are very popular smileys that can be found in several message applications. Vim provides a plugin to search for emojis called vim-emoji. The terminal must support the use of emojis like in iterm2. In linux additional fonts may be installed to render emojis like noto-fonts-emoji (Google’s own emoji font) or ttf-symbola.
Autocompletion function can be added in .vimrc
and then activated during insert mode with the keyboard CTRL+X
CTRL+U
.
" Emoji
set completefunc=emoji#complete
I spend most on my time using vim, then I consider a good idea to make it confortable, so I like to give vim a little of style, I use vim-devicons. Terminal font must be able to render glyphs. This can be patched with Nerd Fonts.
Checkout my .vimrc
and my other rc
files in my dotfiles repository
Vim is a simple and ubiquitous text editor that I use daily. In this article I show how to use Vim to take and publish diary notes using Vimwiki and Hugo.