Mapping Shift + Alt + anything in vim - vim

I would like to map Shift + Alt + l and Shift + Alt + h to switch between split in Vim (the default combinations are Ctrl + w + l and Ctrl + w + h)
I have the solution to map Shift + Alt + "Arrow": it's :
map <A-S-Right> <ESC> <C-w>l (Shift + Alt + right arrow)
map <A-S-Left> <ESC> <C-w>h (Shift + Alt + left arrow)
But it's not working with the letter
i.e.
map <A-S-l> <ESC> <C-w>l
map <A-S-h> <ESC> <C-w>h
Any suggestion?

Related

Persistent (sticky) first line or column in VIM

This may be a stretch, but is there a chance to script a vim command such that the first (any?) row is constantly displayed at the top? The first (any) column (defined by a unique delimiter) be constantly displayed in the left?
The best I can manage is to split the screen and maximize the bottom one, so something like
split %
wincmd w
wincmd _
would be good for an upper row, but of course if the row is wider than the screen it doesn't work that well - unless there is a way to start a mode where two windows have their columns aligned.
For a persistent column I'm less sure. Need to somehow get the column of first delimiter (f command I thought, but I couldn't get it to work), vsplit % and vertical resize, then switch, wincmd l. Again this will only work if there are less rows then entire screen.
Doing both is even trickier, but possible using the above. I would also split the title row to make an empty cell at the corner. As far as synchronization, the title has to keep the row but sync on column, and vice-versa for the persistent column.
Is there a way to create such a persistent row+column setup that is synchronized with the main window? Also getting rid of the file names would be useful in this setup.
This is the best I could do, thanks to #DoktorOSwaldo's comment above. F2 and F3 toggle between a bound first column (according to given delimiter) and a bound first row. F4 destroys both:
hi cursorcolumn ctermbg=red
function Title_destroy()
if( winnr() == 1 )
return 0
endif
let oldpos = getpos('.')
wincmd k
wincmd j
hide
call setpos('.',oldpos)
set nocul
set nocuc
endfunction
function Title_bar()
if( winnr() > 1 )
call Title_destroy()
endif
set nowrap
split %
set scb
wincmd j
set scb
wincmd _
set scrollopt=hor
set cuc
endfunction
function Col_bar(delim)
if( winnr() > 1 )
call Title_destroy()
endif
set nowrap
let oldpos = getpos('.')
call setpos('.',[oldpos[0],oldpos[1],0,oldpos[3]])
let width = searchpos(a:delim)[1]+3
call setpos('.',oldpos)
vsplit %
exe 'vertical resize' width
set scb
wincmd l
set scb
set scrollopt=ver
set cul
endfunction
nnoremap <F2> :call Title_bar()<CR>
nnoremap <F3> :call Col_bar(nr2char(getchar()))<CR>
nnoremap <F4> :call Title_destroy()<CR>
I couldn't figure out a way to do both at the same time, since scrollopt is a global thing. If anyone figures it out please leave a comment or answer. Maybe somehow overloading window scrolling to change the scrollopt according to the scroll direction. For now this is good enough for handling large tables (for me).
Upgrades
It's fairly easy to accept a number optional argument - to change the row/column from just first.
Having both a sticky row and a sticky column.

Can word movement in vim skip the symbols?

For example, what I want:
http://vimdoc.sourceforge.net/htmldoc/motion.html
------>------>----------->
w w w
what Vim behaves:
http://vimdoc.sourceforge.net/htmldoc/motion.html
--->-->----->>---------->>
w w w w w w
You could do this:
nnoremap w /\v(^\|\A)\zs\a<cr>
onoremap w /\v(^\|\A)\zs\a<cr>
xnoremap w /\v(^\|\A)\zs\a<cr>
It maps the 'w' key to a search. This search looks for any alphabetic character that is preceded by either a non-alphabetic character, or a start of line. The various different mapping modes (nnoremap, onoremap, xnoremap) are so that it works in visual mode and as an argument to an operator, e.g. dw will delete our custom word rather than the default meaning of a word.
Yes. Just set 'iskeyword' to the desired value.

Detecting decimals in vim

I'd like to create a shortcut to convert rem to px and px to rem for CSS file in vimrc.
""""for converting px to rem""""
nnoremap <Leader>rem :%s; \(\d*\)px;\= string(submatch(1) / 16.0) . "rem";
""""for converting rem to px"""
nnoremap <Leader>px :%s; \(\d*\)rem;\= string(submatch(1) * 16.0) . "px";
The first one works but not the second one. When rem has a decimal, it doesn't convert to px.
How can I improve this code?
=======
After the help of KoRoN the following is my final solution
""""for converting px to rem""""
nnoremap <Leader>rem :%s;\<\(\d*\)px;\= float2nr(submatch(1) / 16.0) . "rem";
""""for converting rem to px"""
nnoremap <Leader>px :%s;\<\(\d\+\%(\.\d\+\)\?\)rem;\= float2nr(str2float(submatch(1)) * 16.0) . "px";
Try to use \(\d\+\%(\.\d\+\)\?\) instead of \(\d*\) for decimal (float).
This pattern is not perfect, but will cover most of cases.
And you should convert string to float by using str2float.
As a result of these, your second map should be like this:
nnoremap <Leader>px :%s; \(\d\+\%(\.\d\+\)\?\)rem;\= string(str2float(submatch(1)) * 16.0) . "px";

Smart window resizing with splits in MacVim

