26

Is there an editor which has the option to "split the screen" into two or more parts, accessing more than one file (possibly with a file tree) without opening more editor windows at once, and how would one do this (what are the commands).

I don't know if I made myself clear, but "split screen" is the only way to describe what I want to achieve. I want to use it to program, having more than one file open for editing. Note that I'm pretty new to both vi and emacs, if these are capable of doing this. Also, if this has to be done through a terminal editor, can it be done in the same terminal, regardless of the screen size?

  • 1
    I know you asked specifically about editors and not terminals, but I think it is worth to note for future visitors: the terminal emulator terminator also has the feature of split screen: ctrl + shift + e will split vertically and ctrl + shift + o will split horizontally (and also ctrl + shift + t will open a new tab) – Carlos Campderrós Aug 2 '12 at 14:55
  • @CarlosCampderrós I'll keep that in mind, thanks! – Eve Aug 2 '12 at 16:41
  • 1
    @CarlosCampderrós: You can also use a multiplexer like screen or tmux to achieve that in other terminal emulators. Disadvantage, of course, is that you have to remember to run them first, but the flexibility is probably worth it. – Phoshi Aug 3 '12 at 0:19

12 Answers 12

38

vim can easily do that:

ctrl+ws - Split windows

ctrl+ww - switch between windows

ctrl+wq - Quit a window

ctrl+wv - Split windows vertically

:sp filename

will open filename in new buffer and split a window.

You can also do

vim -o file1 file2

To open the files in a split screen layout. Replace -o with -O for vertical split instead of horizontal.

  • 4
    Or type :help CTRL-W to see all the split window operations. – Bernhard Aug 2 '12 at 6:22
  • 1
    Wow, great! I also stumbled upon ":split", but it only splits horizontally. Can you please just include which version of vim this is? Thanks! – Eve Aug 2 '12 at 16:43
  • @Eve I use VIM (Vi IMproved) 7.3. – rush Aug 2 '12 at 19:00
  • 1
    @Eve - you can also use :vsplit to create a vertical split, and as with :split it accepts a filename or command – Useless Aug 3 '12 at 10:43
  • 1
    And like <C-w>h/j/k/l will move between windows in specific directions, <C-w>H/J/K/L (capitalized) will move the window in that direction. – Izkata Aug 3 '12 at 14:50
13

This can be done using Emacs. It works in GUI and in terminal mode. You can even split multiple times. Here are some basic key combinations:

C-x 2 Split the selected window into two windows, one above the other (split-window-below).
C-x 3 Split the selected window into two windows, positioned side by side (split-window-right).
C-Mouse-2 In the mode line of a window, split that window.

