Reputation: 165
I am testing few fortran codes by including print statements at various places. I also want to include a line number in the print statement, like:
...
write(*,*)'[current line #] I am here'
.....
.....
write(*,*)'[current line #] I am here too'
currently, I am inserting the line number manually by looking at the status bar. Is there any macro for the same?
Upvotes: 2
Views: 230
Reputation: 165
Please have a look at the link http://crueltown.com/wordpress/?p=40 I was requiring this. Thank you all the answers.
Upvotes: 0
Reputation: 196916
In insert mode, you can do:
<C-r>=line('.')<CR>
In normal mode, you can create a simple mapping:
nnoremap <F9> :execute ":normal 0iline number: " . line('.') . " hello world"<CR>
which outputs this when executed on line 39:
line number: 39 hello world
See :help line()
and, more generally, :help functions
.
Upvotes: 3
Reputation: 172778
A simple expression mapping will do:
:inoremap <expr> <F11> line('.')
Or, if you prefer a complete abbreviation (type debug
+ Space to trigger it):
:inoreabbrev <expr> debug "write(*,*)'" . line('.')
Upvotes: 6
Reputation: 9273
You can include line('.')
inside your macro, which returns the cursor line number.
Upvotes: 0