Vim is my main text editor. I don’t consider myself as an expert in Vim usage and I’m always looking for new ways to use it. At the moment these little config values and tricks make my Vim what it is.
You can see my Vim config files in the repo.
Window handling in Vim was quite problematic for me a long time. But then I came up with this little gem:
nmap w <C-W>
It maps key
w to sequence
Ctrl W. It allows me to cycle thru all
windows by just hitting
w repeatedly. Other subcommands for
nfor creating new window
vsplitting window vertically
cfor closing window
ocloses all other windows
One good command is
:sf[ind] which creates new window and
finds a file in path and opens it. More commands and explanation
how the windowing really works is in
Indentation, tabs and whitespace usage is the most problematic question after choosing the editor. Over the years I’ve tried several different rules for indentation and currently I’m adjusting my rules based on language, project and the team I’m working with.
But my personal preference still is this:
set tabstop=2 set shiftwidth=2 set autoindent set expandtab set smarttab
Basically it means: tabs are replaced with 2 spaces.
:retab I can kill tabs really easily. It converts
tabs to spaces according to the rules above.
The statusline at the bottom of the window is handy little tool to show all kinds of information about the file and the character where the cursor is located.
set modeline set statusline=%F%m%r%h%w\ [\%03.3b]\ [\%02.2B]\ [%04l,%04v][%p%%]\ [%L]
This shows, from left to right:
You can get more choices from
:help 'statusline' and customize the statusline
to your own liking.
set laststatus=2 set wildmenu
The first one allocates own line for commands and the latter turns on enhanced command line autocompletion which uses the statusline to show autocompletion results.
I like my files in UTF-8, thank you. This makes it so:
set encoding=utf-8 setglobal fileencoding=utf-8 set nobomb set termencoding=utf-8 set fileencodings=utf-8,iso-8859-15
And I hate BOM because it messes some editors, command line tools and such. So it is turned off by default. Also for this very reason I have a rule: first line of all source code files is empty. Also the last line of the file has to be empty.
That was easy.
I use candycode for syntax highlighting color scheme and can recommend it. I added underlining to the cursor. It is enabled with simply:
I’ve used these really good resources as a base to find my own taste:
That’s all for now. I’ll update this page when something new comes up.