tips and tricks for everything but emacs

Forum rules
Share your brain ;)
pidsley
Hermit
Posts: 2539
Joined: Wed Oct 17, 2012 12:31 pm

tips and tricks for everything but emacs

Unread post by pidsley » Tue Feb 17, 2015 4:16 am

We have a T&T for emacs, so let's have one for everything else. Post the things you use in nano, vim, tmux, even cmus, moc, and anything else you can think of. What shortcut keys or configs work for you?

I already posted about using nano buffers to load more than one file at once here: http://linuxbbq.org/bbs/viewtopic.php?f ... 132#p37123

The things I use in vim every day:

Code: Select all

function! NuTriState()  " toggle through line-number modes
    if(&rnu)    " turn off line numbering
        set nonu
        set nornu
    elseif(&nu) " normal numbers on, add relative numbers (hybrid mode)
        set rnu
    else        " normal numbers off, turn them on
        set nu
    endif
endfunc

nnoremap <silent><F2> :call NuTriState()<cr>

" select lines in visual mode, ,ic adds # comments, ,rc removes
map ,ic :s/^/#/g<CR>:let @/ = ""<CR>
map ,rc :s/^#//g<CR>:let @/ = ""<CR>
And I use tmux all the time. I usually have two ratpoison windows open -- one for firefox, and the other for tmux. I use tmux like a CLI window manager. In tmux I usually have one multi-pane window for terminals, a second full window for weechat, and a third window for ssh to my nfs server. Assuming "P" means "prefix" (which I have defined as ctrl-A, but you may have as ctrl-B in a default tmux config, I use these sequences every day:

Code: Select all

P-z  : toggle pane full screen
P-!  : split pane into a new window
P-c  : create new window
P-<n>  : goto window <n>
Very basic.

You have probably also seen my tmux.conf, where I redefine the window split commands to the function keys. Nothing fancy like gutterslob or DJ's configs, but it works for me.

What interesting keybinds or configs do you use?

(thamks dkeg and gekkop for encouraging me to start this thread)

User avatar
kexolino
Common Boob
Posts: 557
Joined: Sun Jun 16, 2013 1:57 pm

Re: tips and tricks for everything but emacs

Unread post by kexolino » Tue Feb 17, 2015 7:50 am

I have a pretty basic vimrc, and most parts of it I found around the internet, so credit to those people.

Code: Select all

nnoremap j gj
nnoremap k gk
Two simple mappings for navigating wrapped lines. Pretty useful if you have set wrap in your vimrc, because otherwise vim will always just jump to the top of the wrapped line.

Some useful stuff for searching:

Code: Select all

set hlsearch "highlights the searched string (only after you press enter)
set incsearch "starts searching immediately, not just after pressing enter
set ignorecase "ignores cases when searching
set smartcase "unless you enter an uppercase letter in your search
After the search is highlighted, it will stay that way, so :nohl can be used to unhighlight everything.

Though I rarely use panes, I have these maps for navigating, makes it simpler:

Code: Select all

nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>

machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

Re: tips and tricks for everything but emacs

Unread post by machinebacon » Tue Feb 17, 2015 8:03 am

Very good thread, thanks Pids!

If dialogs should be 'no colour', do this:

Code: Select all

dialog --create-rc ~/.dialogrc
and make sure use_colors and use_shadow are set to OFF. Some ncurses applications support the no color switch, for example

Code: Select all

mc -b
htop -C
..gnutella..

User avatar
dkeg
Configurator
Posts: 3782
Joined: Sun Nov 18, 2012 9:23 pm
Location: Mid-Atlantic Grill

Re: tips and tricks for everything but emacs

Unread post by dkeg » Tue Feb 17, 2015 12:27 pm

Great Pidsley! We have been discussing this over a few IRC sessions. We are quite basic and will probably blow our load by first page end, but here we go!

VIM - Folding

In your .vimrc

Code: Select all

"" Code Folding {{{                                               
    set foldenable                          " Enable code folding 
    set foldmethod=manual                   " But do it manually
    autocmd BufWinLeave * mkview            " Auto save folds
    autocmd BufWinEnter * silent loadview   " Auto load saved folds
" }}}
The actual folding part

Code: Select all

v for visual mode
j to highlight lines to fold
zf to fold
space bar to unfold
za to refold
Highlight the folds - adjust color codes as needed

Code: Select all

highlight folded       term=NONE cterm=bold ctermfg=8   ctermbg=0 
FYI, if you open a plain vim session, you'll get an error on load b/c there are no folds to load. Just ignore. Or wrap in some logic. If you do that, then share!

Edit: And folding in action!
fold.png

Work hard; Complain less

User avatar
dkeg
Configurator
Posts: 3782
Joined: Sun Nov 18, 2012 9:23 pm
Location: Mid-Atlantic Grill

Re: tips and tricks for everything but emacs

Unread post by dkeg » Tue Feb 17, 2015 12:29 pm

And one more ...

VIM - multiple line commenting

Code: Select all

ctrl-v for visual block mode
j to highlight text to comment
shift i for insert
add commenting character
esc twice

Work hard; Complain less

User avatar
GekkoP
Emacs Sancho Panza
Posts: 5877
Joined: Tue Sep 03, 2013 7:05 am

Re: tips and tricks for everything but emacs

Unread post by GekkoP » Tue Feb 17, 2015 8:57 pm

Probably a lame one, but comes in handy when you have different machines.

VIM - Editing files over the netwok

Code: Select all

vim scp://user@server//home/user/file

User avatar
stark
MILF
Posts: 521
Joined: Sat Sep 27, 2014 6:38 pm
Location: Arpanet
Contact:

Re: tips and tricks for everything but emacs

Unread post by stark » Thu Feb 19, 2015 10:24 am

If you can do it go ahead and do it, if you can't do it then don't even criticize it. - gingerdesu

User avatar
wuxmedia
Grasshopper
Posts: 6445
Joined: Wed Oct 17, 2012 11:32 am
Location: Back in Blighty
Contact:

Re: tips and tricks for everything but emacs

Unread post by wuxmedia » Thu Feb 19, 2015 9:51 pm

GekkoP wrote:Probably a lame one, but comes in handy when you have different machines.

VIM - Editing files over the netwok

Code: Select all

vim scp://user@server//home/user/file
ah thanks Gekko, never thought of that, means I could customise my vimrc..! never need to leave $HOME :)
"Seek, and Ye shall find"
"Github | Chooons | Site"

User avatar
kexolino
Common Boob
Posts: 557
Joined: Sun Jun 16, 2013 1:57 pm

Re: tips and tricks for everything but emacs

Unread post by kexolino » Thu Mar 26, 2015 11:28 am

Snipmate is a pretty useful plugin for vim. Basically, enter an abbreviation, press tab and it will enter the corresponding piece of text for you, and will also place the cursor in the correct position. Small example: entering p, then pressing tab in a html file will give you <p>*cursor here*</p>, or you could have a snippet that will create a whole html structure for you (with doctype, html, head, body, etc tags).

You can write your own snippets, but I recommend downloading vim-snippets as well, because they have a lot pre-written snippets for a ton of languages.

User avatar
ivanovnegro
Minister of Truth
Posts: 5448
Joined: Wed Oct 17, 2012 11:12 pm

Re: tips and tricks for everything but emacs

Unread post by ivanovnegro » Thu Mar 26, 2015 6:43 pm

^ Very nice Kex.

User avatar
GekkoP
Emacs Sancho Panza
Posts: 5877
Joined: Tue Sep 03, 2013 7:05 am

Re: tips and tricks for everything but emacs

Unread post by GekkoP » Thu Mar 26, 2015 9:46 pm

Better searches in tmux with tmux-copycat: https://github.com/tmux-plugins/tmux-copycat

User avatar
rust collector
Motörhead
Posts: 535
Joined: Mon Jan 13, 2014 3:56 pm
Location: no_nb

Re: tips and tricks for everything but emacs

Unread post by rust collector » Mon Mar 30, 2015 2:51 pm

Since real programmers use butterflies... Here I have something for nano:

If you start nano, then want to open a file, you press ctrl+r, where you can write the name of the file you want to look at.
If you then press ctrl+t, you get a simple file browser, where you can arrow your way around.

I just found that a few days ago. I had no idea.

User avatar
wuxmedia
Grasshopper
Posts: 6445
Joined: Wed Oct 17, 2012 11:32 am
Location: Back in Blighty
Contact:

Re: tips and tricks for everything but emacs

Unread post by wuxmedia » Mon Mar 30, 2015 4:47 pm

that's nice. cool share :)
"Seek, and Ye shall find"
"Github | Chooons | Site"

pidsley
Hermit
Posts: 2539
Joined: Wed Oct 17, 2012 12:31 pm

Re: tips and tricks for everything but emacs

Unread post by pidsley » Mon Mar 30, 2015 5:01 pm

Yes thank you rusty. I was not aware of this feature.

User avatar
Dr_Chroot
Alfalfa
Posts: 1100
Joined: Mon Jun 09, 2014 9:49 pm
Location: among the sagebrush
Contact:

Re: tips and tricks for everything but emacs

Unread post by Dr_Chroot » Tue Mar 31, 2015 4:41 pm

I'm sure everyone else already knows about this, but just in case...

Code: Select all

mpv https://www.youtube.com/watch?v=HBcTc6KTGgI
works just as well as using youtube-dl or youtube-viewer :D mpv has really impressed me the more I use it; it seems to be able to do just about everything that VLC or mplayer2 have done for me in the past.
Fight internet censorship.
EFF | Tor Project | Bitcoin

"There have been times throughout American history where what is right is not the same as what is legal. Sometimes to do the right thing you have to break the law." - Edward Snowden

machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

Re: tips and tricks for everything but emacs

Unread post by machinebacon » Sun Apr 05, 2015 10:20 am

Code: Select all

for fillo in `ls -tr /var/lib/dpkg/info/*.list` ; 
    do basename ${fillo} | sed 's/.list$//g' ; 
done  > forens.txt

ls -ltr /var/lib/dpkg/info/*.list > forentime.txt

for lint in `cat forens.txt` ; do 
    echo -n "[ ${lint} Installed ] : " ; 
    echo -n "`grep /${lint}.list forentime.txt | awk '{ print $6, $7, $8 }'` : " ; 
    ( ( grep -A3 " ${lint}$" /var/lib/apt/extended_states | grep '^Auto' > /dev/null ) && echo "Auto" ) || echo "Manual" ; 
done > pkgdatetime.txt
shows you how old your system is. (Here on my dad's laptop it shows Sep 13, 2012 -- one of the first BBQ releases (something around Saltimbocca), upgraded once a year without borkage, by the way).

Found here: http://unix.stackexchange.com/questions ... ation-date
..gnutella..

User avatar
GekkoP
Emacs Sancho Panza
Posts: 5877
Joined: Tue Sep 03, 2013 7:05 am

Re: tips and tricks for everything but emacs

Unread post by GekkoP » Tue Apr 07, 2015 7:49 am

^ nice one!

User avatar
Dr_Chroot
Alfalfa
Posts: 1100
Joined: Mon Jun 09, 2014 9:49 pm
Location: among the sagebrush
Contact:

Re: tips and tricks for everything but emacs

Unread post by Dr_Chroot » Tue Apr 07, 2015 3:03 pm

^^ Wow, this is great :)
Fight internet censorship.
EFF | Tor Project | Bitcoin

"There have been times throughout American history where what is right is not the same as what is legal. Sometimes to do the right thing you have to break the law." - Edward Snowden

User avatar
bayberry
Troll
Posts: 4
Joined: Thu Sep 04, 2014 3:00 pm

Re: tips and tricks for everything but emacs

Unread post by bayberry » Fri Apr 10, 2015 12:54 am

I have a secret, and it's time I aired it: I love Netrw, the file browser that comes packaged with Vim. It's great for browsing remote filesystems without leaving Vim and ditching your precious buffer list, but I use it even on my local machine. Local browsing is a large enough topic so it's all I'm going to talk about here. I never touch mc or ranger, and don't bother with other plugins like CtrlP because I fear excess plugins, which has something to do with why I like the BBQ. I don't bring in Python and Ruby hooks, vim-pathogen, whatever, I just install a minimal Vim package, set nocompatible, change out swapfiles for backups, and get on with life. In Netrw.

The two commands I make heavy use of: :Explore sends you to the directory of the current file (in a split if it has unwritten changes), and :Rexplore sends you to the last directory you saw in Netrw, in case you've been buffer-hopping in the meantime. I nnoremap these, but I don't have a reasonable mneumonic so you might as well come up with your own. (Optionally, :Hexplore and :Vexplore will open Netrw in a split window, but I don't clutter my screen doing that when a simple C-o will take me right back to my last file anyway if I have a change of heart.)

If you don't like the look of Netrw, try pressing i a few times to cycle through styles. Set g:netrw_liststyle in your vimrc for perpetuity.

Most navigating techniques from normal mode work in Netrw. j, 5j, z^, PgUp, /, ?, n, whatever you're used to for getting around, they all still work the same. Except marks.

Some quick default keymappings to get you started:
  • % opens a new file in the current directory. You're prompted for a name.
  • mf marks a file
  • md diffs 2 or 3 marked files
  • me edits all marked files in new buffers
  • mx prompts for a shell command to be executed on marked files
  • u and U navigate backward and forward in your directory history, while - acts as your "cd .."
  • mb bookmarks a directory. gb takes you to your most recently bookmarked directory. You can view all bookmarks with qb. Use the bookmark number as a prefix to go to that bookmark: for example, 3gb goes to bookmark 3. (Yes, this is inelegant. I find I don't need to make use of long-standing bookmarks often, much as I used to do in mc.)
  • o and v open the file under your cursor in a horizontal or vertical split. Size of the split can be set with g:netrw_winsize
  • gh toggles hidden files
:help netrw-browse-maps gives you the full list. Compression, ctags, sorting and reverse sorting, and so on.

Here are the only global settings I feel I need in my .vimrc:

Code: Select all

" Hide top banner. Supposedly a
" dangerous thing to do. Might not
" work on all machines.
let g:netrw_banner=0

" Use cache to speed up browsing on remote
" file systems only. Don't bother at home.
" Manual refresh: C-l.
let g:netrw_fastbrowse=1

" Naivgating to a new directory changes
" the current working directory.
let g:netrw_keepdir=0

" One file per line, no time stamp.
" View file info with qf
let g:netrw_liststyle=0
This covers a very small portion of Netrw, but I use this stuff all the time.

Also, hi, everyone.

User avatar
dkeg
Configurator
Posts: 3782
Joined: Sun Nov 18, 2012 9:23 pm
Location: Mid-Atlantic Grill

Re: tips and tricks for everything but emacs

Unread post by dkeg » Fri Apr 10, 2015 2:31 am

well, that was a a very nice first post. There's no way you can not post an intro post now. Only then will you properly be welcomed.

Work hard; Complain less

Post Reply