Page 1 of 4

tips and tricks for everything but emacs

Posted: Tue Feb 17, 2015 4:16 am
by pidsley
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)

Re: tips and tricks for everything but emacs

Posted: Tue Feb 17, 2015 7:50 am
by kexolino
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>

Re: tips and tricks for everything but emacs

Posted: Tue Feb 17, 2015 8:03 am
by machinebacon
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

Re: tips and tricks for everything but emacs

Posted: Tue Feb 17, 2015 12:27 pm
by dkeg
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

Re: tips and tricks for everything but emacs

Posted: Tue Feb 17, 2015 12:29 pm
by dkeg
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

Re: tips and tricks for everything but emacs

Posted: Tue Feb 17, 2015 8:57 pm
by GekkoP
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

Re: tips and tricks for everything but emacs

Posted: Thu Feb 19, 2015 10:24 am
by stark

Re: tips and tricks for everything but emacs

Posted: Thu Feb 19, 2015 9:51 pm
by wuxmedia
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 :)

Re: tips and tricks for everything but emacs

Posted: Thu Mar 26, 2015 11:28 am
by kexolino
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.

Re: tips and tricks for everything but emacs

Posted: Thu Mar 26, 2015 6:43 pm
by ivanovnegro
^ Very nice Kex.

Re: tips and tricks for everything but emacs

Posted: Thu Mar 26, 2015 9:46 pm
by GekkoP
Better searches in tmux with tmux-copycat: https://github.com/tmux-plugins/tmux-copycat

Re: tips and tricks for everything but emacs

Posted: Mon Mar 30, 2015 2:51 pm
by rust collector
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.

Re: tips and tricks for everything but emacs

Posted: Mon Mar 30, 2015 4:47 pm
by wuxmedia
that's nice. cool share :)

Re: tips and tricks for everything but emacs

Posted: Mon Mar 30, 2015 5:01 pm
by pidsley
Yes thank you rusty. I was not aware of this feature.

Re: tips and tricks for everything but emacs

Posted: Tue Mar 31, 2015 4:41 pm
by Dr_Chroot
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.

Re: tips and tricks for everything but emacs

Posted: Sun Apr 05, 2015 10:20 am
by machinebacon

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

Re: tips and tricks for everything but emacs

Posted: Tue Apr 07, 2015 7:49 am
by GekkoP
^ nice one!

Re: tips and tricks for everything but emacs

Posted: Tue Apr 07, 2015 3:03 pm
by Dr_Chroot
^^ Wow, this is great :)

Re: tips and tricks for everything but emacs

Posted: Fri Apr 10, 2015 12:54 am
by bayberry
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.

Re: tips and tricks for everything but emacs

Posted: Fri Apr 10, 2015 2:31 am
by dkeg
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.