LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-08-2004, 07:22 PM   #1
Fulkan
LQ Newbie
 
Registered: Sep 2004
Posts: 11

Rep: Reputation: 0
Question vimrc


Hi

I am learning C++ and using Vim editor. I read some FAQs about how to configure Vim editor. First, I created vimrc in my home directory and wrote some codes. When I want to write new program, I have to write the following lines;

#include <iostream>
using namespace std;
int main ()
{


I want to see these lines whenever I create new .cc file. Can anyone help me about it?

I also want to see line numbers in vim editor. I read that if I write set nu in vimrc file, I can see lines but I can't see...

my last question is when I open rxvt terminal. I only see $ in the beginning of the each line . I used see. For example (/home/us $ )

I want to see directory name/ $ again. Do you have any suggestion about it?

Thanks

Last edited by Fulkan; 10-08-2004 at 09:09 PM.
 
Old 10-08-2004, 10:13 PM   #2
DaHammer
Member
 
Registered: Oct 2003
Location: Planet Earth
Distribution: Slackware, LFS
Posts: 561

Rep: Reputation: 30
Re: vimrc

Quote:
Originally posted by Fulkan
Hi

I am learning C++ and using Vim editor. I read some FAQs about how to configure Vim editor. First, I created vimrc in my home directory and wrote some codes. When I want to write new program, I have to write the following lines;

#include <iostream>
using namespace std;
int main ()
{


I want to see these lines whenever I create new .cc file. Can anyone help me about it?
I'm not sure what you're saying here. You write the lines but can't see them? What distro are you using? And are you certain you are using the vim editor and not one of the clones? Reason I ask is that some distros will link "vi" to another editor like Elvis and you think you're using vi when you're actually using Elvis. Do you see the vim welcome screen when you just run "vim"?

Quote:
Originally posted by Fulkan

I also want to see line numbers in vim editor. I read that if I write set nu in vimrc file, I can see lines but I can't see...
That's correct, if you want to see line numbers, then all you gotta do is add "set nu" to your .vimrc file. You can also set it after you start vi by typing a : and then type "set nu" and hit enter. But if you'll notice at the bottom vim tells you which line number you're cursur is on automatically anyway. Also notice the . in front of the .vimrc file. That must be there and the file should be in your home directory. Here's the one I use:

.vimrc
Code:
if v:lang =~ "^ko"
   set fileencodings=euc-kr
   set guifontset=-*-*-medium-r-normal--16-*-*-*-*-*-*-*
elseif v:lang =~ "^ja_JP"
   set fileencodings=euc-jp
   set guifontset=-misc-fixed-medium-r-normal--14-*-*-*-*-*-*-*
elseif v:lang =~ "^zh_TW"
   set fileencodings=big5
   set guifontset=-sony-fixed-medium-r-normal--16-150-75-75-c-80-iso8859-1,-taipei-fixed-medium-r-normal--16-150-75-75-c-160-big5-0
elseif v:lang =~ "^zh_CN"
   set fileencodings=gb2312
   set guifontset=*-r-*
endif
if v:lang =~ "utf8$" || v:lang =~ "UTF-8$"
   set fileencodings=utf-8,latin1
endif

set backupcopy=yes      " Fixes crontab -e issue
set nocompatible	" Use Vim defaults (much better!)
set bs=2		" allow backspacing over everything in insert mode
"set ai			" always set autoindenting on
"set backup		" keep a backup file
set viminfo='20,\"50	" read/write a .viminfo file, don't store more
			" than 50 lines of registers
set history=50		" keep 50 lines of command line history
set ruler		" show the cursor position all the time

" Only do this part when compiled with support for autocommands
if has("autocmd")
  " In text files, always limit the width of text to 78 characters
  autocmd BufRead *.txt set tw=78
  " When editing a file, always jump to the last cursor position
  autocmd BufReadPost *
  \ if line("'\"") > 0 && line ("'\"") <= line("$") |
  \   exe "normal g'\"" |
  \ endif
endif

" Don't use Ex mode, use Q for formatting
map Q gq

" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
  syntax on
  set hlsearch
endif

if has("autocmd")
 augroup cprog
  " Remove all cprog autocommands
  au!

  " When starting to edit a file:
  "   For C and C++ files set formatting of comments and set C-indenting on.
  "   For other files switch it off.
  "   Don't change the order, it's important that the line with * comes first.
  autocmd FileType *      set formatoptions=tcql nocindent comments&
  autocmd FileType c,cpp  set formatoptions=croql cindent comments=sr:/*,mb:*,el:*/,://
 augroup END

 augroup gzip
  " Remove all gzip autocommands
  au!

  " Enable editing of gzipped files
  "	  read:	set binary mode before reading the file
  "		uncompress text in buffer after reading
  "	 write:	compress file after writing
  "	append:	uncompress file, append, compress file
  autocmd BufReadPre,FileReadPre	*.gz set bin
  autocmd BufReadPost,FileReadPost	*.gz let ch_save = &ch|set ch=2
  autocmd BufReadPost,FileReadPost	*.gz '[,']!gunzip
  autocmd BufReadPost,FileReadPost	*.gz set nobin
  autocmd BufReadPost,FileReadPost	*.gz let &ch = ch_save|unlet ch_save
  autocmd BufReadPost,FileReadPost	*.gz execute ":doautocmd BufReadPost " . expand("%:r")

  autocmd BufWritePost,FileWritePost	*.gz !mv <afile> <afile>:r
  autocmd BufWritePost,FileWritePost	*.gz !gzip <afile>:r

  autocmd FileAppendPre			*.gz !gunzip <afile>
  autocmd FileAppendPre			*.gz !mv <afile>:r <afile>
  autocmd FileAppendPost		*.gz !mv <afile> <afile>:r
  autocmd FileAppendPost		*.gz !gzip <afile>:r
 augroup END
endif
if &term=="xterm"
     set t_Co=8
     set t_Sb=^[4%dm
     set t_Sf=^[3%dm
endif

" some extra commands for HTML editing
nmap ,mh wbgueyei<<ESC>ea></<ESC>pa><ESC>bba
nmap ,h1 _i<h1><ESC>A</h1><ESC>
nmap ,h2 _i<h2><ESC>A</h2><ESC>
nmap ,h3 _i<h3><ESC>A</h3><ESC>
nmap ,h4 _i<h4><ESC>A</h4><ESC>
nmap ,h5 _i<h5><ESC>A</h5><ESC>
nmap ,h6 _i<h6><ESC>A</h6><ESC>
nmap ,hb wbi<b><ESC>ea</b><ESC>bb
nmap ,he wbi<em><ESC>ea</em><ESC>bb
nmap ,hi wbi<i><ESC>ea</i><ESC>bb
nmap ,hu wbi<u><ESC>ea</i><ESC>bb
nmap ,hs wbi<strong><ESC>ea</strong><ESC>bb
nmap ,ht wbi<tt><ESC>ea</tt><ESC>bb
nmap ,hx wbF<df>f<df>

set shiftwidth=2
set cino=>2,e0,n0,f0,{0,}0,^0,:s,=s,ps,ts,c3,+s,(2s,us,)20,*30,gs,hs
Quote:
Originally posted by Fulkan

my last question is when I open rxvt terminal. I only see $ in the beginning of the each line . I used see. For example (/home/us $ )

I want to see directory name/ $ again. Do you have any suggestion about it?

Thanks
This depends on the shell you are using. Run "echo $SHELL" to see which one you are using. If it's bash, then you can add something like this to your system profile file (/etc/profile on Slackware) or .bash_profile:

Code:
PS1='\u@\h:\w\$ '
 
Old 10-08-2004, 11:32 PM   #3
Fulkan
LQ Newbie
 
Registered: Sep 2004
Posts: 11

Original Poster
Rep: Reputation: 0
@Dahammer

My first question was when I create new .cc file with vim, I have to write the same lines such as #include <iostream> the beginning of my code. I am tired to write the same lines. Can vim add this line(s) automatically for me by writing script in .vimrc?

Now, I don't have a problem about configuring .vimrc. I see some spaces before line numbers.. Can I remove them?

My linux PC is at my school. System administrator installed fedora. If I connect it by using telnet, I can see directory names before $ in telnet window but when I make remote desktop connection and run rxvt I see only $. I run "echo $SHELL" and I got /bin/ksh.

Thanks for helping.
 
Old 10-09-2004, 01:10 AM   #4
DaHammer
Member
 
Registered: Oct 2003
Location: Planet Earth
Distribution: Slackware, LFS
Posts: 561

Rep: Reputation: 30
Quote:
Originally posted by Fulkan
@Dahammer

My first question was when I create new .cc file with vim, I have to write the same lines such as #include <iostream> the beginning of my code. I am tired to write the same lines. Can vim add this line(s) automatically for me by writing script in .vimrc?
Ah, I see. Not to my knowledge but what you could do is set up a template with whatever you wanted in it and then use cat to create the initial file.

Quote:
Originally posted by Fulkan

Now, I don't have a problem about configuring .vimrc. I see some spaces before line numbers.. Can I remove them?
The spaces you see before and just after the line numbers are not part of the actual file. There are merely a cosmetic in vim and I doubt you can change it without modifing the VIM source code.

Quote:
Originally posted by Fulkan

My linux PC is at my school. System administrator installed fedora. If I connect it by using telnet, I can see directory names before $ in telnet window but when I make remote desktop connection and run rxvt I see only $. I run "echo $SHELL" and I got /bin/ksh.

Thanks for helping.
You might try seting $PS1 in your .bashrc file as it may be getting reset when you start rxvt. The howto at http://www.faqs.org/docs/Linux-HOWTO...mpt-HOWTO.html may also be of some help.
 
Old 07-05-2008, 07:50 AM   #5
dongli
LQ Newbie
 
Registered: Feb 2008
Posts: 8

Rep: Reputation: 0
Oh, it is a long time ago post already~

I find a solution to the first question.

First, create a skeleton file in $HOME/.vim/skeleton/, which includes the content you want vim to insert everytime you create a c++ file. Let's call it cpp.skel;

Second, edit $HOME/.vimrc, add the following line
Code:
autocmd bufnewfile *.cpp 0read ~/.vim/skeleton/cpp.skel | normal G
That will make vim insert cpp.skel into new file and put the cursor to the last line when you create a c++ file identified by its extend name (.cpp)

Hope this will help someone!
 
Old 07-22-2010, 01:20 PM   #6
Archit
LQ Newbie
 
Registered: Jul 2010
Posts: 4

Rep: Reputation: 0
Easy way to add.... :)

1 . open vimrc
vi /etc/vimrc

add this line any where,
:abb cpp #include<stdio.h> ^M int main() ^M { ^M return 0; ^M } ^M

to add ^M : press "ctrl+c" and then press "ctrl+m" .

quit vi
esc + : wq

open any file , go to insert mode and press cpp.

regards
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
encryption with Vim (vim -x) mikshaw Linux - Software 2 03-07-2007 09:00 AM
VIM help arunsri Linux - Software 8 03-14-2005 02:09 AM
Vim cxtech Slackware 3 03-06-2004 04:19 PM
Configuring (g)vim-tab with C++/Java Mega Man X Programming 2 01-28-2004 06:27 AM
vim x vi bira Linux - General 3 03-15-2002 02:55 PM


All times are GMT -5. The time now is 09:18 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration