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.
Related
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.
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";
I have the x,y data for a number of curves stored in one file, separated by a blank line.
I want to plot the different curves with different line styles (solid, dashed ...).
How do I do it ?
You can use the every keyword to select block of datas (separated with a single empty line, so two new line character after each other), and you can use the linestyle keyword to explicitely define linestyle.
p "data.txt" every:::0::0 w l ls 1, "" every:::1::0 w l ls 2
If you have not so much datas, you can write the whole command by hand. If you have more block of datas, you may prefer to use a for loop:
p for [i=0 : maximum_number_of_curves : every_nth_curve] "data.txt" every:::i::i w l ls i
Please note that some terminal types does not support dashed or dotted linestyles. Use 1 as the value of every_nth_curve if you would like to use every data.
If you have double empty lines (three new line characters), you have to use the index keyword to select block of datas, e.g:
p for [i=0 : maximum_number_of_curves : every_nth_curve] "data.txt" index i w l ls i
I am using DrawIt plugin in Vim 7 to draw some ASCII diagrams.
This might be too much, but still—
Is there any plugin which can display a grid in background, to make the drawing easier?
I can't add anything to #David and #romainl's thoughts (I think #romainl's suggestion of using a semi-transparent window with a grid behind it is inspired!).
However, you might find it easier to visualise the cursor position by using:
set cursorline
set cursorcolumn
Of course it's not a substitute for a true grid, but it will at least let you see at a glance the alignment of the cursor.
Let me propose an implementation emulating the guiding grid using Vim
highlighting features. The following function creates the necessary
highlighting taking two mandatory arguments and another two optional ones.
The former two are distances between horizontal and vertical lines,
correspondingly. The latter arguments are the height and the width of the
area covered with grid (in lines and characters, correspondingly). When these
arguments are not specified the number of lines in the buffer and the length
of the longest line in it are used.
function! ToggleGrid(...)
if exists('b:grid_row_grp') || exists('b:grid_prev_cc')
call matchdelete(b:grid_row_grp)
let &colorcolumn = b:grid_prev_cc
unlet b:grid_row_grp b:grid_prev_cc
return
endif
let [dr, dc] = [a:1, a:2]
if a:0 < 4
let [i, nr, nc] = [1, line('$'), 0]
while i <= nr
let k = virtcol('$')
let nc = nc < k ? k : nc
let i += 1
endwhile
else
let [nr, nc] = [a:3, a:4]
endif
let rows = range(dr, nr, dr)
let cols = range(dc, nc, dc)
let pat = '\V' . join(map(rows, '"\\%" . v:val . "l"'), '\|')
let b:grid_row_grp = matchadd('ColorColumn', pat)
let b:grid_prev_cc = &colorcolumn
let &colorcolumn = join(cols, ',')
endfunction
I'm inclined to agree with #romainl; I can't think of any way to do this truly in Vim without mucking around with the source. However, I can think of a few workarounds.
In many terminal emulators, you can set a background image. (xfce4-terminal has this feature, for example). You could design a background where the dimensions of each cell correspond to the space occupied by your monospace font.
Nate Kane's vim-indent-guide might be helpful- it displays vertical lines you could use to align characters. See the screenshots page for some examples.
You could abuse Vim's highlighting to simulate a grid of sorts.
Let L(R) be the language denoted by regular expression R.
I'd really love your help with presenting a regular expression to the complement
of L((0 U 10 U 110)* (epsilon U 1 U 11)), where language is over the alphabet {0,1}, epsilon is the empty word, 'U' stands for union and '*' is the star iterator.
I tried to find it with De Morgan's laws. I think that I am requested to evaluate
not (L((0 U 10 U 110)* (epsilon U 1 U 11)))- what is not of the '*' for example?
Thanks a lot
You need to convert the regular expression to a deterministic finite automaton, complement that (into another DFA), then turn that back into a regular expression.