I'm using the latest MacVim. Is there any way to have it so if I open MacVim without a file or with only one file, it sets the window width to n characters? Then if I do a vertical split it will expand the window width to 2n characters? Same for 3 vertical splits but it will stop increasing the width after the window is 3n characters. Then if I close those splits it will resize down?
This appears to work. Whether or not a horizontal split has been done, any time a vsplit is created or deleted the window is resized.
let g:auto_resize_width = 40
function! s:AutoResize()
let win_width = winwidth(winnr())
if win_width < g:auto_resize_width
let &columns += g:auto_resize_width + 1
elseif win_width > g:auto_resize_width
let &columns -= g:auto_resize_width + 1
endif
wincmd =
endfunction
augroup AutoResize
autocmd!
autocmd WinEnter * call <sid>AutoResize()
augroup END
Configure the window width by changing the variable at the top. You probably want to do something like let g:auto_resize_width = &columns to set it to use the width of the original window as the width to resize by.
Things get a little wonky if you have so many vsplits that the window becomes maximized horizontally. I'm trying to find a fix and I'll post it if I find one.
I realized that my first post modified window height, not width. Here is what I meant:
Here's a quick solution I came up with, but it's not perfect. The function counts the number of open windows and then sets the window width to original_width * num_windows. The autocommands call the function when Vim starts, and whenever a new window is opened. You can change the default window width (80) to suit your needs.
function! SmartWidth( width )
let num_wins = 0
windo let num_wins+=1
sil exe "set columns=" . num_wins * a:width
sil exe "normal! \<c-w>="
endfunction
autocmd VimEnter * call SmartWidth(80)
autocmd WinEnter * call SmartWidth(80)
This works in the basic case, but does not distinguish between horizontal and vertical splits. I don't know how to do that!

vim-pressing arrow keys give 'after'

my vim is 7.0 and I can't update it to 7.3, i don't have the privilege.
How to produce the problem:
- in Vim, in any mode, if i keep pressing any arrow keys (either arrow keys or hjkl) it always gives this word "after". e.g:
abcd efgh gives abcd efghafter
very stupid.
I tried to put set nocompatible and
map ^[[A <up>
map ^[[B <down>
map ^[[C <right>
map ^[[D <left>`
in vimrc, doesn't work...
Could you please help?
EDIT:
:map gives this:
v <C-C> * :call RangeCommentLine()<CR>
no <C-C> * :call CommentLine()<CR>
n <CR> * :noh<CR><CR>
n <C-N> * :<C-U>YRReplace '1', 'p'<CR>
n <C-P> * :<C-U>YRReplace '-1', 'P'<CR>
v <C-X> * :call RangeUnCommentLine()<CR>
no <C-X> * :call UnCommentLine()<CR>
v # * :call VisualSearch('b')<CR>
v * * :call VisualSearch('f')<CR>
n . * :<C-U>YRYankCount '.'<CR>
n # YRMapsExpression("<SNR>16_", "#", "1")
n D D<SNR>16_yrrecord
x P * :<C-U>YRPaste 'P', 'v'<CR>
n P * :<C-U>YRPaste 'P'<CR>
n Y Y<SNR>16_yrrecord
x d * :YRDeleteRange 'v'<CR>
n dgg dgg<SNR>16_yrrecord
n dG dG<SNR>16_yrrecord
n d$ d$<SNR>16_yrrecord
n daw daw<SNR>16_yrrecord
n diw diw<SNR>16_yrrecord
n dE dE<SNR>16_yrrecord
n de de<SNR>16_yrrecord
n dw dw<SNR>16_yrrecord
n dd dd<SNR>16_yrrecord
n gx <Plug>NetrwBrowseX
n gp * :<C-U>YRPaste 'gp'<CR>
n gP * :<C-U>YRPaste 'gP'<CR>
v jj <Esc><Space>
x p * :<C-U>YRPaste 'p', 'v'<CR>
n p * :<C-U>YRPaste 'p'<CR>
x x * :YRDeleteRange 'v'<CR>
n x x<SNR>16_yrrecord
x y * :YRYankRange 'v'<CR>
n ygg ygg<SNR>16_yrrecord
n yG yG<SNR>16_yrrecord
n y$ y$<SNR>16_yrrecord
n yaw yaw<SNR>16_yrrecord
n yiw yiw<SNR>16_yrrecord
n yE yE<SNR>16_yrrecord
n ye ye<SNR>16_yrrecord
n yw yw<SNR>16_yrrecord
n yy yy<SNR>16_yrrecord
n y * "+y<Space>
n <Plug>NetrwBrowseX * :call netrw#NetrwBrowseX(expand("<cWORD>"),0)<CR>
n <SNR>16_yrrecord * :call YRRecord3()<CR>
n <F11> * :YRShow<CR>
:imap gives
i <S-Tab> *#<C-R>=<SNR>13_SetVals()<CR><C-R>=<SNR>13_TabComplete('up')<CR><C-R>=<SNR>13_RestoreVals()<CR>
i <Tab> *#<C-R>=<SNR>13_SetVals()<CR><C-R>=<SNR>13_TabComplete('down')<CR><C-R>=<SNR>13_RestoreVals()<CR>
i <SNR>16_yrrecord * <C-R>=YRRecord3()<CR>
i <SNR>16_YRGetChar & <C-R>=YRGetChar()<CR>
i jj <Esc>
The only solution is to update to vim 7.3

Resources