Source: http://www.gnu.org/software/emacs/manual/html_node/emacs/Split-Window.html

  • 1
    For anyone unfamiliar with Emacs terminology, it is worth noting that an Emacs window is what many other editors call a screen or a panel. An Emacs frame is what others call a window (it is called a frame because the windows within it are framed either by the desktop decoration (title-bar and borders) or by the terminal... Windows contain buffers (some text; usually a file). – Peter.O Aug 2 '12 at 3:34
  • 1
    @Peter.O - Not just for those unfamiliar with Emacs... I have been using Emacs for over 5 years and would not have been able to explain the differences. I just use it. – jordanm Aug 2 '12 at 3:37
11

With vim, you can use split or vsplit.

The first one will split horizintally and the second one will split vertically.

CTRLw then to navigate through split screens.

You can also use tab. tabnew filename will open filename in a new tab. You can use tabnext and :tabprevious to navigate between tabs.

I personnaly maps the left and right arrows to navigate between tabs:

map <right> :tabnext<CR>
map <left> :tabprevious<CR>
inoremap <right> <ESC>:tabnext<CR>a
inoremap <left> <ESC>:tabprevious<CR>a
7

Kate

KDE Advanced Text Editor is very featureful.
It has everything you described in the question and much more.

See for yourself:

Screenshot

To split the view, go to ViewSplit View. Then you can select one of these options:

  • Split Vertical (Ctrl+Shift+L)
  • Split Horizotal (Ctrl+Shift+T)
  • Close Current View (Ctrl+Shift+R)

To get the layout like on this screenshot, Split Vertical, click on the bottom view and then Split Horizontal.

Of course, the boundaries of the views can be changed by dragging the borders (splitters) between them. To switch between the views, use F8 and Shift+F8.

By the way, Kate has a so-called VI Mode (SettingsConfigure Kate…Editing → VI Input Mode). Then the shortcuts for view splitting become the same as in Vim (see this answer).

7

joe (Joe's Own Editor) can do this, too:

ctrl+ko - split window horizontally

ctrl+kp - switch to the previous window

ctrl+kn - switch to the next window

ctrl+ke - open new file in current window

ctrl+kg - grow height of current window

ctrl+kt - shrink height of current window

ctrl+ki - hide all windows except the current one, press again to show all windows again

ctrl+c or ctrl+kx - close a window

5

Sublime Text 2 can do that (and many more).

4

If you are interested in getting to grips a bit better with VIM, check out vimcasts.org, it has a bunch of really friendly video tutorials. This one especially for split screen magic

Enjoy!

  • That's nice, thanks so much! I would up this more, but I'm only allowed one. – Eve Aug 4 '12 at 2:23
2

Regarding file trees, I personally use NERDtree with Vim. It requires Pathogen. I found the command to open the tree (:NERDtree toggle, iirc) to be a bit long, so I remapped it to <F2>. If you're working on a project with lots of files in lots of directories (think Rails projects), it's a really nice.

EDIT:

NERDtree is on Github: https://github.com/scrooloose/nerdtree

This is the remapping I use in my .vimrc: map <F2> :NERDTreeToggle<CR>

  • Thanks, I may have other questions about this. Those I reserve for another time. ;) – Eve Aug 4 '12 at 2:31
1

I use tmux and vim for split-screen editing in a terminal-based environment, though you could use any command-line based text editor for this (e.g. nano, emacs etc.).

tmux is short for "terminal multiplexer" and it allows you to create sessions with multiple terminals, running in separate "windows" and also "panes" within these windows, which are what allow you to split the screen. tmux is included in the repositories of many Linux and BSD distributions. I find this to be the most flexible option for coding, as I can also add splits and windows that contain terminals where I can compile code and use a version control system, like git alongside my code editing.

Here is an example of how I would create a split screen editing session using tmux and vim.

First open a terminal. In the below commands written after $ are issued from the command line. This uses the default key-bindings in tmux.

  1. Start a new tmux session. Here we make one called "coding":

    $ tmux new -s coding

    tmux just opened

  2. Press Ctrl+b followed by either % for a vertical split or " for a horizontal split.

    vertical split

    horizontal split

  3. You can move between the splits (or in tmux parlance, the "panes") by pressing Ctrl+b followed by o.

  4. Now open up a text editor with whatever files you want to edit in each pane. Here I have just opened two text files using vim, e.g.

    $ vim file1.txt

    Switch panes:Ctrl+b followed by o.

    $ vim file2.txt

    editing two files simultaneously

tmux is extremely advanced, allowing for multiple panes in a single window arranged in various ways and vim allows you to open multiple text files at once in tabs. I tend to use both the tabbing in vim and the panes in tmux to allow me to edit, version control and debug code simultaneously. If you have time to invest in learning the keyboard shortcuts and features of tmux it can be a very powerful development environment.

A tmux cheat sheet for starting out: dayid's screen and tmux cheat sheet

A tutorial on tabs in vim: Vim tips: Using tabs

0

i personally would use screen or tmux. both allow you to open multiple panels though i think tmux is better at recovering a multi panel session than screen. you also get the added benefit of being able to attach to the session if you disconnect from you local desktop session and then SSH in. You even have the ability to share the session with other users as well for collaboration.

  • here is a downvote because you dont use shift – peterh Mar 3 '15 at 5:46
0

Beside vim, emacs and joe editors, here are some others terminal (tty) / x-terminal emulator editors, that can show at least two files at the same time. May be not the cutest Swiss army knives but learning curve seem not too steep in any case:

1) mcedit

Is part of Midnight Commander (a text-mode file manager, install it with apt-get install mc in Debian-based distros).

mcedit

2) wpe \ xwpe

Available with apt-get install xwpe in Dedbian distros. However, seem that is a stopped protect.

xwpe

3) nfte \ efte

eFTE is also available via apt-get install efte.

efte

On the other hand, for the X-window there also some GUI "diff" tools that might be useful for this purpose. In my Linux Mint I have at least two:

4) xxdiff

A Qt-based application (apt-get install xxdiff)

xxdiff

Not tested and not showed, but exists also Fldiff using the Fast Light Toolkit (FLTK) but inspired partly in xxdiff. Also in the official repositories (apt-get install fldiff and you can test it yourself). The same apply to mgdiff.

5) kdiff3

A similar KDE application (apt-get install kdiff3).

kdiff3

0

You can use github's atom text editor. It comes with split screen functionality.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.