This is a companion discussion topic for the original entry at https://thoughtbot.com/upcase/videos/indenting-with-ben-orenstein
@benorenstein Iām trying to map p key, ( map p :set pasteo"*]p:set nopaste)
When I use the key, I go to next line and the mode stays in āPASTEā without copying anything. Is this because there is a " (comment) in the map?
Seems likely!
Did you try \"
?
Great tutorial.
In case others are having issues, I had to add this to my .vimrc file to get the == shortcut to work
filetype plugin indent on
I had trouble getting paste to work until I realised the vim that ships with OS X doesnāt have clipboard support. Installing vim from Homebrew with the --override-system-vim
option made it work.
http://vimcasts.org/blog/2013/11/getting-vim-with-clipboard-support/
Not only MacOX my limux also had the similar problem. This can be detected by if :echo has(āclipboardā) gives a 0. Then you need to uninstall vim and reinstall vim-gtk.
Is there any special reason you added <CR>
in this normal mode shortcut: map <Leader>i mmg=G'm<CR>
?
For me <CR>
moves cursor to the next line thus losing original cursor position after using <Leader>i
shortcut.
Oops! Good point. That <CR>
shouldnāt be there.
in my opinion longer single line mappings arenāt really readable / maintainable. I prefer extracting the separate parts of the paste binding into a vim function and then executing that function using a mapping.
that way your mapping would be written as (note: I use set clipboard=unnamed):
function! PasteCode()
set paste
execute "normal! o\<esc>\]p"
set nopaste
endfunction
nmap <leader>pp :call PasteCode()<CR>
In the end itās all personal preference of course, but I prefer to keep the use of <CR>
in mappings to a minimum.
also I use the following two functions allot, so Iāll paste them here maybe someone finds them useful.
set tabstop
, softtabstop
, and shiftwidth
to the same value:
function! Stab()
let l:tabstop = 1 * input('set tabstop = softtabstop = shiftwidth = ')
if l:tabstop > 0
let &l:sts = l:tabstop
let &l:ts = l:tabstop
let &l:sw = l:tabstop
endif
call SummarizeTabs()
endfunction
list the current values of tabstop
, softtabstop
and shiftwidth
:
function! SummarizeTabs()
try
echohl ModeMsg
echon 'tabstop='.&l:ts
echon ' shiftwidth='.&l:sw
echon ' softtabstop='.&l:sts
if &l:et
echon ' expandtab'
else
echon ' noexpandtab'
endif
finally
echohl None
endtry
endfunction