Results 1 to 10 of 10

Thread: line number count in terminal

  1. #1
    Join Date
    Aug 2009
    Beans
    9

    line number count in terminal

    How do i get the line number count to appear in the terminal screen at the bottom right corner?.. as it becomes really tough while compiling the codes without knowing which line the error is at..

  2. #2
    Join Date
    Apr 2008
    Location
    UK
    Beans
    496
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: line number count in terminal

    Normally javac/gcc will give line numbers for any errors (which aren't always correct in terms of where the problem actually lies), and then you can just jump to that line in your text editor of choice. For example, I use the command line text editor vim, so all I need to do is open the file (vim myfile.c) and enter (:502) or whatever the line number is, and I'm right there. Or if you prefer GUI text editors, gedit shows you the current line number on the status bar on the bottom, and Ctrl+I will take you to a specific line.

    Maybe I'm not quite understanding your problem correctly: what language are you coding in, and which compiler are you using? edit: and which text editor are you using?
    Ace1 FreeBSD/Gnome 2, i5 2300, 16GB, HX750W, 20TB ZFS pool, 60GB SSD, Fractal Design XL
    Ace2 Ubuntu/Xubuntu, i7 2600, 16GB, HX850W, 4TB, Asus HD6970, Fractal Design R3
    Ace3 Ubuntu/XFCE, E7200, 4GB, OCZ GameXStream 700W, 8TB

  3. #3
    Join Date
    Aug 2009
    Beans
    9

    Re: line number count in terminal

    Thanks for your reply, but i did not understand what u said.
    What does vimmyfile.c do?I write codes in c language,using gcc compiler.Generally i write them in the terminal and not in gedit .So how do i get the line no. count to appear in the terminal??

  4. #4
    Join Date
    Sep 2009
    Location
    Hampshire, UK
    Beans
    375
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: line number count in terminal

    do you mean numbering each line?
    Code:
    cat <filename> -n
    Hope im not being obtuse but I cant think of a way or reason to list total at bottom right of terminal.
    Toshiba AMD64 2Ghz, 4Gb RAM: dual Natty/win7. Dell Mini10v: 10.04. SamsungN140:win7/11.04. NB200:10.10.
    ++ desktops P4 3Ghz ++ servers
    Full Circle Magazine | Ubuntu Pocket Guide | HantsLUG

  5. #5
    Join Date
    Jun 2009
    Location
    0000:0400
    Beans
    Hidden!

    Re: line number count in terminal

    Quote Originally Posted by studybuddy09 View Post
    Thanks for your reply, but i did not understand what u said.
    What does vimmyfile.c do?I write codes in c language,using gcc compiler.Generally i write them in the terminal and not in gedit .So how do i get the line no. count to appear in the terminal??
    Vim is a terminal based text editor (the only, as far as I'm concerned). I guess that means you're using Nano? You can use Alt-G to go to a specific line number and you can use Ctrl-C to see what your current position is.

  6. #6
    Join Date
    Apr 2008
    Location
    UK
    Beans
    496
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: line number count in terminal

    Ok, but what are you using to write your source code? I.e. which of the following (or another method: and source.c in the following is just the example of a source code file you may be trying to edit):

    Code:
    $ nano source.c  #Nano text editor
    $ vim source.c  #Vim text editor
    $ pico source.c  #Pico text editor
    $ emacs source.c  #Emacs text editor
    $ cat >> source.c  #Appending text directly
      my text
      ^D
    "vim myfile.c" was an example of opening a source file in the popular Vim terminal text editor.

    I'm still trying to understand what you want to display line numbers. Are you talking about line numbers for your source code? In which case you should probably use a text editor such as in the above list. Or if you're just reading through source code and not editing it, maybe you want (cat -n source.c).
    Ace1 FreeBSD/Gnome 2, i5 2300, 16GB, HX750W, 20TB ZFS pool, 60GB SSD, Fractal Design XL
    Ace2 Ubuntu/Xubuntu, i7 2600, 16GB, HX850W, 4TB, Asus HD6970, Fractal Design R3
    Ace3 Ubuntu/XFCE, E7200, 4GB, OCZ GameXStream 700W, 8TB

  7. #7
    Join Date
    Aug 2009
    Beans
    9

    Re: line number count in terminal

    Yes, i use vim to write codes and i am talking about line numbers for the source code.
    But i want them in the command line terminal and not in the gedit text editor(in which it already displays the line nos.).
    The cat<filename> -n cmd worked, but it prints the code along with the line nos.
    I want the line nos. to appear simultaneously while typing the code.
    Hope im clear!!
    Last edited by studybuddy09; November 9th, 2009 at 02:41 AM.

  8. #8
    Join Date
    Apr 2008
    Location
    UK
    Beans
    496
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: line number count in terminal

    Now I see what you want: line numbering in edit mode in vim.

    I'm not sure how to achieve this (but I'm sure you can). However, in the meantime, you can use these shortcuts to speed things up:

    Open a file with cursor at line number 13:

    Code:
    vim +13 source.c
    Navigate to line number 13 when inside vim (but not in edit mode; hit Escape if you are in edit mode):

    Code:
    :13
    edit: Turns out it's pretty easy. You can set this in your ~/.vimrc file, or just enter it each time:

    Enable line numbering when inside vim (but not in edit mode; hit Escape if you are in edit mode):

    Code:
    :set number
    Last edited by stderr; November 9th, 2009 at 02:44 AM.
    Ace1 FreeBSD/Gnome 2, i5 2300, 16GB, HX750W, 20TB ZFS pool, 60GB SSD, Fractal Design XL
    Ace2 Ubuntu/Xubuntu, i7 2600, 16GB, HX850W, 4TB, Asus HD6970, Fractal Design R3
    Ace3 Ubuntu/XFCE, E7200, 4GB, OCZ GameXStream 700W, 8TB

  9. #9
    Join Date
    Feb 2008
    Beans
    1,031

    Re: line number count in terminal

    Don't use vi/vim personally, but this is what google says:

    http://www.tech-recipes.com/rx/402/s...-in-vi-or-vim/

    Hope that helps

  10. #10
    Join Date
    Aug 2009
    Beans
    9

    Re: line number count in terminal

    The set number command worked!!
    Thanks a lot for all your help!!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •