Difference between pages "Package:Vim" and "Repository Configuration"

(Difference between pages)
(Add details about paste mode, instead of disabling auto-indent.)
 
(New repository layout)
 
Line 1: Line 1:
{{Ebuild
+
{{Warning|This article is a work-in-progress referring to a future Portage version. It does not apply to the current Funtoo Portage version. Please do not update your configuration yet.}}
|Summary=Vim is an improved, vi-style text editor with many features.
+
|CatPkg=app-editors/vim
+
|Maintainer=
+
|Repository=Gentoo Portage Tree
+
}}
+
== Introduction ==
+
  
So you thought you could get by with gedit? Not when you must configure an application on your server in a data center two states away! When it comes to remote system administration, all roads lead back to Vim. Not a Vim expert? No problem, you just need a handful of commands to do everything you need to do.
+
Starting with Portage-2.3.8, a switch to a new repository configuration framework is complete and users may want to update their configuration files. This document aims to describe the goals for the new framework and how to use it.
  
Entire books have been written about Vim, and they still fail to capture all of its functionality. But the core command set is all you really need if you're just making a few changes to a few files over SSH. You might not do it as efficiently as a Vim expert, but it's good enough to get the job done. In fact, if you're working with Vim (the pre-eminent vi-clone) on a server, there's a good chance it's "vim-tiny," a stripped-down Vim that offers the traditional vi functionality but not the full set of Vim features.
+
== Multiple repository layout ==
 +
One of the most important changes is the switch from the old ''overlay'' layout to a new cleaner ''repository'' system. The new layout is more flexible and more predictable. For example, repositories can now use resources (eclasses, for example) provided by other repositories.
  
==Insert Mode==
+
The old layout was based on the concept of one ''main tree'' and optionally a number of overlays. The main tree provided base system ebuilds, eclasses, profiles, while overlays mostly were able to provide their own ebuilds. The ebuild provided by overlays overrode the ebuilds in main tree to the extend of making it impossible to install the main tree version. Overlays could also provide eclasses for their own ebuilds and package.* entries that applied to all overlays and to the main tree. The Package Manager is responsible for updating the main tree, while overlays are managed externally.
The first thing you must grok is that Vim has several modes -- command mode, insert mode, and last-line mode (also known as ex mode). When you start Vim, you'll be in command mode. Here, all of the keys are used to perform commands, not input text. To switch to input mode, hit <span style="color:green">i</span>, and you're able start editing the file, adding text, using Backspace, etc.
+
To return to command mode, hit <span style="color:green">Esc</span>. To enter last-line or Ex mode, use :, and then input the command you wish to enter.
+
  
