In a fortran code, I have lines likec    write(6,*) something     write(6,*) something_elseI would like to insert the first character of the previous line when I open a new line with o in normal mode or enter in insert mode.In the example given, if I open a new line under the 1st line, the line should open with a c and when I open new line under the 2nd, the new line should start with a whitespace. How would I do that in vim?P.S. Kindly add appropriate tags if you find any. I could only find vimscript and vimrc which might even be not so appropriate.
Automatically insert first character of previous line
vimrc;vimscript
One possible approach is to use custom function:function! MyFunction()  let curline = getline(line('.'))  let char =    if len(curline)    let char = curline[0]  endif  let l:r = append(line('.'), char)  let l:r = setpos('.', [0, line('.')+1, 3, 1])endfunctionnnoremap o :call MyFunction()<CR>Ainoremap <CR> <Esc>:call MyFunction()<CR>AUsing above mapping will make it work both in normal and insert mode.