Vim is my preferred editor to write in, code or otherwise. Whenever I am forced to use another program to write, I feel uncomfortable and sometimes accidentally type in stuff like "dw" or ":w" and I find myself pressing
<Esc> all the time.
This post will showcase the plugins I use and some of the settings in my vimrc file which make using Vim much easier.
These are the plugins I can't live without and which I find myself using all the time.
If I can only use one plugin in Vim and had to choose which one, I'll pick NERDTree in a heartbeat. NERDTree is a file explorer plugin that gives a "drawer" like feature in Vim. Activate it, and you get a nice file explorer on the left, so you can easily find the files you want.
You can bookmark directories with the command
:Bookmark bookmark_name. Now, when in the NERDTree window, pressing
B brings up all your bookmarks. Pressing
cd on a folder node changes the current working directory into the highlighted node.
Managing buffers is probably the most confusing aspect of Vim. I still don't quite understand how to manage them, to be honest. But that's what MiniBufExpl is for.
It arranges your buffers in a row on the top of the window like tabs in a browser or other editors.
Everytime you open a file and start a new buffer, it is listed on top. You can then press
<Ctrl-Shift-Tab> to cycle between them. And since the plugin displays the buffer number beside the its name, you can use the
:bN command to quickly switch to a buffer number (where
N is the number).
The plugin also highlights buffers which have unsaved changes in them, which can be very handy when you're editing a lot of files.
Bclose is another plugin which helps with buffer management. It offers an easy way to easily close buffers and when the last buffer is closed, it creates a "scratch" buffer in place of the last one. It makes Vim act more like other editors you may be used to.
:Bclose closes the current buffer and opens the next available one or creates a "scratch" or empty buffer if it can't find the next one. I mapped
<leader>x so I can easily close buffers with a simple keystroke.
Surround offers shortcuts to easily surround words with parentheses, quotes and even HTML tags. (e.g. Typing
ysiw" surrounds the current word with quotes and
ysiw<tag> surrounds the word with
ds<tag> deletes the nearest surrounding
Repeat extends the default
. or "repeat" command in Vim so it can be used with Surround, among other things.
As if Vim's movement keys weren't good enough, EasyMotion is a very welcome addition to my setup. It provides quicker movement by allowing you to "pinpoint" the location you want to place your cursor. The animation on the project page probably does a better job at showing what I mean.
Pathogen provides an easy way to manage your plugins by allowing you to place each plugin in their own folder. Pathogen then appends each plugin's folder to Vim's path so they can be loaded and used.
It has also given me the opportunity to clean up my
~/.vim folder and to upload it to Bitbucket and Github.
These are plugins I have installed but I rarely use, if at all.
:bNmost of the time though.
<F4>to get a quick overview of a piece of code.
Here are the settings which I've added or I find quite interesting or useful.
I added this to simulate smooth scrolling by pressing
<Shift-Space>, just like in a browser.
map <S-Space> <C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y> map <Space> <C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E>
The smooth part only seems to work in GVim on Windows though.
Some mappings to plugins and functions and other stuff which I use often.
<F3>is mapped to toggle NERDTree
<F4>is mapped to toggle Taglist
<F5>is mapped to insert the current timestamp
<leader>evopens up my .vimrc file for quick edits
<leader>xis mapped to
:Bcloseto easily close files
<leader>cdswitch to the directory of the current file or buffer
;inserts a semicolon at the end of the line
map <F3> :NERDTreeToggle<CR><CR> map <F4> :TlistToggle<CR><CR> nmap <F5> a<C-R>=strftime("%Y-%m-%d %I:%M:%S")<CR><Esc> imap <F5> <C-R>=strftime("%Y-%m-%d %I:%M:%S")<CR> map <leader>ev :e! ~/.vimrc<cr> map <leader>cd :cd %:p:h<cr> au FileType java silent noremap ; <Esc>mcA;<Esc>`c
Easily switch windows by pressing
<Ctrl> + the direction of the window you want.
map <C-j> <C-W>j map <C-k> <C-W>k map <C-h> <C-W>h map <C-l> <C-W>l
I like to keep my Python code under 80 characters per line. And since the marker is a little distracting, I wanted an easy way to toggle it on or off.
I made a little function to do just that and mapped it to
<F2> to quickly check my bounds.
" Toggle 80 column marker nnoremap <F2> :call ToggleColorColumn()<CR> func! ToggleColorColumn() if exists("b:colorcolumnon") && b:colorcolumnon let b:colorcolumnon = 0 exec ':set colorcolumn=0' echo '80 column marker off' else let b:colorcolumnon = 1 exec ':set colorcolumn=80' echo '80 column marker on' endif endfunc