==Vim Command Mode==
+
The new layout is based on the concept of one or more configurable repositories. Each repository can either be stand-alone or depend upon other repositories. The distribution provides a repository called ''funtoo'' (a drop-in replacement for Gentoo's ''gentoo'' repository). Users can install more repositories at they will, the repositories providing their own ebuilds, eclasses and profiles as necessary and/or using them from other repositories. Users can explicitly choose the repository they want to install packages from. The Package Manager can update all repositories.
I could go on for days about the commands needed in command mode, but we're just here for the basics, so let's look at movement. Movement is based on the standard alphabetic keys:
+
  
* '''h''' Move the cursor to the left one character.
+
== Portage configuration ==
* '''l''' Move the cursor to the right one character.
+
=== New repository layout ===
* '''j''' Move the cursor down one line.
+
The repository configuration should be stored in <code>/etc/portage/repos.conf</code>. It can be either a single file or a directory containing one or more ''.conf'' files.
* '''k''' Move the cursor up one line.
+
  
You can move faster by using <span style="color:green">b</span> and <span style="color:green">w</span> to move backward and forward by one "word" at a time, respectively. Vim looks at "words" as a string of alphanumeric characters. So "eix" is a word, but "eix-sync" is multi-word because it's broken up by a non-alphanumeric character.
+
The default configuration is installed as <code>/usr/share/portage/config/repos.conf</code>. This file is internal configuration file installed with portage ebuild and should '''not''' be modified. Instead, the configuration in <code>/etc/portage/repos.conf</code> can override the defaults specified there.
  
Deleting is done with  <span style="color:green">d</span> or  <span style="color:green">x</span>. To delete a single character, move the cursor over that character and use <span style="color:green">x</span>. Using <span style="color:green">dw</span> will delete the word the cursor is over, and <span style="color:green">db</span> will delete the previous word.
+
The configuration uses format similar to Windows .ini files. Each section heading (repository name in square brackets) signifies a single repository, followed by one or more key-value option pairs. For example, the following file copies default configuration for Funtoo repository:
  
To delete an entire line, use <span style="color:green">dd</span>. To delete from the cursor to the end of the line, use <span style="color:green">d$</span>. To delete from the cursor to the beginning of the line, use <span style="color:green">d0</span>. The $ is shorthand for "end of the line," and 0 is shorthand for beginning of the line. You can also use ^.
+
{{file|name=/etc/portage/repos.conf/funtoo.conf|desc=Example configuration override for Funtoo repository|body=
 
+
[funtoo]
==Copying and Pasting in Vim==
+
# moved to non-default location!
Let's look at copying and pasting real quick. To highlight text to copy, use the <span style="color:green">v</span>, <span style="color:green">V</span> and <span style="color:green">Ctrl-V</span> commands. You might have guessed by now that Vim commands are case-sensitive, So v and V are different things.
+
location = /var/db/repos/funtoo
 
+
sync-type = git
The <span style="color:green">v</span> command simply allows you to highlight changes character by character using the movement (hljk and others) or arrow keys. The <span style="color:green">v</span> command highlights entire lines. And the <span style="color:green">Ctrl-v</span> command highlights blocks of text -- very useful for highlighting and copying columns of text.
+
sync-uri = git://github.com/funtoo/ports-2015.git
 
+
auto-sync = yes
Once you've highlighted the text you want to copy, hit <span style="color:green">y</span> to "yank" the text into the buffer.
+
 
+
To paste the text, use <span style="color:green">p</span> or <span style="color:green">P</span> to paste. The p command will paste after the cursor, and P pastes before the cursor.
+
==Search and Replace==
+
To search through the document, use the / key to initiate a forward search, or ? to initiate a backward search.
+
 
+
To search and replace, use <span style="color:green">:s</span> with the range of lines and search terms. Like so:
+
<pre>
+
:%s/old/new/
+
</pre>
+
 
+
The % means "global," but you can replace that with a range of lines, like this:
+
 
+
<pre>
+
:1,15s/old/new/
+
</pre>
+
Another example of search/replace functions
+
<pre>Command        Outcome
+
:s/xxx/yyy/    Replace xxx with yyy at the first occurence
+
:s/xxx/yyy/g  Replace xxx with yyy first occurrence, global (whole sentence)
+
:s/xxx/yyy/gc  Replace xxx with yyy global with confirm
+
:%s/xxx/yyy/g  Replace xxx with yyy global in the whole file</pre>
+
+
I prefer to use the <span style="color:green">c</span> (confirm) and <span style="color:green">g</span> (global) options too, so when searching it will search the entire line and not just the first occurrence of a string.
+
 
+
A usual search would look something like :%s/old/new/gc, and when you hit Enter you'll be prompted before you make changes. I recommend using confirm; otherwise you can wind up with unexpected results.
+
 
+
==Undo==
+
What if you've made an edit you didn't want to make? Easy, use the undo <span style="color:green">u</span> command. If you didn't mean to undo what you did -- and it's easy to accidentally hit u -- use <span style="color:green">Ctrl-r</span> to redo the last change.
+
Quick note: If Vim is in vi-compatibility mode, it will have only one "level" of undo. In normal Vim mode, you can undo many, many changes. But vi undoes only the most recent change.
+
 
+
==Saving, Quitting and More ...==
+
One of the things that's severely non-obvious while working with Vim the first time is how do I get the heck out of here? You can quit Vim in a number of ways, but I'll show the most usual ones.
+
 
+
First, if you want to save your changes before exiting Vim, use  <span style="color:green">:w</span> or save and exit in one action with <span style="color:green">:wq</span>.
+
Don't want to save your changes? It happens. No problem, just use <span style="color:green">:q!</span> if you realize that you've made some edits that you don't want to save, and they are too complex to easily undo before exiting. Note that you can also write changes to a different filename by using :w newfile.
+
 
+
This is just a short and sweet intro to Vim for emergencies or minimal usage. You could do much, much more with Vim if you wanted. Be sure to read through the Vim tutorial by running vimtutor, and look through Vim's documentation by running :help. But in a pinch, this list of commands should get you through.
+
 
+
== Good Starter Vimrc ==
+
 
+
The following file makes a very good starter <tt>.vimrc</tt> file. Place it in your home directory, and you will get true tabs (displayed indented 4 spaces) and you will be able to see all the whitespace in your document, which is handy when editing critical files:
+
 
+
{{file|name=~/.vimrc|desc=A good starter .vimrc file|body=
+
set noexpandtab
+
set shiftwidth=4
+
set tabstop=4
+
set listchars=eol:%,tab:>-,trail:~,extends:>,precedes:<
+
set list
+
filetype indent off
+
filetype plugin off
+
 
}}
 
}}
 +
Location variable is now what used to be a PORTDIR, when using old-fashioned <code>/etc/portage/make.conf</code>.  <code>/var/db/repos/funtoo</code> is a dummy location example. Default location in Funtoo is  set to <code>/usr/portage</code>. Users are free to choose a location of their suits. sync-type is a CVS tree used for portage tree, git is a default in Funtoo. sync-uri is what used to be a SYNC variable, when using old-fashioned configuration through <code>/etc/portage/make.conf</code>
 +
The most useful repository configuration options are listed below:
 +
;location: ''Obligatory.'' Specifies the directory where repository is/will be stored. If Portage knows how to sync the repository and the location does not exist, it will be created on next ''emerge --sync''. Otherwise, the directory must exist.
 +
;priority: Specifies the priority used for ordering ebuilds from different repositories. If two repositories provide an ebuild with matching versions, the repository with higher priority will be used.
 +
;auto-sync: Specifies whether ''emerge --sync'' should update the repository. Defaults to ''yes'' if ''sync-type'' is specified, ''no'' otherwise.
 +
;sync-depth: Specifies ''--depth'' for git clone. Used only on initial sync. Defaults to 1. Can be set to 0 to force full clone (not pass ''--depth'' at all).
 +
;sync-type: Specifies syncing/update method. Can be one of: ''cvs'', ''git'', ''rsync'', ''svn''.
 +
;sync-umask: Specifies the umask used when updating/syncing the repository.
 +
;sync-uri: Specifies remote URI from which the repository will be cloned/synced. Can use any syntax valid for a particular syncing method.
 +
;sync-user: Specifies the user[:group] used to update/sync the repository. If ''FEATURES=usersync'' is used, defaults to the credentials of directory owner.
  
By default, copying and pasting into a vim window will cause things to horribly auto-indent. To fix this, add the following to your <tt>.vimrc</tt> file:
+
[[Category:Portage]]
 
+
{{file|name=~/.vimrc|desc=fix pasting auto-indentation|body=
+
set noai
+
}}
+
 
+
Alternatively, you can temporarily switch to "paste mode" before pasting with <span style="color:green">:set paste</span>. You will see <tt>-- INSERT (paste) --</tt> in the status bar when you are in insert mode. Don't forget to disable paste mode with <span style="color:green">:set nopaste</span> after pasting. You can also use bang to switch between "paste" and "nopaste" so that you just have to recall the last command : <span style="color:green">:set paste!</span>. ([http://vim.wikia.com/wiki/Toggle_auto-indenting_for_code_paste See also])
+
 
+
{{EbuildFooter}}
+

Revision as of 13:52, February 14, 2015

Warning

This article is a work-in-progress referring to a future Portage version. It does not apply to the current Funtoo Portage version. Please do not update your configuration yet.

Starting with Portage-2.3.8, a switch to a new repository configuration framework is complete and users may want to update their configuration files. This document aims to describe the goals for the new framework and how to use it.

Multiple repository layout

One of the most important changes is the switch from the old overlay layout to a new cleaner repository system. The new layout is more flexible and more predictable. For example, repositories can now use resources (eclasses, for example) provided by other repositories.

The old layout was based on the concept of one main tree and optionally a number of overlays. The main tree provided base system ebuilds, eclasses, profiles, while overlays mostly were able to provide their own ebuilds. The ebuild provided by overlays overrode the ebuilds in main tree to the extend of making it impossible to install the main tree version. Overlays could also provide eclasses for their own ebuilds and package.* entries that applied to all overlays and to the main tree. The Package Manager is responsible for updating the main tree, while overlays are managed externally.

The new layout is based on the concept of one or more configurable repositories. Each repository can either be stand-alone or depend upon other repositories. The distribution provides a repository called funtoo (a drop-in replacement for Gentoo's gentoo repository). Users can install more repositories at they will, the repositories providing their own ebuilds, eclasses and profiles as necessary and/or using them from other repositories. Users can explicitly choose the repository they want to install packages from. The Package Manager can update all repositories.

Portage configuration

New repository layout

The repository configuration should be stored in /etc/portage/repos.conf. It can be either a single file or a directory containing one or more .conf files.

The default configuration is installed as /usr/share/portage/config/repos.conf. This file is internal configuration file installed with portage ebuild and should not be modified. Instead, the configuration in /etc/portage/repos.conf can override the defaults specified there.

The configuration uses format similar to Windows .ini files. Each section heading (repository name in square brackets) signifies a single repository, followed by one or more key-value option pairs. For example, the following file copies default configuration for Funtoo repository:

/etc/portage/repos.conf/funtoo.conf - Example configuration override for Funtoo repository
[funtoo]
# moved to non-default location!
location = /var/db/repos/funtoo
sync-type = git
sync-uri = git://github.com/funtoo/ports-2015.git
auto-sync = yes

Location variable is now what used to be a PORTDIR, when using old-fashioned /etc/portage/make.conf. /var/db/repos/funtoo is a dummy location example. Default location in Funtoo is set to /usr/portage. Users are free to choose a location of their suits. sync-type is a CVS tree used for portage tree, git is a default in Funtoo. sync-uri is what used to be a SYNC variable, when using old-fashioned configuration through /etc/portage/make.conf The most useful repository configuration options are listed below:

location
Obligatory. Specifies the directory where repository is/will be stored. If Portage knows how to sync the repository and the location does not exist, it will be created on next emerge --sync. Otherwise, the directory must exist.
priority
Specifies the priority used for ordering ebuilds from different repositories. If two repositories provide an ebuild with matching versions, the repository with higher priority will be used.
auto-sync
Specifies whether emerge --sync should update the repository. Defaults to yes if sync-type is specified, no otherwise.
sync-depth
Specifies --depth for git clone. Used only on initial sync. Defaults to 1. Can be set to 0 to force full clone (not pass --depth at all).
sync-type
Specifies syncing/update method. Can be one of: cvs, git, rsync, svn.
sync-umask
Specifies the umask used when updating/syncing the repository.
sync-uri
Specifies remote URI from which the repository will be cloned/synced. Can use any syntax valid for a particular syncing method.
sync-user
Specifies the user[:group] used to update/sync the repository. If FEATURES=usersync is used, defaults to the credentials of directory owner.