After telling you about my completely reworked VIM setup and the awesome VIM plugins I'm using in it, this blog post deals to share with some snippets and settings I'm using to make all that stuff work round.
VIM already provides you with a ton of pre-defined shortcuts on various keys and in various combinations with <shift>
and <ctrl>
. Therefore, the so called Leader Key was introduced, allowing you to choose one base key to deal as the starting point for all your custom shortcuts. Defining the leader is easy using:
let mapleader = ","
let maplocalleader = ","
You can then access this key through <leader>
and use it in keyboard combinations. Many plugins also try to register sensible defaults here, without inteferring with others.
Using the incremental search setting, VIM starts running through your text document and showing you search results, while you still type your search. This helps a) to find stuff earlier and b) return early, if the desired result cannot be found. Incsearch is set by:
set incsearch
set nohlsearch
The latter option disables the annoying highlighting of search results after you finished searching.
When auto-completing file names in command mode (like when doing :edit
, :split
or :vsplit
), the wild menu offers you more comfort and especially more context. Enable it by:
set wildmenu
set wildmode=list:longest
The latter setting defines the style of the menu. A matter of taste.
The place you are currently editing in insert mode is typically only marked by the cursor. Using the cursor line, you get a more appealing visual identifier:
autocmd InsertLeave * set nocursorline
autocmd InsertEnter * set cursorline
The autocommands deal for enabling/disabling the line when you enter/leave insert mode.
One feature which I had ages ago already (I suspect by either some plugin or by a distro based setting), but which suddenly vanished, was to restore the cursor position in a file I recently edited, when I re-open it again. Thanks to Benjamin, I now have that again through:
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g`\"" | endif
Making invisible chars (e.g. tabs) visible can sometimes help while debugging. This little snippet allows you to switch that on using <leader><L>
:
nnoremap <leader>L :set list!<CR>
set listchars=tab:▸\ ,eol:¬
Thanks to a VIM cast for that.
How often do you forget a sudo
in front of your vim
command when editing a system config file? Using the following snippet allows you to write your changes anyway, without exiting your VIM session:
cnoremap w!! w !sudo tee % >/dev/null
Thanks to Jakob for this snippet.
If you write CamelCase code, its often useful to navigate through the dedicated parts using <ctrl><left>
and <ctrl><right>
:
nnoremap <silent><C-Left> :<C-u>cal search('\<\<Bar>\U\@<=\u\<Bar>\u\ze\%(\U\&\>\@!\)\<Bar>\%^','bW')<CR>
nnoremap <silent><C-Right> :<C-u>cal search('\<\<Bar>\U\@<=\u\<Bar>\u\ze\%(\U\&\>\@!\)\<Bar>\%$','W')<CR>
inoremap <silent><C-Left> <C-o>:cal search('\<\<Bar>\U\@<=\u\<Bar>\u\ze\%(\U\&\>\@!\)\<Bar>\%^','bW')<CR>
inoremap <silent><C-Right> <C-o>:cal search('\<\<Bar>\U\@<=\u\<Bar>\u\ze\%(\U\&\>\@!\)\<Bar>\%$','W')<CR>
Using :setpaste
you can switch off all automatic formatting (e.g. indentation) in VIM. This is useful, if you want to paste from external sources through your terminal. However, using the following config, it becomes even more convenient:
set pastetoggle=<ins>
nnoremap <silent> <ins> :setlocal paste!<CR>i
autocmd InsertLeave <buffer> se nopaste
The <ins>
(insert) key becomes the paste toggle, meaning that, in insert mode, it switches between paste
/nopaste
. In normal mode, pressing insert will set you into insert mode and set paste
. Furthermore, when you leave insert mode with paste
it will be switched off, so that you don't forget it.
In times of distributed version control, undo functionality might become less and less important. However, it still gives you some comfort, especially if VIM remembers your undo history between sessions:
set undodir=~/.vim/undodir
set undofile
set undolevels=1000
set undoreload=10000
This sets vim to store undo information in files below ~/.vim/undodir
. It will keep up to 1000 (yes, feels almost endless) actions and up to 10000 lines of buffers that get overwritten externally.
Another goodie found in Benjamins config: When editing a file, it occurs quite often to me, that I need to edit one in the same directory (or one level above). I tent to write stuff like :vs %:h
which is
vertical split (:vs
)
current file name (%
)
strip last path element (:h
)
This works, but is a) hard to type and b) does not give you auto-completion for subsequent path elements (the files). The following shortcut simply expands the desired base path from typing %%
:
cnoremap %% <C-R>=expand('%:h').'/'<cr>
I would love to have %%%
expand to %:h:h
(one more path level removed), but we did not find a solution for that, yet. Anyone maybe has an idea?
If you liked this blog post or learned something, please consider using flattr to contribute back: .
Fields with bold names are mandatory.
lucash
First of all thanks for sharing your config and plugins in this and the previous posts.
Link to commentTo get %%% work as described this should work:
cnoremap %%% <C-R>=fnamemodify(fnamemodify(expand('%'), ":h"), ":h")<cr>
Toby
Hi lucash,
Link to commentwell, that works. However, I need to wait quite a bit now after using just %%. I expect VIM now waits if I will type another % and only expand the first 2 afterwards.
Maybe there is a solution without that hassle?
Cheers,
Toby
Saara james
It is an useful info about VIM plugin and I ever heard about it any where.Nice post to know about PHP editing with VIM -9-
Link to commentThose who interest in it should know following shortcuts.
Sounds good.
Аренда Яхты
Interesting post. I will subscribe for new posts
Link to commentfashion spot
As for why the critics was completely misinterpreted also a wide range of hair pass is issued, all free evaluation of evidence!
Link to commentffxi gil sale
I think your leader key is wonderful for me to learn. I am looking forward for your next post, I will try to get the hang of it!
Link to commentArcheage Gold
Sometimes it is extremely difficult to explore good and useful information out there when doing research.I'm glad that there is a knowledge from your page
Link to commentSamfrank
Lovely work! I'm definitely going to visit the blog frequently.
Link to commentI tried the ctags command and this does seem to do exactly the same thing. You're right on that :)
VIM is pretty damn cool. will take a look at NERDTree later.
ana
i know that vim is very powerful but i prefer nano :)
Link to commentAnvith Bhat
You should know, anti-corruption commissioner had billions of assets, it is because he often to help the mediation of disputes between the mine owners, all of these are he deserved rewards, http://www.louboutinukstockists.co.uk/
Link to commentwww.freeartsonline.com
I like the valuable info you provide in your articles. I will bookmark your blog and check again here regularly. I am quite certain I will learn many new stuff right here! Best of luck for the next
Link to commentmac repair
I wanted to inform you for this great help!! I definitely enjoyed every little bit of it. I have you bookmarked to check out new stuff on this post.
Link to commentelektronik sigara
Such an interesting article. I really still don't believe that I will find this article on your site surely not believe it. But Thanks for posting it.
Link to commentliquidation entreprise eurl
The author has written an excellent article. You made your point and not much to discuss. It's like this universal truth that you can not argue with the truth is not universal, everything has its exception. Thanks for this information.
Link to commentwww.bestfootballteams.com
Great team there. San Gabriel Valley puts out some good players.
Link to commentI am very much overwhelmed by your thoughts for this particular story. A more deeper and staged knowledge would be good for me.
www.seoeggs.com
There are a lot of important elements of SEO. As any busy Perth SEO company, who utilizes a diversified approach that helps clients weather all Google algorithm changes, are seeing that it is becoming increasingly important to add unique content and high quality content to your business website.
Link to commentwww.dailyfamily.eu
The actual rings given in the engagement are actually changed in the right hand left, and big quantities associated with savoury as well as sweet foods are supplied.
Link to commentwww.onlineflowershop.eu
Flowers can be bought or sent with the local florist and today, due in order to advances within technology, through on the internet florists too.
Link to commentwww.electronicbooks.eu
Guide fairs offer an excellent chance for more information about the actual publishing business, about booksellers, marketers, distributors as well as marketers. The going to author will even learn a good deal about exactly what readers would like and how you can reach visitors.
Link to commentwww.autosdeals.eu
it's not necessary to worry regarding your poor credit as lots of creditors are prepared to serve a person the loan on the platter. It's you opportunity to own the greatest model associated with car. It's an easy and also the most traditional loan.
Link to commentChristine
I rewrote PDV - phpDocumentor for VIM completely and it now nicely integrates with current plugin managers. Its code is now way cleaner and maintainable and it has some fancy new features like templating support through my Vmustache implementation and support for making the generated doc blocks UltiSnippets snippets for even more ease in editing them
Link to commentwww.popfreemusic.com
You write about wonderful information. Publish clause stunning as well as article writing levels is very beneficial effortlessly realize for you to anybody who is going to understand ones document understanding that boost my understanding.
Link to commentwww.ilikechinesefoods.com
Guide fairs offer an excellent chance for more information about the actual publishing business, about booksellers, marketers, distributors as well as marketers. The going to author will even learn a good deal about exactly what readers would like and how you can reach visitors.
Link to commenthotspot software
This plan is ideal for our customers for whom system availability is business critical, and who require software investment protection.
Link to commentsakfo
Flowers can be bought or sent with the local florist and today
Link to commentkirsten price female mind mastery
Ive been visiting several websites for about the last two hours and Taking advantage of this resources will really be a good read for visitors
Link to commenthttp://pinterest.com/lvlouisvuitton/
The 2013 Louis Vuitton Handbags are classic and a girl must have at least one in her closet. Chic, classic style, classy and good quality.
Link to commentAlltherma airquality
It is pronounce wiggling and everyone likes it. It also needs to amend examinee and someone.
Link to commentApplication Security
A website's security certificate gives users extended security by encrypting data between the user's browser and the Web server. Security certificates are installed on the server, so your website developers can securely transfer information such as financial or medical records.
Link to commentwww.queens-hotel-karlsruhe.com
Qualified post and also very helpful for writing this valuable information. Your post is one of the better that I have read, You should congrat your self for having able to write down some really wonderful articles
Link to commentwww.queens-hotel-karlsruhe.com
A top new topic in this post makes your site is greatly appreciated. Look forward to read more on this blog's updates. This is just what I'm looking for, a blog that I find almost all of the posts to be very beneficial
Link to commentlaw-states.com
By state law, there is typically a small fee that you must pay before a public record can be released and divorce is one of the categories of such public information.
Link to comment